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.

106 lines
3.3 KiB

6 years ago
  1. //
  2. // FillRecoveryCodeViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 12/20/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. class FillRecoveryCodeViewController: UIViewController {
  11. private var fillrecoverycodeviewmodel = FillRecoveryCodeViewModel()
  12. private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  13. @IBOutlet weak var textFieldRecoveryCode: UITextField!
  14. @IBAction func gotoPreviousView(_ sender: Any) {
  15. _ = navigationController?.popViewController(animated: true)
  16. }
  17. @IBAction func submitRecoveryCode(_ sender: Any) {
  18. let recoverycode: String = textFieldRecoveryCode.text!
  19. fillrecoverycodeviewmodel.setCode(code: recoverycode)
  20. switch fillrecoverycodeviewmodel.checkCodeLength() {
  21. case .Valid:
  22. disableUserInteractions()
  23. showActivityIndicator(activityIndicator: activityIndicator)
  24. fillrecoverycodeviewmodel.resetUser()
  25. case .InValid(let error):
  26. self.popUpMessageError(value: 11, message: error)
  27. }
  28. }
  29. override func viewDidLoad() {
  30. super.viewDidLoad()
  31. self.hideKeyboardWhenTappedAround()
  32. textFieldRecoveryCode.delegate = self
  33. fillrecoverycodeviewmodel.authenticated.value = nil
  34. fillrecoverycodeviewmodel.internetConnection.value = nil
  35. fillrecoverycodeviewmodel.fillCodeConnectionTimeOut.value = nil
  36. /**
  37. connection timeout
  38. */
  39. fillrecoverycodeviewmodel.fillCodeConnectionTimeOut.bind { [unowned self] in
  40. guard $0 != nil else {
  41. return
  42. }
  43. self.enableUserInteractions()
  44. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  45. self.popUpMessage(value: 20)
  46. }
  47. /**
  48. Internet Check
  49. */
  50. fillrecoverycodeviewmodel.internetConnection.bind { [unowned self] in
  51. guard $0 != nil else {
  52. return
  53. }
  54. self.enableUserInteractions()
  55. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  56. self.popUpMessage(value: 15)
  57. }
  58. /**
  59. Check the authenticated code
  60. */
  61. fillrecoverycodeviewmodel.authenticated.bind { [unowned self] in
  62. guard $0 != nil else {
  63. return
  64. }
  65. self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  66. self.enableUserInteractions()
  67. guard $0! else {
  68. self.popUpMessageError(value: 10, message: self.fillrecoverycodeviewmodel.getErrorMessage())
  69. return
  70. }
  71. self.performSegue(withIdentifier: "changePassword", sender: nil)
  72. }
  73. }
  74. }
  75. extension FillRecoveryCodeViewController: UITextFieldDelegate {
  76. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  77. guard let code = textField.text else {
  78. return true
  79. }
  80. let length = code.characters.count + string.characters.count - range.length
  81. return length <= 4
  82. }
  83. }