|
|
@ -56,6 +56,17 @@ class LoginViewController: UIViewController { |
|
|
|
|
|
|
|
var presenter: LoginModuleInterface? |
|
|
|
|
|
|
|
private var validDic = [ |
|
|
|
"id": false, |
|
|
|
"pw": false |
|
|
|
] |
|
|
|
|
|
|
|
private var isValid = false { |
|
|
|
didSet{ |
|
|
|
loginButton.isEnabled = isValid |
|
|
|
loginButton.backgroundColor = isValid ? AppConstants.themeRedColor : .lightGray |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: VC's Life cycle |
|
|
|
|
|
|
@ -89,8 +100,7 @@ class LoginViewController: UIViewController { |
|
|
|
|
|
|
|
@IBAction func login(_ sender: UIButton) { |
|
|
|
let username = self.userNameTextField.text! |
|
|
|
let password = self.passwordTextField.text! |
|
|
|
self.presenter?.login(userName: username, password: password, encryptedPassword: self.encryptedPassword ?? "") |
|
|
|
self.presenter?.login(userName: username, encryptedPassword: self.encryptedPassword ?? "") |
|
|
|
} |
|
|
|
// MARK: Other Functions |
|
|
|
|
|
|
@ -107,43 +117,29 @@ class LoginViewController: UIViewController { |
|
|
|
userNameTextField.statusImageView.isHidden = true |
|
|
|
userNameTextField.validCondition = { $0.count > 3 } |
|
|
|
userNameTextField.errorMessage = "userid_error_text".localized() |
|
|
|
userNameTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged) |
|
|
|
|
|
|
|
passwordTextField.titleFont = font |
|
|
|
passwordTextField.statusImageView.isHidden = true |
|
|
|
passwordTextField.validCondition = { $0.count > 5 } |
|
|
|
passwordTextField.errorMessage = "password_policy_error".localized() |
|
|
|
passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged) |
|
|
|
|
|
|
|
loginButton.layer.cornerRadius = 10 |
|
|
|
} |
|
|
|
|
|
|
|
func authenticateUser() { |
|
|
|
let context : LAContext = LAContext() |
|
|
|
var error: NSError? |
|
|
|
let reasonString = "Authentication is needed to access Gme Remit application." |
|
|
|
|
|
|
|
if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) { |
|
|
|
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString) { (success, error) in |
|
|
|
if success { |
|
|
|
print("authenticated") |
|
|
|
} |
|
|
|
else { |
|
|
|
// print(evalPolicyError?.localizedDescription) |
|
|
|
guard let error = error as NSError? else {return} |
|
|
|
switch error.code { |
|
|
|
case LAError.systemCancel.rawValue: |
|
|
|
print("Authentication was cancell by the system") |
|
|
|
case LAError.userCancel.rawValue: |
|
|
|
print("Authentication cancelled by the user") |
|
|
|
case LAError.userFallback.rawValue: |
|
|
|
print("user selected to enter custome password") |
|
|
|
default: |
|
|
|
print("Authentication failed.") |
|
|
|
|
|
|
|
@objc private func editingChanged(_ textField: ValidationTextField) { |
|
|
|
switch textField { |
|
|
|
case userNameTextField: |
|
|
|
userNameTextField.filterForUserIDFormat() |
|
|
|
validDic["id"] = userNameTextField.isValid |
|
|
|
case passwordTextField: |
|
|
|
validDic["pw"] = passwordTextField.isValid |
|
|
|
default: () |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
isValid = validDic.reduce(true){ $0 && $1.value} |
|
|
|
} |
|
|
|
|
|
|
|
private func configureLanguage() { |
|
|
@ -166,7 +162,6 @@ class LoginViewController: UIViewController { |
|
|
|
} |
|
|
|
|
|
|
|
func setupColor() { |
|
|
|
self.loginButton.backgroundColor = AppConstants.themeRedColor |
|
|
|
self.headerTitle.textColor = AppConstants.themeRedColor |
|
|
|
} |
|
|
|
|
|
|
|