From 64102902bd9f57902b36759fea49af7c5354c9ae Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Sat, 2 Apr 2022 23:57:52 +0900 Subject: [PATCH 01/14] =?UTF-8?q?[Feat]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B0=BE=EA=B8=B0=20=EB=B7=B0=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hyangyu/Hyangyu/Resources/Constants/URL.swift | 5 ++- .../APIServices/AuthAPI/PasswordAPI.swift | 6 +-- .../APIServices/AuthAPI/PasswordService.swift | 14 +++---- .../FindPasswordViewController.swift | 39 +++++++------------ .../FindPasswordViewController.xib | 13 ++++--- 5 files changed, 33 insertions(+), 44 deletions(-) diff --git a/Hyangyu/Hyangyu/Resources/Constants/URL.swift b/Hyangyu/Hyangyu/Resources/Constants/URL.swift index d2f5860..7fdd887 100644 --- a/Hyangyu/Hyangyu/Resources/Constants/URL.swift +++ b/Hyangyu/Hyangyu/Resources/Constants/URL.swift @@ -19,9 +19,11 @@ extension Const { static let signUpURL = "/user/signup" // 로그인 (POST) - static let signInURL = "/auth" + // 비밀번호 찾기(POST) + static let findPasswordURL = "/send-email" + // 비밀번호 변경 (POST) static let passwordURL = "/user/password" @@ -30,7 +32,6 @@ extension Const { // 전시회 저장 (POST), 전시회 취소(DELETE), 전시회 조회 (GET), 카테고리 - 전시회(GET) static let displayURL = "/display" - // MARK: - My Page - User Service // 닉네임 변경 (POST) diff --git a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift index 3fb1ccf..1b1b2b2 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift @@ -31,8 +31,8 @@ public class PasswordAPI { } } - func getEmailCode(completion: @escaping (NetworkResult) -> Void, email: String) { - courseProvider.request(.getEmailCode(email: email)) { (result) in + func postEmailCode(completion: @escaping (NetworkResult) -> Void, email: String) { + courseProvider.request(.postEmailCode(email: email)) { (result) in switch result { case .success(let response): let statusCode = response.statusCode @@ -70,7 +70,7 @@ public class PasswordAPI { private func judgeGetEmailCodeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { let decoder = JSONDecoder() - guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) else { + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) else { return .pathErr } diff --git a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift index 668044d..01b155c 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift @@ -10,7 +10,8 @@ import Moya enum PasswordService { case putChangedPassword(email: String, password: String) - case getEmailCode(email: String) + case postEmailCode(email: String) + } extension PasswordService: TargetType { @@ -22,8 +23,8 @@ extension PasswordService: TargetType { switch self { case .putChangedPassword(_, _): return Const.URL.passwordURL - case .getEmailCode(let email): - return Const.URL.passwordURL + "/\(email)" + case .postEmailCode(let email): + return Const.URL.findPasswordURL + "/\(email)" } } @@ -31,8 +32,8 @@ extension PasswordService: TargetType { switch self { case .putChangedPassword(_, _): return .put - case .getEmailCode(_): - return .get + case .postEmailCode(_): + return .post } } @@ -48,7 +49,7 @@ extension PasswordService: TargetType { "email": email, "password": password ], encoding: JSONEncoding.default) - case .getEmailCode(_): + case .postEmailCode(_): return .requestPlain } } @@ -59,4 +60,3 @@ extension PasswordService: TargetType { ] } } - diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift index a2e09a1..fbd1c38 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift @@ -15,12 +15,13 @@ class FindPasswordViewController: UIViewController { var isResetCodeEnabled: Bool = false private var userResetCode: Int = 0 + // MARK: - @IBOutlet Properties @IBOutlet weak var emailTextField: UITextField! @IBOutlet weak var emailTextFieldView: UIView! @IBOutlet weak var emailWarningLabel: UILabel! - - @IBOutlet weak var nextButton: UIButton! + + // MARK: - View Life Cycle override func viewDidLoad() { super.viewDidLoad() initNavigationBar() @@ -39,14 +40,12 @@ class FindPasswordViewController: UIViewController { emailTextField.delegate = self } - private func configureUI() { emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) nextButton.makeRounded(radius: 20) emailWarningLabel.isHidden = true - nextButton.isEnabled = false } @@ -82,29 +81,15 @@ class FindPasswordViewController: UIViewController { nextButton.alpha = 0.3 } - func validateCode(code: String) -> Bool { - // Email 정규식 - let codeRegEx = "^[0-9]{4}$" - let codeTest = NSPredicate(format: "SELF MATCHES %@", codeRegEx) - return codeTest.evaluate(with: code) - } - - private func checkCodeFormat(userInput: String) { - if validateCode(code: userInput) { - makeCompleteButtonEnable() - } else { - makeCompleteButtonDisable() - } + private func pushToNewPasswordViewController() { + self.navigationController?.pushViewController(ResetCodeViewController.loadFromNib(), animated: true) } - - - private func pushToNewPasswordViewController() { - self.navigationController?.pushViewController(NewPasswordViewController.loadFromNib(), animated: true) + @IBAction func touchNextButton(_ sender: Any) { + getCode() } - } extension FindPasswordViewController: UITextFieldDelegate { @@ -112,7 +97,6 @@ extension FindPasswordViewController: UITextFieldDelegate { emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) } - // 실시간 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { guard let text = textField.text else { return false @@ -121,7 +105,6 @@ extension FindPasswordViewController: UITextFieldDelegate { return true } - // 키보드 내렸을 때 (.co 등 때문에 추가) func textFieldDidEndEditing(_ textField: UITextField) { guard let text = textField.text else { return @@ -137,18 +120,22 @@ extension FindPasswordViewController { if let email = self.emailTextField.text { - PasswordAPI.shared.getEmailCode(completion: { (result) in + PasswordAPI.shared.postEmailCode(completion: { (result) in switch result { case .success(let code): - if let data = code as? CodeData { + if let data = code as? EmailCheckData { self.emailWarningLabel.isHidden = true self.user.email = email + print("data.message: \(data.message)") + self.emailWarningLabel.text = "\(data.message)" + self.pushToNewPasswordViewController() } case .requestErr(let message): self.emailWarningLabel.isHidden = false if let message = message as? String { self.emailWarningLabel.text = "\(message)" + self.pushToNewPasswordViewController() } case .pathErr: print(".pathErr") diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib index 8335ae9..8b8a11d 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib @@ -1,8 +1,9 @@ - + - + + @@ -24,7 +25,7 @@ - + From affef4637c42fdcfc9969bd4547cbc5b90931cdf Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Sat, 30 Apr 2022 23:56:11 +0900 Subject: [PATCH 02/14] =?UTF-8?q?[Chore]=20URL=20=EC=B6=94=EA=B0=80=20(#63?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hyangyu/Hyangyu/Resources/Constants/URL.swift | 3 +++ Hyangyu/Hyangyu/Sources/CustomTabBar/UIColor+RGB.swift | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Hyangyu/Hyangyu/Resources/Constants/URL.swift b/Hyangyu/Hyangyu/Resources/Constants/URL.swift index 7fdd887..e13ae35 100644 --- a/Hyangyu/Hyangyu/Resources/Constants/URL.swift +++ b/Hyangyu/Hyangyu/Resources/Constants/URL.swift @@ -27,6 +27,9 @@ extension Const { // 비밀번호 변경 (POST) static let passwordURL = "/user/password" + // 인증번호 동일 확인 (DELETE) + static let checkCodeURL = "/authnum" + // MARK: - Saved - My Page Saved Service // 전시회 저장 (POST), 전시회 취소(DELETE), 전시회 조회 (GET), 카테고리 - 전시회(GET) diff --git a/Hyangyu/Hyangyu/Sources/CustomTabBar/UIColor+RGB.swift b/Hyangyu/Hyangyu/Sources/CustomTabBar/UIColor+RGB.swift index d5d5d6f..51ad568 100644 --- a/Hyangyu/Hyangyu/Sources/CustomTabBar/UIColor+RGB.swift +++ b/Hyangyu/Hyangyu/Sources/CustomTabBar/UIColor+RGB.swift @@ -21,4 +21,3 @@ extension UIColor { } } } - From 4d7568d4cd7c449208083f5361d8285838e4336a Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Sat, 30 Apr 2022 23:56:44 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[Add]=20AuthAPI=20=EC=97=B0=EA=B2=B0=20(#?= =?UTF-8?q?63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hyangyu/Hyangyu/Sources/APIModels/Auth.swift | 2 - .../APIServices/AuthAPI/PasswordAPI.swift | 44 ++++++++++++++++--- .../APIServices/AuthAPI/PasswordService.swift | 10 +++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/APIModels/Auth.swift b/Hyangyu/Hyangyu/Sources/APIModels/Auth.swift index 4012972..b0583f8 100644 --- a/Hyangyu/Hyangyu/Sources/APIModels/Auth.swift +++ b/Hyangyu/Hyangyu/Sources/APIModels/Auth.swift @@ -32,5 +32,3 @@ struct CodeData: Codable { struct EmailCheckData: Codable { let message: String } - - diff --git a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift index 1b1b2b2..24a8fc4 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift @@ -37,7 +37,22 @@ public class PasswordAPI { case .success(let response): let statusCode = response.statusCode let data = response.data - let networkResult = self.judgeGetEmailCodeStatus(by: statusCode, data) + let networkResult = self.judgeStatus(by: statusCode, data) + completion(networkResult) + + case .failure(let err): + print(err) + } + } + } + + func checkCode(completion: @escaping (NetworkResult) -> Void, email: String, authNum: String) { + courseProvider.request(.checkCode(email: email, authNum: authNum)) { (result) in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + let networkResult = self.judgeStatus(by: statusCode, data) completion(networkResult) case .failure(let err): @@ -67,16 +82,16 @@ public class PasswordAPI { } } - private func judgeGetEmailCodeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { - + private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { let decoder = JSONDecoder() - guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) else { + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) + else { return .pathErr } switch statusCode { case 200: - return .success(decodedData.data) + return .success(decodedData.message) case 400..<500: return .requestErr(decodedData.message) case 500: @@ -85,5 +100,24 @@ public class PasswordAPI { return .networkFail } } + +// private func judgeGetEmailCodeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { +// +// let decoder = JSONDecoder() +// guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) else { +// return .pathErr +// } +// +// switch statusCode { +// case 200: +// return .success(decodedData.data) +// case 400..<500: +// return .requestErr(decodedData.message) +// case 500: +// return .serverErr +// default: +// return .networkFail +// } +// } } diff --git a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift index 01b155c..779a41b 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift @@ -11,6 +11,7 @@ import Moya enum PasswordService { case putChangedPassword(email: String, password: String) case postEmailCode(email: String) + case checkCode(email: String, authNum: String) } @@ -25,6 +26,8 @@ extension PasswordService: TargetType { return Const.URL.passwordURL case .postEmailCode(let email): return Const.URL.findPasswordURL + "/\(email)" + case .checkCode(let email, let authNum): + return Const.URL.checkCodeURL } } @@ -34,6 +37,8 @@ extension PasswordService: TargetType { return .put case .postEmailCode(_): return .post + case .checkCode(_, _): + return .delete } } @@ -51,6 +56,11 @@ extension PasswordService: TargetType { ], encoding: JSONEncoding.default) case .postEmailCode(_): return .requestPlain + case .checkCode(let email, let authNum): + return .requestParameters(parameters: [ + "email": email, + "authNum": authNum + ], encoding: JSONEncoding.default) } } From e779accd71843207f195f391081d60d80b09fb34 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 2 May 2022 23:37:27 +0900 Subject: [PATCH 04/14] =?UTF-8?q?[Chore]=20ProfileEditVC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyPage/ProfileEditViewController.swift | 13 ++----------- Hyangyu/Hyangyu/Sources/Views/HeaderView.swift | 3 +-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift index 0b3b1f2..58e1945 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift @@ -9,7 +9,7 @@ import UIKit import Then -protocol ProfileEditViewControllerDelegate: class { +protocol ProfileEditViewControllerDelegate: AnyObject { func setUpdate(data: MyPageResponse) } @@ -19,7 +19,6 @@ struct ProfileEditViewControllerViewModel { } - final class ProfileEditViewController: UIViewController { // MARK: - Properties @@ -47,7 +46,6 @@ final class ProfileEditViewController: UIViewController { @IBOutlet weak var countingLabel: UILabel! - private let imageShadowView = UIView().then { $0.layer.shadowOffset = CGSize(width: 0, height: 0) $0.layer.shadowOpacity = 0.2 @@ -55,7 +53,6 @@ final class ProfileEditViewController: UIViewController { $0.layer.shadowColor = UIColor.gray.cgColor } - weak var delegate: ProfileEditViewControllerDelegate? private var viewModel: ProfileEditViewControllerViewModel = ProfileEditViewControllerViewModel(profileImage: UIImage(), userName: "") @@ -90,7 +87,6 @@ final class ProfileEditViewController: UIViewController { userProfileImageView.clipsToBounds = true } - private func setDelegation() { userNameTextField.delegate = self let tapGesture = UITapGestureRecognizer(target: self, action: #selector(touchToPickImage)) @@ -144,7 +140,6 @@ final class ProfileEditViewController: UIViewController { // MARK: - @IBAction - @IBAction func didTapCancel(_ sender: Any) { dismiss(animated: true, completion: nil) } @@ -221,9 +216,6 @@ final class ProfileEditViewController: UIViewController { } - - - private func actionSheetAlert() { let imagePickerController = UIImagePickerController() imagePickerController.delegate = self @@ -268,12 +260,11 @@ final class ProfileEditViewController: UIViewController { self.viewModel = viewModel } - } // MARK: - UIImagePickerControllerDelegate, UINavigationControllerDelegatenil extension ProfileEditViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { var newImage: UIImage? = nil diff --git a/Hyangyu/Hyangyu/Sources/Views/HeaderView.swift b/Hyangyu/Hyangyu/Sources/Views/HeaderView.swift index e3c3172..cc61856 100644 --- a/Hyangyu/Hyangyu/Sources/Views/HeaderView.swift +++ b/Hyangyu/Hyangyu/Sources/Views/HeaderView.swift @@ -6,6 +6,7 @@ // import UIKit + import Kingfisher import Then import SnapKit @@ -58,7 +59,6 @@ class HeaderView: UIView { weak var delegate: HeaderViewDelegate? - func configureUI() { addSubview(profileImageView) addSubview(userNameLabel) @@ -66,7 +66,6 @@ class HeaderView: UIView { buttonStackView.addArrangedSubview(profileEditButton) buttonStackView.addArrangedSubview(myReviewButton) - profileImageView.snp.makeConstraints { $0.top.equalTo(safeAreaInsets.top).offset(110) $0.leading.equalTo(safeAreaInsets.left).offset(20) From 10a277441467149001ed93dfd17072afb01caf13 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Mon, 2 May 2022 23:37:39 +0900 Subject: [PATCH 05/14] =?UTF-8?q?[Chore]=20User=20=EC=88=98=EC=A0=95=20(#6?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hyangyu/Hyangyu/Sources/AppModels/User.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Hyangyu/Hyangyu/Sources/AppModels/User.swift b/Hyangyu/Hyangyu/Sources/AppModels/User.swift index 4adff85..ad3becb 100644 --- a/Hyangyu/Hyangyu/Sources/AppModels/User.swift +++ b/Hyangyu/Hyangyu/Sources/AppModels/User.swift @@ -11,6 +11,8 @@ import UIKit class User { static let shared = User() + var email: String? var username: String? var profileImage: UIImage? + var password: String? } From 35c2f060ff233a543550c97387a44108881a841f Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Tue, 3 May 2022 23:52:32 +0900 Subject: [PATCH 06/14] =?UTF-8?q?[Chore]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20&?= =?UTF-8?q?=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20UI=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/ViewControllers/SignIn/SignInViewController.xib | 5 +++-- .../Sources/ViewControllers/SignUp/SignUpViewController.xib | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.xib index 5fa24ff..9a8ad68 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/SignIn/SignInViewController.xib @@ -1,8 +1,9 @@ - + - + + diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.xib index 5b99c8a..66caa57 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.xib @@ -1,8 +1,9 @@ - + - + + From 08d42b6d21fe03ac86f23b119a73ff32aaf6389f Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Tue, 3 May 2022 23:57:00 +0900 Subject: [PATCH 07/14] =?UTF-8?q?[ADD]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=AC=EC=84=A4=EC=A0=95=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FindPasswordViewController.swift | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift index fbd1c38..390f378 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift @@ -14,6 +14,7 @@ class FindPasswordViewController: UIViewController { let user = SignUpUser.shared var isResetCodeEnabled: Bool = false private var userResetCode: Int = 0 + private var isEmailRight: Bool = false // MARK: - @IBOutlet Properties @IBOutlet weak var emailTextField: UITextField! @@ -31,6 +32,23 @@ class FindPasswordViewController: UIViewController { } // MARK: - Functions + private func addTarget() { + emailTextField.addTarget(self, action: #selector(self.activateEmailTextField), for: .editingDidBegin) + emailTextField.addTarget(self, action: #selector(self.inactivateEmailTextField), for: .editingDidEnd) + } + + // 텍스트 필드 확성화 + @objc private func activateEmailTextField() { + emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) + } + + // 텍스트 필드 비활성화 + @objc private func inactivateEmailTextField() { + + isEmailRight = checkEmail(email: emailTextField.text ?? "") + emailWarningLabel.isHidden = isEmailRight || !emailTextField.hasText ? true : false + emailTextFieldView.layer.borderColor = isEmailRight || !emailTextField.hasText ? UIColor.systemGray2.cgColor : UIColor.systemRed.cgColor + } private func initNavigationBar() { self.navigationController?.initWithBackButton() @@ -41,8 +59,8 @@ class FindPasswordViewController: UIViewController { } private func configureUI() { - emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) - nextButton.makeRounded(radius: 20) + emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) + nextButton.makeRounded(radius: 12) emailWarningLabel.isHidden = true @@ -50,7 +68,7 @@ class FindPasswordViewController: UIViewController { } private func checkEmailFormat(email: String) { - if validateEmail(email: email) { + if checkEmail(email: email) { nextButton.isEnabled = true nextButton.alpha = 1.0 @@ -64,7 +82,7 @@ class FindPasswordViewController: UIViewController { } } - func validateEmail(email: String) -> Bool { + private func checkEmail(email: String) -> Bool { // Email 정규식 let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" let emailTest = NSPredicate(format: "SELF MATCHES %@", emailRegEx) @@ -81,15 +99,17 @@ class FindPasswordViewController: UIViewController { nextButton.alpha = 0.3 } - private func pushToNewPasswordViewController() { - self.navigationController?.pushViewController(ResetCodeViewController.loadFromNib(), animated: true) + private func pushToNewPasswordViewController(email: String) { + let resetCodeViewController = ResetCodeViewController.loadFromNib() + resetCodeViewController.email = email + self.navigationController?.pushViewController(resetCodeViewController, animated: true) + } @IBAction func touchNextButton(_ sender: Any) { getCode() } - } extension FindPasswordViewController: UITextFieldDelegate { @@ -124,18 +144,19 @@ extension FindPasswordViewController { switch result { case .success(let code): - if let data = code as? EmailCheckData { + if let data = code as? String { self.emailWarningLabel.isHidden = true self.user.email = email - print("data.message: \(data.message)") - self.emailWarningLabel.text = "\(data.message)" - self.pushToNewPasswordViewController() + print("data.message: \(data)") + self.emailWarningLabel.text = "\(data)" + self.showToast(message: data) + self.pushToNewPasswordViewController(email: email) } case .requestErr(let message): self.emailWarningLabel.isHidden = false if let message = message as? String { self.emailWarningLabel.text = "\(message)" - self.pushToNewPasswordViewController() + self.pushToNewPasswordViewController(email: email) } case .pathErr: print(".pathErr") From d617462d88fdc5da7a9e564a0808bcff052cfb03 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Wed, 4 May 2022 23:06:42 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[Add]=20=EC=9D=B8=EC=A6=9D=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResetCode/ResetCodeViewController.swift | 158 +++++++++++++++++- .../ResetCode/ResetCodeViewController.xib | 24 ++- 2 files changed, 166 insertions(+), 16 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift index 68ac84d..92e21d7 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift @@ -9,21 +9,163 @@ import UIKit class ResetCodeViewController: UIViewController { + // MARK: - Properties + var email: String? // 이메일 + + // MARK: - @IBOutlet Properties + + @IBOutlet weak var codeTextFieldView: UIView! + @IBOutlet weak var codeTextField: UITextField! + @IBOutlet weak var warningLabel: UILabel! + @IBOutlet weak var completeButton: UIButton! + + // MARK: - View Life Cycle override func viewDidLoad() { + print("이거 실행되긴 하니?") super.viewDidLoad() + + initNavigationBar() + setDelegation() + configureUI() - // Do any additional setup after loading the view. + } + + // MARK: - Functions + private func addTarget() { + codeTextField.addTarget(self, action: #selector(self.activateCodeTextField), for: .editingDidBegin) + codeTextField.addTarget(self, action: #selector(self.inactivateCodeTextField), for: .editingDidEnd) + codeTextField.addTarget(self, action: #selector(self.activateCompleteButton), for: .editingChanged) + } + + // 텍스트 필드 확성화 + @objc private func activateCodeTextField() { + codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) } + // 텍스트 필드 비활성화 + @objc private func inactivateCodeTextField() { + codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) + } + + // 버튼 활성화 + @objc private func activateCompleteButton() { + completeButton.isEnabled = codeTextField.hasText + completeButton.alpha = 1.0 + } + + private func initNavigationBar() { + self.navigationController?.initWithBackButton() + } + + private func setDelegation() { + self.codeTextField.delegate = self + } + + private func configureUI() { + codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) + completeButton.makeRounded(radius: 12) + makeCompleteButtonDisable() + } + + private func pushToNewPasswordViewController() { + self.navigationController?.pushViewController(NewPasswordViewController.loadFromNib(), animated: true) + } + + private func makeCompleteButtonEnable() { + completeButton.isEnabled = true + completeButton.alpha = 1.0 + } - /* - // MARK: - Navigation + private func makeCompleteButtonDisable() { + completeButton.isEnabled = false + completeButton.alpha = 0.3 + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + func validateCode(code: String) -> Bool { + // Email 정규식 + let codeRegEx = "^[a-z0-9+]{6}$" + let codeTest = NSPredicate(format: "SELF MATCHES %@", codeRegEx) + return codeTest.evaluate(with: code) } - */ + private func checkCodeFormat(userInput: String) { + if validateCode(code: userInput) { + makeCompleteButtonEnable() + } else { + makeCompleteButtonDisable() + } + } + + @IBAction func touchCompleteButton(_ sender: Any) { + print("touched Complete Button") + sendCode() + } + + private func pushToNewPasswordViewController(email: String) { + let newPasswordViewController = NewPasswordViewController.loadFromNib() + self.navigationController?.pushViewController(newPasswordViewController, animated: true) + + } + +} + +// MARK: - UITextFieldDelegate +extension ResetCodeViewController: UITextFieldDelegate { + func textFieldDidEndEditing(_ textField: UITextField) { + print("textFieldDidendEditing") + guard let text = textField.text else { + return + } + checkCodeFormat(userInput: text) + } + + func textFieldDidBeginEditing(_ textField: UITextField) { + print("저 실행되었습니다.") + warningLabel.isHidden = true + codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) + completeButton.isEnabled = true + } + + // Return 눌렀을 시 키보드 내리기 + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + return true + } +} + +extension ResetCodeViewController { + func sendCode() { + print("저 실행됩니다요") + guard let code = codeTextField.text else { + return + } + + PasswordAPI.shared.checkCode(completion: { response in + switch response { + case .success(let data): + if let data = data as? String { + self.showToast(message: data) + } + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.dismiss(animated: true) + } + self.pushToNewPasswordViewController() + case .requestErr(let message): + if let message = message as? String { + print(message) + self.showToast(message: message) + } + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.dismiss(animated: true) + } + print("requestErr", message) + case .pathErr: + print("pathErr") + case .serverErr: + print("serverErr") + case .networkFail: + print("networkFail") + } + }, email: email ?? "", authNum: code) + } } diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib index feec7d8..1e04a8a 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib @@ -1,8 +1,9 @@ - + - + + @@ -11,7 +12,11 @@ + + + + @@ -28,10 +33,10 @@ - + - + @@ -39,10 +44,10 @@ - - - - + + + + From 17b6da31137b40d5a0d5579bd45623e735107814 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Thu, 5 May 2022 23:58:19 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[Chore]=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/ResetCode/ResetCodeViewController.swift | 1 + .../Sources/ViewControllers/SignUp/SignUpViewController.swift | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift index 92e21d7..6b2667c 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift @@ -64,6 +64,7 @@ class ResetCodeViewController: UIViewController { private func configureUI() { codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) completeButton.makeRounded(radius: 12) + warningLabel.isHidden = true makeCompleteButtonDisable() } diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.swift index e58c8b3..d20db5f 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/SignUp/SignUpViewController.swift @@ -92,8 +92,6 @@ class SignUpViewController: UIViewController { // 버튼 활성화 조건 [emailTextField, passwordTextField, confirmPasswordTextField, nicknameTextField].forEach {$0.addTarget(self, action: #selector(self.activateSignUpButton), for: .editingChanged)} - - } // 이메일 정규식 체크 From cbae5b8b20b26ee7c6783b9c342c4ddab8a9c589 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Fri, 6 May 2022 22:53:40 +0900 Subject: [PATCH 10/14] =?UTF-8?q?[Add]=20=EC=83=88=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20UI=20=EC=9E=91=EC=97=85=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NewPassword/NewPasswordViewController.xib | 135 +++++++++++------- 1 file changed, 80 insertions(+), 55 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib index 852275c..658d71a 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib @@ -1,8 +1,9 @@ - + - + + @@ -11,6 +12,15 @@ + + + + + + + + + @@ -19,120 +29,135 @@ - - + + + + - - - + + - - - - + - - + + + + + - + From 07ed9292e17632edf92303329b30517d414a18cf Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Tue, 10 May 2022 21:01:31 +0900 Subject: [PATCH 11/14] =?UTF-8?q?[Fix]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=88=98=EC=A0=95=20=EC=84=9C=EB=B2=84=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=ED=95=B4=EA=B2=B0=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../APIServices/AuthAPI/PasswordAPI.swift | 28 ++++--------------- .../APIServices/AuthAPI/PasswordService.swift | 11 ++++---- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift index 24a8fc4..92a1d52 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordAPI.swift @@ -15,14 +15,16 @@ public class PasswordAPI { public init() { } - func putNewPassword(completion: @escaping (NetworkResult) -> Void, email: String, password: String) { - courseProvider.request(.putChangedPassword(email: email, password: password)) { (result) in + func postNewPassword(completion: @escaping (NetworkResult) -> Void, email: String, password: String) { + courseProvider.request(.postChangedPassword(email: email, password: password)) { (result) in + print(result) switch result { case .success(let response): + print("response 제대로 오는지 확인: ", response) let statusCode = response.statusCode let data = response.data - let networkResult = self.judgeChangePasswordStatus(by: statusCode, data) + let networkResult = self.judgeStatus(by: statusCode, data) completion(networkResult) case .failure(let err): @@ -100,24 +102,4 @@ public class PasswordAPI { return .networkFail } } - -// private func judgeGetEmailCodeStatus(by statusCode: Int, _ data: Data) -> NetworkResult { -// -// let decoder = JSONDecoder() -// guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) else { -// return .pathErr -// } -// -// switch statusCode { -// case 200: -// return .success(decodedData.data) -// case 400..<500: -// return .requestErr(decodedData.message) -// case 500: -// return .serverErr -// default: -// return .networkFail -// } -// } } - diff --git a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift index 779a41b..babc1bd 100644 --- a/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift +++ b/Hyangyu/Hyangyu/Sources/APIServices/AuthAPI/PasswordService.swift @@ -9,7 +9,7 @@ import Foundation import Moya enum PasswordService { - case putChangedPassword(email: String, password: String) + case postChangedPassword(email: String, password: String) case postEmailCode(email: String) case checkCode(email: String, authNum: String) @@ -22,7 +22,7 @@ extension PasswordService: TargetType { var path: String { switch self { - case .putChangedPassword(_, _): + case .postChangedPassword(_, _): return Const.URL.passwordURL case .postEmailCode(let email): return Const.URL.findPasswordURL + "/\(email)" @@ -33,8 +33,8 @@ extension PasswordService: TargetType { var method: Moya.Method { switch self { - case .putChangedPassword(_, _): - return .put + case .postChangedPassword(_, _): + return .post case .postEmailCode(_): return .post case .checkCode(_, _): @@ -48,10 +48,11 @@ extension PasswordService: TargetType { var task: Task { switch self { - case .putChangedPassword(let email, let password): + case .postChangedPassword(let email, let password): // body가 있는 request - JSONEncoding.default return .requestParameters(parameters: [ "email": email, + "username": "", "password": password ], encoding: JSONEncoding.default) case .postEmailCode(_): From 44aace0c02f1f34c366c493b919277a9bfb9bac4 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Tue, 10 May 2022 21:05:28 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[Feat]=20=EC=83=88=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20UI=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 새 비밀번호 입력 시작과 입력 끝 시 테두리 컬러 변경되도록 수정 - 새 비밀번호 서버 연결 --- .../NewPasswordViewController.swift | 234 +++++++++++++++++- .../NewPassword/NewPasswordViewController.xib | 62 ++--- 2 files changed, 253 insertions(+), 43 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.swift index 023ef09..5840f52 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.swift @@ -8,22 +8,232 @@ import UIKit class NewPasswordViewController: UIViewController { - + + var user = User.shared + private var isPasswordRight: Bool = false + private var isConfirmPasswordRight: Bool = false + + @IBOutlet weak var passwordTextFieldView: UIView! + @IBOutlet weak var passwordTextField: UITextField! + @IBOutlet weak var passwordWarningLabel: UILabel! + + @IBOutlet weak var confirmPasswordTextFieldView: UIView! + @IBOutlet weak var confirmPasswordTextField: UITextField! + @IBOutlet weak var confirmPasswordWarningLabel: UILabel! + + @IBOutlet weak var passwordSecureButton: UIButton! + @IBOutlet weak var confirmPasswordSecureButton: UIButton! + @IBOutlet weak var confirmButton: UIButton! + override func viewDidLoad() { super.viewDidLoad() - - // Do any additional setup after loading the view. + + initNavigationBar() + configureUI() + setDelegation() + } + + private func initNavigationBar() { + self.navigationController?.initWithBackButton() + } + + private func configureUI() { + [passwordTextFieldView, confirmPasswordTextFieldView].forEach({$0?.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) }) + [passwordWarningLabel, confirmPasswordWarningLabel].forEach({$0?.isHidden = true }) + + confirmButtonDisable() + confirmButton.makeRounded(radius: 12) + + } + + // MARK: - Functions + private func checkTextField() { + // 입력 중 일때 + passwordTextField.addTarget(self, action: #selector(self.checkPasswordTextField), for: .editingChanged) + confirmPasswordTextField.addTarget(self, action: #selector(self.checkConfirmPasswordTextField), for: .editingChanged) + + } + + // 비밀번호 텍필 값 바뀔 때 + @objc private func checkPasswordTextField() { + // 비밀번호 + let passwordCount = passwordTextField.text?.count ?? 0 + if passwordCount > 11 { + passwordTextField.deleteBackward() + } + isPasswordRight = checkPassword(password: passwordTextField.text ?? "") + passwordWarningLabel.isHidden = isPasswordRight || !passwordTextField.hasText ? true : false + passwordTextFieldView.layer.borderColor = isPasswordRight || !passwordTextField.hasText ? UIColor.systemGray2.cgColor : UIColor.systemRed.cgColor + + // 비밀번호 확인 텍필 + isConfirmPasswordRight = checkConfirmPassword(input: passwordTextField.text ?? "") + confirmPasswordWarningLabel.isHidden = isConfirmPasswordRight || !confirmPasswordTextField.hasText ? true : false + confirmPasswordTextFieldView.layer.borderColor = isConfirmPasswordRight || !confirmPasswordTextField.hasText ? UIColor.systemGray2.cgColor : UIColor.systemRed.cgColor + } + + // 비밀번호 확인 텍필 값 바뀔 떄 + @objc private func checkConfirmPasswordTextField() { + isConfirmPasswordRight = checkConfirmPassword(input: passwordTextField.text ?? "") + confirmPasswordWarningLabel.isHidden = isConfirmPasswordRight || !confirmPasswordTextField.hasText ? true : false + confirmPasswordTextFieldView.layer.borderColor = isConfirmPasswordRight || !confirmPasswordTextField.hasText ? UIColor.systemGray2.cgColor : UIColor.systemRed.cgColor + } + + @IBAction func updateCurrentStatus(_ sender: Any) { + passwordTextField.isSecureTextEntry.toggle() + if passwordTextField.isSecureTextEntry { + passwordSecureButton.setImage(UIImage(systemName: "eye"), for: .normal) + } else { + passwordSecureButton.setImage(UIImage(systemName: "eye.slash"), for: .normal) + } + } + + @IBAction func updateConfirmStatus(_ sender: UIButton) { + confirmPasswordTextField.isSecureTextEntry.toggle() + if confirmPasswordTextField.isSecureTextEntry { + confirmPasswordSecureButton.setImage(UIImage(systemName: "eye"), for: .normal) + } else { + confirmPasswordSecureButton.setImage(UIImage(systemName: "eye.slash"), for: .normal) + } + } + + // 화면 터치시 키보드 내림 + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + self.view.endEditing(true) + } + + private func checkConfirmPassword (input: String) -> Bool { + return passwordTextField.text == confirmPasswordTextField.text + } + + private func setDelegation() { + passwordTextField.delegate = self + confirmPasswordTextField.delegate = self + } + + private func confirmButtonEnable() { + confirmButton.isEnabled = true + confirmButton.alpha = 1.0 + } + + private func confirmButtonDisable() { + confirmButton.isEnabled = false + confirmButton.alpha = 0.3 + } + + private func showFormatError() { + passwordWarningLabel.isHidden = false + passwordWarningLabel.text = "6~12자리의 영문, 숫자, 특수문자만 사용 가능합니다" + passwordWarningLabel.textColor = UIColor.systemRed + confirmButtonDisable() + } + + private func hideFormatError() { + passwordWarningLabel.isHidden = false + passwordWarningLabel.text = "사용 가능한 비밀번호입니다" + passwordWarningLabel.textColor = UIColor.systemGreen + confirmButtonDisable() + } + + private func checkPasswordSameness() { + if passwordTextField.text == confirmPasswordTextField.text { + confirmPasswordWarningLabel.isHidden = false + confirmPasswordWarningLabel.text = "비밀번호가 일치합니다" + confirmPasswordWarningLabel.textColor = .systemGreen + confirmButtonEnable() + } else { + confirmPasswordWarningLabel.isHidden = false + confirmPasswordWarningLabel.text = "비밀번호가 일치하지 않습니다." + confirmPasswordWarningLabel.textColor = .systemRed + confirmButtonDisable() + } + } + + // 패스워드 정규식 체크 + private func checkPassword(password: String) -> Bool { + let passwordRegEx = "[A-Z0-9a-z!@#$%^&*()_+=-]{6,12}" + let passwordText = NSPredicate(format: "SELF MATCHES %@", passwordRegEx) + return passwordText.evaluate(with: password) + } + + @IBAction func touchCompleteButton(_ sender: UIButton) { + postNewPassword() + } + + func popToRootViewController() { + self.navigationController?.popToRootViewController(animated: true) + } +} - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. +extension NewPasswordViewController: UITextFieldDelegate { + func textFieldDidBeginEditing(_ textField: UITextField) { + + if textField == passwordTextField { + passwordTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) + } else if textField == confirmPasswordTextField { + confirmPasswordTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) + } + } - */ + + func textFieldDidEndEditing(_ textField: UITextField) { + + if textField == passwordTextField { + passwordTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) + } else if textField == confirmPasswordTextField { + confirmPasswordTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) + } + + guard let password = passwordTextField.text else { + return + } + + if password != "" { + if checkPassword(password: password) { + if confirmPasswordTextField.text != "" { + checkPasswordSameness() + } else { + hideFormatError() + } + } else { + showFormatError() + } + } else { + passwordWarningLabel.isHidden = true + } + } +} +extension NewPasswordViewController { + func postNewPassword() { + guard let password = passwordTextField.text else { + return + } + user.password = password + + guard let email = user.email else { + return + } + + PasswordAPI.shared.postNewPassword(completion: { (response) in + switch response { + case .success(let data): + if let data = data as? String { + self.showToast(message: data) + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.dismiss(animated: true) + } + } + self.popToRootViewController() + case .requestErr(let message): + print("requestErr", message) + case .pathErr: + print("pathErr") + case .serverErr: + print("serverErr") + case .networkFail: + print("networkFail") + } + }, email: email, password: password) + } } diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib index 658d71a..2dade29 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/NewPassword/NewPasswordViewController.xib @@ -35,22 +35,8 @@ - - - + + - + - + + - - - - - - + + + + + From cc6f23a888856b2145cf864b1084ad98064cc318 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Tue, 10 May 2022 21:06:23 +0900 Subject: [PATCH 13/14] =?UTF-8?q?[Fix]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B0=BE=EA=B8=B0=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SignUpUser -> User로 변경 --- .../FindPasswordViewController.swift | 29 ++++++++++++------- .../FindPasswordViewController.xib | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift index 390f378..bb89e2e 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.swift @@ -11,7 +11,7 @@ class FindPasswordViewController: UIViewController { // MARK: - Properties - let user = SignUpUser.shared + let user = User.shared var isResetCodeEnabled: Bool = false private var userResetCode: Int = 0 private var isEmailRight: Bool = false @@ -99,6 +99,11 @@ class FindPasswordViewController: UIViewController { nextButton.alpha = 0.3 } + // 화면 터치시 키보드 내림 + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + self.view.endEditing(true) + } + private func pushToNewPasswordViewController(email: String) { let resetCodeViewController = ResetCodeViewController.loadFromNib() resetCodeViewController.email = email @@ -114,22 +119,25 @@ class FindPasswordViewController: UIViewController { extension FindPasswordViewController: UITextFieldDelegate { func textFieldDidBeginEditing(_ textField: UITextField) { + emailWarningLabel.isHidden = true emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) } - func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { - guard let text = textField.text else { - return false - } - checkEmailFormat(email: text) - return true - } +// func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { +// guard let text = textField.text else { +// return false +// } +// return true +// } func textFieldDidEndEditing(_ textField: UITextField) { guard let text = textField.text else { return } - checkEmailFormat(email: text) + if text != "" { + checkEmailFormat(email: text) + } + emailTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) } @@ -149,15 +157,14 @@ extension FindPasswordViewController { self.user.email = email print("data.message: \(data)") self.emailWarningLabel.text = "\(data)" - self.showToast(message: data) self.pushToNewPasswordViewController(email: email) } case .requestErr(let message): self.emailWarningLabel.isHidden = false if let message = message as? String { self.emailWarningLabel.text = "\(message)" - self.pushToNewPasswordViewController(email: email) } + self.pushToNewPasswordViewController(email: email) case .pathErr: print(".pathErr") case .serverErr: diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib index 8b8a11d..83f0758 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/FindPassword/FindPasswordViewController.xib @@ -38,7 +38,7 @@ - + From 3bd95cc6819ded7d9dc171ae4bdb08a13031f4f1 Mon Sep 17 00:00:00 2001 From: bsorinnn Date: Tue, 10 May 2022 21:07:55 +0900 Subject: [PATCH 14/14] =?UTF-8?q?[Chore]=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 테스트 용으로 만든 Print 정리 - 검색한 단어 저장 CoreData 코드 없애기 --- Hyangyu/Hyangyu/Sources/AppDelegate.swift | 13 ------- .../MyPage/ProfileEditViewController.swift | 3 +- .../ResetCode/ResetCodeViewController.swift | 39 ++++++++----------- .../ResetCode/ResetCodeViewController.xib | 2 +- 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/Hyangyu/Hyangyu/Sources/AppDelegate.swift b/Hyangyu/Hyangyu/Sources/AppDelegate.swift index 915c428..92b1a11 100644 --- a/Hyangyu/Hyangyu/Sources/AppDelegate.swift +++ b/Hyangyu/Hyangyu/Sources/AppDelegate.swift @@ -11,19 +11,6 @@ import CoreData @main class AppDelegate: UIResponder, UIApplicationDelegate { - - // MARK: - Core Data - lazy var persistentContainer: NSPersistentContainer = { - // name: Core Data 만든 파일명 지정 - let container = NSPersistentContainer(name: "RecentSearchTerm") - container.loadPersistentStores(completionHandler: { (storeDescription, error) in - if let error = error { - fatalError("Unresolved error, \((error as NSError).userInfo)") - } - }) - return container - }() - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift index 58e1945..b6fc322 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/MyPage/ProfileEditViewController.swift @@ -214,8 +214,7 @@ final class ProfileEditViewController: UIViewController { @objc func touchToPickImage() { actionSheetAlert() } - - + private func actionSheetAlert() { let imagePickerController = UIImagePickerController() imagePickerController.delegate = self diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift index 6b2667c..dd1d8f9 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.swift @@ -8,7 +8,7 @@ import UIKit class ResetCodeViewController: UIViewController { - + // MARK: - Properties var email: String? // 이메일 @@ -19,15 +19,14 @@ class ResetCodeViewController: UIViewController { @IBOutlet weak var warningLabel: UILabel! @IBOutlet weak var completeButton: UIButton! - // MARK: - View Life Cycle + // MARK: - View Life Cycle override func viewDidLoad() { - print("이거 실행되긴 하니?") super.viewDidLoad() initNavigationBar() setDelegation() configureUI() - + } // MARK: - Functions @@ -41,7 +40,7 @@ class ResetCodeViewController: UIViewController { @objc private func activateCodeTextField() { codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) } - + // 텍스트 필드 비활성화 @objc private func inactivateCodeTextField() { codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray6.cgColor) @@ -76,19 +75,19 @@ class ResetCodeViewController: UIViewController { completeButton.isEnabled = true completeButton.alpha = 1.0 } - + private func makeCompleteButtonDisable() { completeButton.isEnabled = false completeButton.alpha = 0.3 } - + func validateCode(code: String) -> Bool { // Email 정규식 let codeRegEx = "^[a-z0-9+]{6}$" let codeTest = NSPredicate(format: "SELF MATCHES %@", codeRegEx) return codeTest.evaluate(with: code) } - + private func checkCodeFormat(userInput: String) { if validateCode(code: userInput) { makeCompleteButtonEnable() @@ -96,16 +95,19 @@ class ResetCodeViewController: UIViewController { makeCompleteButtonDisable() } } - + @IBAction func touchCompleteButton(_ sender: Any) { - print("touched Complete Button") sendCode() } + // 화면 터치시 키보드 내림 + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + self.view.endEditing(true) + } + private func pushToNewPasswordViewController(email: String) { let newPasswordViewController = NewPasswordViewController.loadFromNib() self.navigationController?.pushViewController(newPasswordViewController, animated: true) - } } @@ -113,7 +115,6 @@ class ResetCodeViewController: UIViewController { // MARK: - UITextFieldDelegate extension ResetCodeViewController: UITextFieldDelegate { func textFieldDidEndEditing(_ textField: UITextField) { - print("textFieldDidendEditing") guard let text = textField.text else { return } @@ -121,7 +122,6 @@ extension ResetCodeViewController: UITextFieldDelegate { } func textFieldDidBeginEditing(_ textField: UITextField) { - print("저 실행되었습니다.") warningLabel.isHidden = true codeTextFieldView.makeRoundedWithBorder(radius: 12, color: UIColor.systemGray2.cgColor) completeButton.isEnabled = true @@ -136,7 +136,6 @@ extension ResetCodeViewController: UITextFieldDelegate { extension ResetCodeViewController { func sendCode() { - print("저 실행됩니다요") guard let code = codeTextField.text else { return } @@ -144,20 +143,14 @@ extension ResetCodeViewController { PasswordAPI.shared.checkCode(completion: { response in switch response { case .success(let data): - if let data = data as? String { - self.showToast(message: data) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - self.dismiss(animated: true) - } self.pushToNewPasswordViewController() case .requestErr(let message): if let message = message as? String { print(message) self.showToast(message: message) - } - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - self.dismiss(animated: true) + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.dismiss(animated: true) + } } print("requestErr", message) case .pathErr: diff --git a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib index 1e04a8a..ede97b3 100644 --- a/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib +++ b/Hyangyu/Hyangyu/Sources/ViewControllers/ResetCode/ResetCodeViewController.xib @@ -38,7 +38,7 @@ - +