From 5db188546d509627a460ef9858dfd80329040efe Mon Sep 17 00:00:00 2001 From: gme_2 Date: Tue, 11 Sep 2018 13:25:39 +0900 Subject: [PATCH] validation added in registration --- GMERemittance/AppDelegate.swift | 2 -- .../Wireframe/LoginWireframe.swift | 4 +++ .../Interactor/RegisterInteractor.swift | 26 +++++++++++++++- .../Interactor/RegisterInteractorIO.swift | 2 +- .../Presenter/RegisterPresenter.swift | 7 ++++- .../User Interface/View/Register.storyboard | 31 +++++++++---------- .../View/RegisterViewController.swift | 20 ++++++------ .../View/RegisterViewInterface.swift | 3 ++ 8 files changed, 65 insertions(+), 30 deletions(-) diff --git a/GMERemittance/AppDelegate.swift b/GMERemittance/AppDelegate.swift index 5eec49ff..4e9d412a 100644 --- a/GMERemittance/AppDelegate.swift +++ b/GMERemittance/AppDelegate.swift @@ -129,9 +129,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD let alert = aps["alert"] as? NSDictionary, let _ = alert["body"] as? String, let _ = alert["title"] as? String { -// print("Title: \(title) \nBody:\(body)") let codeID = userInfo["code"] as? String -// print("code", codeID!) self.redirectWithPushNotification(notificationCode: codeID!) } diff --git a/GMERemittance/Module/Login/User Interface/Wireframe/LoginWireframe.swift b/GMERemittance/Module/Login/User Interface/Wireframe/LoginWireframe.swift index d45fb60d..e7d3b782 100644 --- a/GMERemittance/Module/Login/User Interface/Wireframe/LoginWireframe.swift +++ b/GMERemittance/Module/Login/User Interface/Wireframe/LoginWireframe.swift @@ -11,6 +11,7 @@ import UIKit class LoginWireframe { weak var view: UIViewController! lazy var mainWireframe = MainWireframe.shared + lazy var registerWireframe = RegisterWireframe() } @@ -39,6 +40,9 @@ extension LoginWireframe: LoginWireframeInput { } func register() { + if let navigation = self.view.navigationController { + self.registerWireframe.pushMainView(in: navigation) + } } diff --git a/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift b/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift index d43b185e..041f4def 100644 --- a/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift +++ b/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift @@ -56,11 +56,36 @@ class RegisterInteractor { return "172017F9EC11222E8107142733" } // MARK: Converting entities + + private func isValid(userName: String, password: String, confirmPassword: String) -> (isValid: Bool, error: Error){ + var error = "" + var isValid = true + if userName.isEmpty { + error = error + "Username field is required."; isValid = false} + if password.isEmpty { + error = error + "\n Password filed is required." + isValid = false + }else { + if password != confirmPassword { + error = error + "\n Passwords do not match." + } + } + + let _error = NSError.init(domain: "LoginInteractor", code: 0, userInfo: [NSLocalizedDescriptionKey : error]) + return (isValid, _error) + } + } extension RegisterInteractor: RegisterInteractorInput { func register(model: RegisterRequestModel) { + let validationResult = self.isValid(userName: model.username ?? "", password: model.password ?? "", confirmPassword: model.confirmPassword ?? "") + if !validationResult.isValid { + self.output?.show(error: validationResult.error) + return + } + model.uuid = self.getUUid() model.appVersion = self.getAppVersion() model.phoneBrand = self.getPhoneBrand() @@ -68,7 +93,6 @@ extension RegisterInteractor: RegisterInteractorInput { model.osVersion = self.getOsVersion() model.fcmId = self.getFcmToken() let clientId = self.getCliendId() - let params = model.serialize() diff --git a/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractorIO.swift b/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractorIO.swift index 9f26a374..a846229b 100644 --- a/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractorIO.swift +++ b/GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractorIO.swift @@ -11,5 +11,5 @@ protocol RegisterInteractorInput: class { } protocol RegisterInteractorOutput: class { - + func show(error: Error) } diff --git a/GMERemittance/Module/Register/User Interface/Presenter/RegisterPresenter.swift b/GMERemittance/Module/Register/User Interface/Presenter/RegisterPresenter.swift index 0b33787c..77250860 100644 --- a/GMERemittance/Module/Register/User Interface/Presenter/RegisterPresenter.swift +++ b/GMERemittance/Module/Register/User Interface/Presenter/RegisterPresenter.swift @@ -23,14 +23,19 @@ class RegisterPresenter { extension RegisterPresenter: RegisterModuleInterface { func register(model: RegisterRequestModel) { + self.view?.showLoading() self.interactor?.register(model: model) } + } // MARK: Register interactor output interface extension RegisterPresenter: RegisterInteractorOutput { - + func show(error: Error) { + self.view?.hideLoading() + self.view?.show(error: error.localizedDescription) + } } diff --git a/GMERemittance/Module/Register/User Interface/View/Register.storyboard b/GMERemittance/Module/Register/User Interface/View/Register.storyboard index c67fe241..a6f9ea69 100644 --- a/GMERemittance/Module/Register/User Interface/View/Register.storyboard +++ b/GMERemittance/Module/Register/User Interface/View/Register.storyboard @@ -36,8 +36,8 @@ - - + + @@ -69,19 +69,19 @@ - + - + - + - + - + @@ -115,10 +115,10 @@ - + - + @@ -151,10 +151,10 @@ - + - + @@ -258,9 +258,8 @@ - + - diff --git a/GMERemittance/Module/Register/User Interface/View/RegisterViewController.swift b/GMERemittance/Module/Register/User Interface/View/RegisterViewController.swift index 718ddb1e..2ed5bd5d 100644 --- a/GMERemittance/Module/Register/User Interface/View/RegisterViewController.swift +++ b/GMERemittance/Module/Register/User Interface/View/RegisterViewController.swift @@ -34,15 +34,6 @@ class RegisterViewController: UIViewController { } - -// ClientId - -// AppVersion -// phoneBrand -// phoneOs -// deviceId -// osVersion - @IBAction func register(_ sender: UIButton) { let email = self.emailTextField.text! let password = self.passwordTextField.text! @@ -60,11 +51,22 @@ class RegisterViewController: UIViewController { private func setup() { // all setup should be done here + self.setupPicturedNavBar() } } // MARK: RegisterViewInterface extension RegisterViewController: RegisterViewInterface { + func showLoading() { + self.showProgressHud() + } + func hideLoading() { + self.hideProgressHud() + } + + func show(error: String) { + self.alert(message: error) + } } diff --git a/GMERemittance/Module/Register/User Interface/View/RegisterViewInterface.swift b/GMERemittance/Module/Register/User Interface/View/RegisterViewInterface.swift index 0f94c122..18d17fcb 100644 --- a/GMERemittance/Module/Register/User Interface/View/RegisterViewInterface.swift +++ b/GMERemittance/Module/Register/User Interface/View/RegisterViewInterface.swift @@ -7,4 +7,7 @@ // protocol RegisterViewInterface: class { + func showLoading() + func hideLoading() + func show(error: String) }