Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Tuist/Dependencies
.AppleDouble
.LSOverride
*.xcconfig
Release.xcconfig

# Icon must end with two \r
Icon
Expand Down
2 changes: 1 addition & 1 deletion Projects/App/Support/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<string>1.5.2</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CloudTypeBaseURL</key>
Expand Down
112 changes: 59 additions & 53 deletions Projects/Feature/Sources/Scene/Auth/SignIn/SignInViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ import UIKit
import Service

public final class SignInViewController: BaseViewController {

// MARK: - Properties
private var viewModel = AuthViewModel()
private var listModel : StudentListModel?
private var profileModel = ProfileViewModel()
private let notificationViewModel = NotificationViewModel()

private let loader = LoaderViewController()

init(viewModel: AuthViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

init(listModel: StudentListModel) {
self.listModel = listModel
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private lazy var textFieldStackView = UIStackView().then {
$0.spacing = 24
$0.axis = .vertical
$0.distribution = .fillEqually
$0.alignment = .fill
}

private let emailTextField = GOMSTextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0), placeholder: "์ด๋ฉ”์ผ")

private let defaultDomain = UILabel().then {
$0.text = "@gsm.hs.kr"
$0.font = .pretendard(size: 16, weight: .regular)
$0.textColor = .color.gomsTertiary.color
}

private let emailErrorLabel = UILabel().then {
$0.text = "์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค."
$0.textColor = .color.gomsNegative.color
Expand All @@ -60,52 +60,52 @@ public final class SignInViewController: BaseViewController {
$0.rightView = showPasswordButton
$0.rightViewMode = .always
}

lazy var showPasswordButton = UIButton().then {
$0.setImage(.image.visible.image, for: .normal)
$0.addTarget(self, action: #selector(showPasswordButtonTapped), for: .touchUpInside)
$0.isEnabled = true
}

private let findPasswordLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 48)).then {
$0.text = "๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?"
$0.textColor = .color.gomsTertiary.color
$0.font = .pretendard(size: 16, weight: .regular)
}

private lazy var findPasswordButton = UIButton().then {
$0.setTitle("๋น„๋ฐ€๋ฒˆํ˜ธ ์ฐพ๊ธฐ", for: .normal)
$0.backgroundColor = .clear
$0.titleLabel?.font = UIFont.pretendard(size: 16, weight: .regular)
$0.setTitleColor(.color.gomsInformation.color, for: .normal)
$0.addTarget(self, action: #selector(findPasswordButtonTapped), for: .touchUpInside)
}

private let passwordErrorLabel = UILabel().then {
$0.text = "์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค."
$0.textColor = .color.gomsNegative.color
$0.font = .pretendard(size: 16, weight: .medium)
$0.isHidden = true
}

private lazy var signInButton = GOMSButton(frame: CGRect(x: 0, y: 0, width: 0, height: 0), title: "๋กœ๊ทธ์ธ").then {
$0.addTarget(self, action: #selector(signInButtonTapped), for: .touchUpInside)
}

// MARK: - Life Cycel
public override func viewDidLoad() {
super.viewDidLoad()

emailTextField.delegate = self
passwordTextField.delegate = self
}

// MARK: - Seletors
@objc func findPasswordButtonTapped() {
let findPasswordVC = FindPasswordViewController(viewModel: self.viewModel)
navigationController?.pushViewController(findPasswordVC, animated: true)
}

private var isTransitioning = false

@objc func signInButtonTapped() {
Expand All @@ -130,32 +130,37 @@ public final class SignInViewController: BaseViewController {
guard let self = self else { return }

if success {
if self.isTransitioning {
return
}

self.isTransitioning = true

if let authority = self.profileModel.profileInfo?.authority {
var rootVC: UIViewController

if authority == Authority.admin.rawValue {
let mainVC = AdminMainViewController()
self.navigationController?.setViewControllers([mainVC], animated: true)
rootVC = AdminMainViewController()
} else if authority == Authority.student.rawValue {
let mainVC = MainViewController()
self.navigationController?.setViewControllers([mainVC], animated: true)
rootVC = MainViewController()
} else {
print("๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.")
self.loader.dismiss(animated: true)
return
}

/// ๐Ÿ”ฅ rootViewController ์ง์ ‘ ๊ต์ฒด
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = scene.windows.first {
window.rootViewController = UINavigationController(rootViewController: rootVC)
window.makeKeyAndVisible()
}
}
} else {
print("ํ”„๋กœํ•„ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
}

self.loader.dismiss(animated: true)
self.isTransitioning = false
}

case 400:
self.passwordErrorUI()
self.loader.dismiss(animated: true)

case 404:
self.emailErrorUI()
self.loader.dismiss(animated: true)
Expand All @@ -168,17 +173,18 @@ public final class SignInViewController: BaseViewController {
}
}


@objc func showPasswordButtonTapped() {
passwordTextField.isSecureTextEntry.toggle()
showPasswordButton.isSelected.toggle()

if showPasswordButton.isSelected {
showPasswordButton.setImage(.image.invisible.image, for: .normal)
} else {
showPasswordButton.setImage(.image.visible.image, for: .normal)
}
}

@objc override func keyboardWillShow(_ sender: Notification) {
self.signInButton.isEnabled = true
signInButton.snp.remakeConstraints {
Expand All @@ -188,18 +194,18 @@ public final class SignInViewController: BaseViewController {
$0.bottom.equalTo(-bounds.height * 0.43)
}
}

@objc override func keyboardWillHide(_ sender: Notification) {
self.signInButton.isEnabled = true

signInButton.snp.makeConstraints {
$0.height.equalTo(48)
$0.leading.equalTo(bounds.width * 0.05)
$0.trailing.equalTo(-bounds.width * 0.05)
$0.bottom.equalTo(-bounds.height * 0.16)
}
}

func signInSuccessUI() {
emailTextField.setPlaceholderColor(.color.gomsTertiary.color)
defaultDomain.textColor = .color.gomsTertiary.color
Expand All @@ -210,15 +216,15 @@ public final class SignInViewController: BaseViewController {
findPasswordLabel.isHidden = false
passwordTextField.layer.borderColor = UIColor.clear.cgColor
passwordTextField.layer.borderWidth = 0

passwordTextField.snp.remakeConstraints {
$0.height.equalTo(56)
$0.leading.equalTo(bounds.width * 0.05)
$0.trailing.equalTo(-bounds.width * 0.05)
$0.top.equalTo(emailTextField.snp.bottom).offset(24)
}
}

func emailErrorUI() {
emailTextField.setPlaceholderColor(.color.gomsNegative.color)
defaultDomain.textColor = .color.gomsNegative.color
Expand All @@ -229,15 +235,15 @@ public final class SignInViewController: BaseViewController {
findPasswordLabel.isHidden = false
passwordTextField.layer.borderColor = UIColor.clear.cgColor
passwordTextField.layer.borderWidth = 0

passwordTextField.snp.remakeConstraints {
$0.height.equalTo(48)
$0.leading.equalTo(bounds.width * 0.05)
$0.trailing.equalTo(-bounds.width * 0.05)
$0.top.equalTo(emailErrorLabel.snp.bottom).offset(24)
}
}

func passwordErrorUI() {
passwordTextField.setPlaceholderColor(.color.gomsNegative.color)
passwordErrorLabel.isHidden = false
Expand All @@ -249,74 +255,74 @@ public final class SignInViewController: BaseViewController {
emailErrorLabel.isHidden = true
emailTextField.layer.borderColor = UIColor.clear.cgColor
emailTextField.layer.borderWidth = 0

passwordTextField.snp.remakeConstraints {
$0.height.equalTo(56)
$0.leading.equalTo(bounds.width * 0.05)
$0.trailing.equalTo(-bounds.width * 0.05)
$0.top.equalTo(emailTextField.snp.bottom).offset(24)
}
}

// MARK: - Navigaiton
override func configNavigation() {
super.configNavigation()
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.title = "๋กœ๊ทธ์ธ"
}

// MARK: - Add View
override func addView() {
emailTextField.addSubview(defaultDomain)
[emailTextField, emailErrorLabel, passwordTextField, passwordErrorLabel, findPasswordLabel, findPasswordButton, signInButton].forEach { view.addSubview($0) }
}

// MARK: - Layout
override func setLayout() {
defaultDomain.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(16)
$0.height.equalTo(28)
$0.centerY.equalToSuperview()
}

emailTextField.snp.makeConstraints {
$0.leading.equalTo(bounds.width * 0.05)
$0.trailing.equalTo(-bounds.width * 0.05)
$0.top.equalTo(bounds.height * 0.2)
$0.height.equalTo(56)
}

emailErrorLabel.snp.makeConstraints {
$0.leading.equalTo(emailTextField.snp.leading)
$0.height.equalTo(48)
$0.top.equalTo(emailTextField.snp.bottom)
}

passwordTextField.snp.makeConstraints {
$0.height.equalTo(56)
$0.leading.equalTo(bounds.width * 0.05)
$0.trailing.equalTo(-bounds.width * 0.05)
$0.top.equalTo(emailTextField.snp.bottom).offset(24)
}

findPasswordLabel.snp.makeConstraints {
$0.height.equalTo(48)
$0.top.equalTo(passwordTextField.snp.bottom)
$0.leading.equalTo(bounds.width * 0.07)
}

passwordErrorLabel.snp.makeConstraints {
$0.height.equalTo(48)
$0.top.equalTo(passwordTextField.snp.bottom)
$0.leading.equalTo(bounds.width * 0.07)
}

findPasswordButton.snp.makeConstraints {
$0.height.equalTo(48)
$0.trailing.equalTo(-bounds.width * 0.07)
$0.top.equalTo(passwordTextField.snp.bottom)
}

signInButton.snp.makeConstraints {
$0.height.equalTo(48)
$0.leading.equalTo(bounds.width * 0.05)
Expand All @@ -335,22 +341,22 @@ extension SignInViewController: UITextFieldDelegate {
viewModel.setupPassword(password: textField.text ?? "")
}
}

public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let currentText = (textField.text ?? "") as NSString
let updatedText = currentText.replacingCharacters(in: range, with: string)

if textField == emailTextField {
return updatedText.count <= 6 && updatedText.rangeOfCharacter(from: .whitespaces) == nil
}

if textField == passwordTextField {
return updatedText.rangeOfCharacter(from: .whitespaces) == nil
}

return true
}

public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if emailTextField.text != "", passwordTextField.text != "" {
passwordTextField.resignFirstResponder()
Expand Down
Loading