You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

  1. //
  2. // PasswordInputViewController.swift
  3. // GME Remit
  4. //
  5. // Created by Amrit Giri on 6/25/20.
  6. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class PasswordInputViewController: UIViewController {
  10. @IBOutlet weak var passwordTextField: ValidationTextField!
  11. @IBOutlet weak var doneBtn: UIButton!
  12. @IBOutlet weak var cancelBtn: UIButton!
  13. @IBOutlet weak var titleLbl: UILabel!
  14. private var validDic = [
  15. "pw": false
  16. ]
  17. var enteredPassword: ((String)->())?
  18. private var isValid = false {
  19. didSet {
  20. doneBtn.isEnabled = isValid
  21. doneBtn.backgroundColor = isValid ? .themeRed : .lightGray
  22. }
  23. }
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. self.isValid = false
  27. self.cancelBtn.backgroundColor = .themeBlue
  28. self.cancelBtn.isEnabled = true
  29. passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
  30. passwordTextField.validCondition = { $0.count > 5 }
  31. passwordTextField.isSecureTextEntry = true
  32. titleLbl.text = "enter_login_password_text".localized()
  33. passwordTextField.errorMessage = "password_policy_error".localized()
  34. passwordTextField.titleText = "password_text".localized()
  35. passwordTextField.placeholder = "enter_login_password_text".localized()
  36. doneBtn.setTitle("done_text".localized(), for: .normal)
  37. cancelBtn.setTitle("cancel_text".localized(), for: .normal)
  38. // Do any additional setup after loading the view.
  39. }
  40. @objc private func editingChanged(_ textField: ValidationTextField) {
  41. switch textField {
  42. case passwordTextField:
  43. validDic["pw"] = passwordTextField.isValid
  44. default: ()
  45. }
  46. isValid = validDic.allSatisfy { $0.value }
  47. }
  48. @IBAction func done(_ sender: UIButton) {
  49. self.enteredPassword?(self.passwordTextField.text ?? "")
  50. self.dismiss(animated: true, completion: nil)
  51. }
  52. @IBAction func cancel(_ sender: UIButton) {
  53. self.dismiss(animated: true, completion: nil)
  54. }
  55. }