@@ -7,6 +7,7 @@
9import UIKit
9import UIKit
10+import TinyConstraints
11class CodeViewController: UIViewController {
12class CodeViewController: UIViewController {
@@ -17,12 +18,16 @@ class CodeViewController: UIViewController {
17 @IBOutlet weak var f5: UITextField!
18 @IBOutlet weak var f5: UITextField!
18 @IBOutlet weak var f6: UITextField!
19 @IBOutlet weak var f6: UITextField!
21+ var loading = UIActivityIndicatorView(style: .gray)
20 var onSuccessLogIn: (()->())?
23 var onSuccessLogIn: (()->())?
22 override func viewDidLoad() {
25 override func viewDidLoad() {
23 super.viewDidLoad()
26 super.viewDidLoad()
24 setUpConstraint()
27 setUpConstraint()
29+ navigationItem.title = DataStorage.standard.getEmail()
26 f1.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
31 f1.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
27 f2.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
32 f2.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
28 f3.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
33 f3.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
@@ -31,6 +36,12 @@ class CodeViewController: UIViewController {
31 f6.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
36 f6.addTarget(self, action: #selector(textFiledDidChange(textField:)), for: .editingChanged)
39+ override func viewWillDisappear(_ animated: Bool) {
40+ super.viewWillDisappear(animated)
42+ loading.stopAnimating()
34 override func viewWillAppear(_ animated: Bool) {
45 override func viewWillAppear(_ animated: Bool) {
35 super.viewWillAppear(animated)
46 super.viewWillAppear(animated)
@@ -62,28 +73,56 @@ class CodeViewController: UIViewController {
76+ func presentAlertInvalidData(with text: String)
78+ let alert = UIAlertController(title: "Invalid code", message: text, preferredStyle: .alert)
79+ alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
80+ self.present(alert, animated: true, completion: nil)
82+ loading.stopAnimating()
65 @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
85 @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
67 @IBAction func whereToGoNext(_ sender: UIButton)
87 @IBAction func whereToGoNext(_ sender: UIButton)
89+ guard let f1t = f1.text, let f2t = f2.text, let f3t = f3.text, let f4t = f4.text, let f5t = f5.text, let f6t = f6.text else {
90+ presentAlertInvalidData(with: "Some fields are missing");
94+ if f1t.isEmpty || f2t.isEmpty || f3t.isEmpty || f4t.isEmpty || f5t.isEmpty || f6t.isEmpty {
95+ presentAlertInvalidData(with: "Some fields are missing");
69 let code = "\(f1.text!)\(f2.text!)\(f3.text!)\(f4.text!)\(f5.text!)\(f6.text!)"
99 let code = "\(f1.text!)\(f2.text!)\(f3.text!)\(f4.text!)\(f5.text!)\(f6.text!)"
70 if let codeToInt = Int(code)
100 if let codeToInt = Int(code)
102+ loading.startAnimating()
72− Model.verify(with: codeToInt) { _ in
103+ Model.verify(with: codeToInt) { [weak self] in
73 // if everything is okay we can authemticicate
104 // if everything is okay we can authemticicate
106+ self?.presentAlertInvalidData(with: "Wrong code. Try again!")
107+ self?.loading.stopAnimating()
74− // Model.authemticiateMe
110+ // Model.authemticiateMe
75− Model.authenticateMe { [weak self] (res) in
111+ Model.authenticateMe { [weak self] (res) in
76− if res {
112+ if res {
77− self?.onSuccessLogIn?()
113+ self?.onSuccessLogIn?()
86− func setUpConstraint(){
122+ func setUpConstraint()
124+ self.view.addSubview(loading)
125+ loading.centerInSuperview()
87 // for keyboard notifications
126 // for keyboard notifications
88 NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotifications), name: UIResponder.keyboardWillShowNotification, object: nil)
127 NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotifications), name: UIResponder.keyboardWillShowNotification, object: nil)