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.isEnabled = true
  28. passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
  29. passwordTextField.validCondition = { $0.count > 5 }
  30. passwordTextField.isSecureTextEntry = true
  31. titleLbl.text = "enter_login_password_text".localized()
  32. passwordTextField.errorMessage = "password_policy_error".localized()
  33. passwordTextField.titleText = "password_text".localized()
  34. passwordTextField.placeholder = "enter_login_password_text".localized()
  35. doneBtn.setTitle("done_text".localized(), for: .normal)
  36. passwordTextField.becomeFirstResponder()
  37. // Do any additional setup after loading the view.
  38. }
  39. @objc private func editingChanged(_ textField: ValidationTextField) {
  40. switch textField {
  41. case passwordTextField:
  42. validDic["pw"] = passwordTextField.isValid
  43. default: ()
  44. }
  45. isValid = validDic.allSatisfy { $0.value }
  46. }
  47. @IBAction func done(_ sender: UIButton) {
  48. self.enteredPassword?(self.passwordTextField.text ?? "")
  49. self.dismiss(animated: true, completion: nil)
  50. }
  51. @IBAction func cancel(_ sender: UIButton) {
  52. self.dismiss(animated: true, completion: nil)
  53. }
  54. }