Commit cc1ae95ceebb8235057740ed54f25ded88594d05

Authored by Dmitriy Tymofyeyev
1 parent 2bd7cbf5

18.07

@@ -36,37 +36,5 @@ @@ -36,37 +36,5 @@
36 landmarkType = "7"> 36 landmarkType = "7">
37 </BreakpointContent> 37 </BreakpointContent>
38 </BreakpointProxy> 38 </BreakpointProxy>
39 - <BreakpointProxy  
40 - BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">  
41 - <BreakpointContent  
42 - uuid = "B21C0B63-1820-47D9-863A-585E52771DA2"  
43 - shouldBeEnabled = "Yes"  
44 - ignoreCount = "0"  
45 - continueAfterRunningActions = "No"  
46 - filePath = "InterQR-Internship/Modules/OneTimePasswordScreen/View/OTPView.swift"  
47 - startingColumnNumber = "9223372036854775807"  
48 - endingColumnNumber = "9223372036854775807"  
49 - startingLineNumber = "94"  
50 - endingLineNumber = "94"  
51 - landmarkName = "didTextFieldChanged(_:)"  
52 - landmarkType = "7">  
53 - </BreakpointContent>  
54 - </BreakpointProxy>  
55 - <BreakpointProxy  
56 - BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">  
57 - <BreakpointContent  
58 - uuid = "7B1AC08C-6FFC-42BD-8C5C-4D6CE5CBD70C"  
59 - shouldBeEnabled = "Yes"  
60 - ignoreCount = "0"  
61 - continueAfterRunningActions = "No"  
62 - filePath = "InterQR-Internship/Modules/OneTimePasswordScreen/ViewController/CodeVerificationViewController.swift"  
63 - startingColumnNumber = "9223372036854775807"  
64 - endingColumnNumber = "9223372036854775807"  
65 - startingLineNumber = "145"  
66 - endingLineNumber = "145"  
67 - landmarkName = "didFullCodeCompletion(_:)"  
68 - landmarkType = "7">  
69 - </BreakpointContent>  
70 - </BreakpointProxy>  
71 </Breakpoints> 39 </Breakpoints>
72 </Bucket> 40 </Bucket>
@@ -9,7 +9,10 @@ import Foundation @@ -9,7 +9,10 @@ import Foundation
9 import Alamofire 9 import Alamofire
10 10
11 class AuthService { 11 class AuthService {
12 - static let share = AuthService() 12 + static let shared = AuthService()
  13 +
  14 + private init() {
  15 + }
13 16
14 var networkToken: String? { 17 var networkToken: String? {
15 get { 18 get {
@@ -87,10 +90,11 @@ class AuthService { @@ -87,10 +90,11 @@ class AuthService {
87 } 90 }
88 91
89 func loginRequest(model: LoginRequestModel, success: @escaping LoginWebServiceResponse, fail: @escaping FailedHandler) { 92 func loginRequest(model: LoginRequestModel, success: @escaping LoginWebServiceResponse, fail: @escaping FailedHandler) {
90 - let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"] 93 + let interceptor = InterQrRequestInterceptor()
  94 +
91 let params = ["device_uuid": model.deviceUUID] as [String: Any] 95 let params = ["device_uuid": model.deviceUUID] as [String: Any]
92 96
93 - AF.request(Constants.baseURL + APIRoutes.loginURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LoginResponseModel.self ) { response in 97 + AF.request(Constants.baseURL + APIRoutes.loginURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default, interceptor: interceptor).responseDecodable(of: LoginResponseModel.self ) { response in
94 98
95 switch response.result { 99 switch response.result {
96 case .failure(let error) : 100 case .failure(let error) :
@@ -102,10 +106,10 @@ class AuthService { @@ -102,10 +106,10 @@ class AuthService {
102 } 106 }
103 107
104 func logoutRequest(model: LogoutRequestModel, completion: @escaping LogoutWebServiceResponse, fail: @escaping FailedHandler) { 108 func logoutRequest(model: LogoutRequestModel, completion: @escaping LogoutWebServiceResponse, fail: @escaping FailedHandler) {
105 - let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"] 109 + let interceptor = InterQrRequestInterceptor()
106 let params = ["device_uuid": model.deviceUUID] as [String: Any] 110 let params = ["device_uuid": model.deviceUUID] as [String: Any]
107 111
108 - AF.request(Constants.baseURL + APIRoutes.logoutURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default, headers: HTTPHeaders(headers), interceptor: nil).responseDecodable(of: LogoutResponseModel.self ) { response in 112 + AF.request(Constants.baseURL + APIRoutes.logoutURL.urlString, method: .post, parameters: params, encoding: JSONEncoding.default, interceptor: interceptor).responseDecodable(of: LogoutResponseModel.self ) { response in
109 113
110 if let error = response.error { 114 if let error = response.error {
111 fail(error) 115 fail(error)
@@ -117,3 +121,16 @@ class AuthService { @@ -117,3 +121,16 @@ class AuthService {
117 } 121 }
118 } 122 }
119 } 123 }
  124 +
  125 +class InterQrRequestInterceptor: RequestInterceptor {
  126 + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result<URLRequest, Error>) -> Void) {
  127 + var urlRequest = urlRequest
  128 +// let headers = ["Authorization": "Bearer \(self.networkToken ?? "")"]
  129 +// let params = ["device_uuid": model.deviceUUID] as [String: Any]
  130 + if let token = AuthService.shared.networkToken {
  131 + urlRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
  132 + }
  133 +// if let deviceUUID =
  134 + completion(.success(urlRequest))
  135 + }
  136 +}
@@ -11,11 +11,8 @@ import ContactsUI @@ -11,11 +11,8 @@ import ContactsUI
11 class AddResidentsViewController: UIViewController { 11 class AddResidentsViewController: UIViewController {
12 var isKeyboardAppear = false 12 var isKeyboardAppear = false
13 13
14 - weak var delegate: ResidentSavable?  
15 -  
16 - var contact = ContactPickerViewController()  
17 var mainView = AddResidentsView() 14 var mainView = AddResidentsView()
18 - 15 + weak var delegate: ResidentSavable?
19 var closeTap: UITapGestureRecognizer? 16 var closeTap: UITapGestureRecognizer?
20 17
21 override func loadView() { 18 override func loadView() {
@@ -41,7 +41,6 @@ extension HomeViewController: UITableViewDelegate, UITableViewDataSource { @@ -41,7 +41,6 @@ extension HomeViewController: UITableViewDelegate, UITableViewDataSource {
41 41
42 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 42 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
43 guard let cell = tableView.dequeueReusableCell(withIdentifier: HomeTableViewCell.id, for: indexPath) as? HomeTableViewCell else { return UITableViewCell() } 43 guard let cell = tableView.dequeueReusableCell(withIdentifier: HomeTableViewCell.id, for: indexPath) as? HomeTableViewCell else { return UITableViewCell() }
44 -// cell.configureWithItem(doors[indexPath.row])  
45 return cell 44 return cell
46 } 45 }
47 46
@@ -80,7 +80,6 @@ class CodeVerificationView: UIView { @@ -80,7 +80,6 @@ class CodeVerificationView: UIView {
80 let spinner: UIActivityIndicatorView = { 80 let spinner: UIActivityIndicatorView = {
81 var obj = UIActivityIndicatorView(style: .large) 81 var obj = UIActivityIndicatorView(style: .large)
82 obj.hidesWhenStopped = true 82 obj.hidesWhenStopped = true
83 -  
84 return obj 83 return obj
85 }() 84 }()
86 85
@@ -9,9 +9,8 @@ import UIKit @@ -9,9 +9,8 @@ import UIKit
9 9
10 class CodeVerificationViewController: UIViewController { 10 class CodeVerificationViewController: UIViewController {
11 var isKeyboardAppear = false 11 var isKeyboardAppear = false
12 - 12 + var verifyMessage: String?
13 private let mainView = CodeVerificationView() 13 private let mainView = CodeVerificationView()
14 - private let networkManager = AuthService()  
15 14
16 override func loadView() { 15 override func loadView() {
17 view = mainView 16 view = mainView
@@ -23,7 +22,7 @@ class CodeVerificationViewController: UIViewController { @@ -23,7 +22,7 @@ class CodeVerificationViewController: UIViewController {
23 22
24 private func initViewController() { 23 private func initViewController() {
25 mainView.otpView.delegate = self 24 mainView.otpView.delegate = self
26 - mainView.backButton.addTarget(self, action: #selector(didDismissVC), for: .touchUpInside) 25 + mainView.backButton.addTarget(self, action: #selector(didTapBackButton), for: .touchUpInside)
27 mainView.verifyButton.addTarget(self, action: #selector(didTapVerifyButton), for: .touchUpInside) 26 mainView.verifyButton.addTarget(self, action: #selector(didTapVerifyButton), for: .touchUpInside)
28 27
29 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) 28 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
@@ -35,36 +34,40 @@ class CodeVerificationViewController: UIViewController { @@ -35,36 +34,40 @@ class CodeVerificationViewController: UIViewController {
35 NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) 34 NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
36 } 35 }
37 36
38 - func networkingVerify() {  
39 - guard let verifyModel = verifyModelFilling() else { return }  
40 - AuthService.share.verifyRequest(model: verifyModel) { response in 37 + func verificationRequestProcessing() {
  38 + self.mainView.spinner.startAnimating()
  39 + guard let verifyModel = getVerifyModel() else { return }
  40 + AuthService.shared.verifyRequest(model: verifyModel) { response in
41 print("3️⃣✅\(response.data)") 41 print("3️⃣✅\(response.data)")
42 print("\(response.message)✅") 42 print("\(response.message)✅")
43 - self.networkingLogin()  
44 - self.mainView.spinner.startAnimating() 43 + self.loginRequestProcessing()
45 } fail: { error in 44 } fail: { error in
  45 + self.mainView.spinner.stopAnimating()
46 print("3️⃣\(error)") 46 print("3️⃣\(error)")
47 self.errorProcessing() 47 self.errorProcessing()
48 } 48 }
49 } 49 }
50 50
51 - func networkingLogin() {  
52 - guard let loginModel = loginModelFilling() else { return }  
53 - AuthService.share.loginRequest(model: loginModel) { response in 51 + func loginRequestProcessing() {
  52 + guard let loginModel = getLoginModel() else { return }
  53 + AuthService.shared.loginRequest(model: loginModel) { response in
54 print("4️⃣\(String(describing: response.message))4️⃣") 54 print("4️⃣\(String(describing: response.message))4️⃣")
55 - self.errorProcessing() 55 + self.verifyMessage = response.message
  56 + self.loginDataProcessing()
56 } fail: { error in 57 } fail: { error in
  58 + self.mainView.spinner.stopAnimating()
  59 + self.errorProcessing()
57 print("4️⃣⛔️\(error)⛔️") 60 print("4️⃣⛔️\(error)⛔️")
58 } 61 }
59 } 62 }
60 63
61 - func verifyModelFilling() -> VerifyRequestModel? { 64 + func getVerifyModel() -> VerifyRequestModel? {
62 let email = "test@interqr.com" 65 let email = "test@interqr.com"
63 guard let code = mainView.otpView.code else { return nil } 66 guard let code = mainView.otpView.code else { return nil }
64 return VerifyRequestModel(emailOrNumber: email, code: code, secondAuthToken: "asdas") 67 return VerifyRequestModel(emailOrNumber: email, code: code, secondAuthToken: "asdas")
65 } 68 }
66 69
67 - func loginModelFilling() -> LoginRequestModel? { 70 + func getLoginModel() -> LoginRequestModel? {
68 guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else { 71 guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
69 return nil 72 return nil
70 } 73 }
@@ -74,7 +77,7 @@ class CodeVerificationViewController: UIViewController { @@ -74,7 +77,7 @@ class CodeVerificationViewController: UIViewController {
74 //MARK: - Targets 77 //MARK: - Targets
75 extension CodeVerificationViewController { 78 extension CodeVerificationViewController {
76 @objc private func didTapVerifyButton() { 79 @objc private func didTapVerifyButton() {
77 - networkingVerify() 80 + verificationRequestProcessing()
78 } 81 }
79 82
80 private func showHomeVC() { 83 private func showHomeVC() {
@@ -82,25 +85,36 @@ extension CodeVerificationViewController { @@ -82,25 +85,36 @@ extension CodeVerificationViewController {
82 navigationController?.pushViewController(viewController, animated: true) 85 navigationController?.pushViewController(viewController, animated: true)
83 } 86 }
84 87
  88 + private func loginDataProcessing() {
  89 + self.mainView.spinner.stopAnimating()
  90 + self.showHomeVC()
  91 + }
  92 +
85 private func errorProcessing() { 93 private func errorProcessing() {
86 guard let code = mainView.otpView.code else { return } 94 guard let code = mainView.otpView.code else { return }
  95 +
87 if code.count < 4 { 96 if code.count < 4 {
88 let alert = UIAlertController(title: "❌", message: "Enter all fields", preferredStyle: .alert) 97 let alert = UIAlertController(title: "❌", message: "Enter all fields", preferredStyle: .alert)
89 alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil)) 98 alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil))
90 present(alert, animated: true, completion: nil) 99 present(alert, animated: true, completion: nil)
  100 + } else if verifyMessage != "OK" {
  101 + let alert = UIAlertController(title: "Wrong password", message: "", preferredStyle: .alert)
  102 + alert.addAction(UIAlertAction(title: "Try again", style: .cancel, handler: { action in
  103 + self.mainView.otpView.isError.toggle()
  104 + self.mainView.errorAlertLabel.isHidden = false
  105 + self.mainView.otpView.textField.becomeFirstResponder()
  106 + }))
  107 + present(alert, animated: true, completion: nil)
91 } else { 108 } else {
92 - if code != "8327" {  
93 - mainView.otpView.isError.toggle()  
94 - mainView.errorAlertLabel.isHidden = false  
95 - mainView.otpView.textField.becomeFirstResponder()  
96 - } else {  
97 - self.mainView.spinner.stopAnimating()  
98 - self.showHomeVC()  
99 - } 109 + let alert = UIAlertController(title: "Network technical issues", message: "", preferredStyle: .alert)
  110 + alert.addAction(UIAlertAction(title: "Reload", style: .cancel, handler: { action in
  111 + self.didTapBackButton()
  112 + }))
  113 + present(alert, animated: true, completion: nil)
100 } 114 }
101 } 115 }
102 116
103 - @objc private func didDismissVC() { 117 + @objc private func didTapBackButton() {
104 navigationController?.popViewController(animated: true) 118 navigationController?.popViewController(animated: true)
105 } 119 }
106 120
@@ -144,11 +158,5 @@ extension CodeVerificationViewController: OTPViewDelegate { @@ -144,11 +158,5 @@ extension CodeVerificationViewController: OTPViewDelegate {
144 158
145 func didFullCodeCompletion(_ otpView: OTPView) { 159 func didFullCodeCompletion(_ otpView: OTPView) {
146 print("code -> \(String(describing: otpView.code))") 160 print("code -> \(String(describing: otpView.code))")
147 - guard let code = otpView.code else { return }  
148 - if code.isEmpty {  
149 - mainView.otpView.isError.toggle()  
150 - otpView.reloadInputViews()  
151 - }  
152 -  
153 } 161 }
154 } 162 }
@@ -11,15 +11,12 @@ class ResidentsViewController: UIViewController { @@ -11,15 +11,12 @@ class ResidentsViewController: UIViewController {
11 var mainView = ResidentsView() 11 var mainView = ResidentsView()
12 var myData: [ResidentModel] = [] 12 var myData: [ResidentModel] = []
13 13
14 - let networkManager = AuthService()  
15 -  
16 override func loadView() { 14 override func loadView() {
17 view = mainView 15 view = mainView
18 } 16 }
19 17
20 override func viewDidLoad() { 18 override func viewDidLoad() {
21 initViewController() 19 initViewController()
22 - initDevice()  
23 } 20 }
24 21
25 func initViewController() { 22 func initViewController() {
@@ -31,32 +28,6 @@ class ResidentsViewController: UIViewController { @@ -31,32 +28,6 @@ class ResidentsViewController: UIViewController {
31 mainView.addResidentsButton.addTarget(self, action: #selector(willShowAddResidentVC), for: .touchUpInside) 28 mainView.addResidentsButton.addTarget(self, action: #selector(willShowAddResidentVC), for: .touchUpInside)
32 } 29 }
33 30
34 - func modelFilling() -> InitRequestModel? {  
35 - guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {  
36 - return nil  
37 - }  
38 - guard let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {  
39 - return nil  
40 - }  
41 - return InitRequestModel(deviceUUID: deviceUUID,  
42 - manufacturer: .Text.apple,  
43 - model: UIDevice.current.model,  
44 - platform: UIDevice.current.systemName,  
45 - osVersion: UIDevice.current.systemVersion,  
46 - appVersion: appVersion)  
47 - }  
48 -  
49 - private func initDevice() {  
50 - guard let model = modelFilling() else {  
51 - return  
52 - }  
53 - AuthService.share.initRequest(model: model) { result in  
54 - print("1️⃣✅\(result.message)✅")  
55 - } fail: { error in  
56 - print("1️⃣\(error)")  
57 - }  
58 - }  
59 -  
60 @objc private func didShowChooseApartVC() { 31 @objc private func didShowChooseApartVC() {
61 navigationController?.popViewController(animated: true) 32 navigationController?.popViewController(animated: true)
62 } 33 }
@@ -111,14 +82,6 @@ extension ResidentsViewController: ResidentTableViewCellDelegate { @@ -111,14 +82,6 @@ extension ResidentsViewController: ResidentTableViewCellDelegate {
111 mainView.tableView.reloadData() 82 mainView.tableView.reloadData()
112 } 83 }
113 84
114 -// func didButtonsTapped(_ button: UIButton) {  
115 -// if !button.isSelected {  
116 -// button.isSelected = true  
117 -// } else {  
118 -// button.isSelected = false  
119 -// }  
120 -// }  
121 -  
122 func didManagerButtonTapped(cell: ResidentTableViewCell) { 85 func didManagerButtonTapped(cell: ResidentTableViewCell) {
123 if !cell.managerButton.isSelected { 86 if !cell.managerButton.isSelected {
124 cell.managerButton.isSelected = true 87 cell.managerButton.isSelected = true
@@ -8,9 +8,8 @@ @@ -8,9 +8,8 @@
8 import UIKit 8 import UIKit
9 9
10 class SettingsViewController: UIViewController { 10 class SettingsViewController: UIViewController {
11 - var mainView = SettingsView()  
12 - var networkManager = AuthService()  
13 - 11 + var logoutMessage: String?
  12 + var mainView = SettingsView()
14 let settingsModel = SettingsModel.allCases 13 let settingsModel = SettingsModel.allCases
15 14
16 override func loadView() { 15 override func loadView() {
@@ -30,7 +29,7 @@ class SettingsViewController: UIViewController { @@ -30,7 +29,7 @@ class SettingsViewController: UIViewController {
30 mainView.settingsTableView.registerReusableCell(SettingsTableViewCell.self) 29 mainView.settingsTableView.registerReusableCell(SettingsTableViewCell.self)
31 30
32 mainView.backButton.addTarget(self, action: #selector(didShowHomeVC), for: .touchUpInside) 31 mainView.backButton.addTarget(self, action: #selector(didShowHomeVC), for: .touchUpInside)
33 - mainView.logoutButton.addTarget(self, action: #selector(didLogoutAndShowVerificationVC), for: .touchUpInside) 32 + mainView.logoutButton.addTarget(self, action: #selector(didTapLogoutButton), for: .touchUpInside)
34 } 33 }
35 } 34 }
36 //MARK: - Delegate 35 //MARK: - Delegate
@@ -39,27 +38,50 @@ extension SettingsViewController { @@ -39,27 +38,50 @@ extension SettingsViewController {
39 navigationController?.popViewController(animated: true) 38 navigationController?.popViewController(animated: true)
40 } 39 }
41 40
42 - @objc private func didLogoutAndShowVerificationVC() {  
43 - networking()  
44 - let vc = VerificationViewController()  
45 - navigationController?.pushViewController(vc, animated: true) 41 + @objc private func didTapLogoutButton() {
  42 + logoutRequestProcessing()
  43 +
46 } 44 }
47 45
48 - func networking() {  
49 - guard let logoutModel = logoutModelFilling() else { return }  
50 - AuthService.share.logoutRequest(model: logoutModel) { response in 46 + func logoutRequestProcessing() {
  47 + guard let logoutModel = getLogoutModel() else { return }
  48 + AuthService.shared.logoutRequest(model: logoutModel) { response in
  49 + self.logoutMessage = response.message
  50 + self.logoutDataProcessing()
51 print("5️⃣❇️\(response.message ?? "Data not received!")❇️") 51 print("5️⃣❇️\(response.message ?? "Data not received!")❇️")
52 } fail: { error in 52 } fail: { error in
  53 + self.logoutErrorProcessing()
53 print("5️⃣❗️\(error)❗️") 54 print("5️⃣❗️\(error)❗️")
54 } 55 }
55 } 56 }
56 57
57 - func logoutModelFilling() -> LogoutRequestModel? { 58 + func getLogoutModel() -> LogoutRequestModel? {
58 guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else { 59 guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
59 return nil 60 return nil
60 } 61 }
61 return LogoutRequestModel(deviceUUID: deviceUUID) 62 return LogoutRequestModel(deviceUUID: deviceUUID)
62 } 63 }
  64 +
  65 + private func logoutDataProcessing() {
  66 + let alert = UIAlertController(title: "Do you really want to logout?", message: "", preferredStyle: .alert)
  67 + alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { action in
  68 + let vc = VerificationViewController()
  69 + self.navigationController?.pushViewController(vc, animated: true)
  70 + }))
  71 + alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
  72 + present(alert, animated: true, completion: nil)
  73 + }
  74 +
  75 + private func logoutErrorProcessing() {
  76 + if logoutMessage != "OK" {
  77 + let alert = UIAlertController(title: "Some network problems", message: "", preferredStyle: .alert)
  78 + alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
  79 + present(alert, animated: true, completion: nil)
  80 + } else {
  81 + let vc = VerificationViewController()
  82 + self.navigationController?.pushViewController(vc, animated: true)
  83 + }
  84 + }
63 } 85 }
64 86
65 //MARK: tableView delegate and datasource 87 //MARK: tableView delegate and datasource
@@ -32,7 +32,7 @@ class VerificationView: UIView { @@ -32,7 +32,7 @@ class VerificationView: UIView {
32 var label = UILabel() 32 var label = UILabel()
33 label.text = .Text.letsVerifyYourAccount 33 label.text = .Text.letsVerifyYourAccount
34 label.numberOfLines = 2 34 label.numberOfLines = 2
35 - label.font = .skModernist(type: .regular, ofSize: 38) 35 + label.font = .skModernist(type: .regular, ofSize: 28)
36 return label 36 return label
37 }() 37 }()
38 38
@@ -8,8 +8,8 @@ @@ -8,8 +8,8 @@
8 import UIKit 8 import UIKit
9 9
10 class VerificationViewController: UIViewController { 10 class VerificationViewController: UIViewController {
11 - var networkManager = AuthService()  
12 var isKeyboardAppear = false 11 var isKeyboardAppear = false
  12 + var startMessage: String?
13 private let mainView = VerificationView() 13 private let mainView = VerificationView()
14 var closeTap: UITapGestureRecognizer? 14 var closeTap: UITapGestureRecognizer?
15 15
@@ -57,13 +57,69 @@ class VerificationViewController: UIViewController { @@ -57,13 +57,69 @@ class VerificationViewController: UIViewController {
57 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil) 57 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
58 } 58 }
59 59
60 - func networking() { 60 + private func initDevice() {
  61 + guard let model = getInitModel() else {
  62 + return
  63 + }
  64 + AuthService.shared.initRequest(model: model) { result in
  65 + print("1️⃣✅\(result.message)✅")
  66 + self.startRequestProcessing()
  67 + } fail: { error in
  68 + print("1️⃣\(error)")
  69 + let alert = UIAlertController(title: "Error", message: "", preferredStyle: .alert)
  70 + alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
  71 + self.present(alert, animated: true, completion: nil)
  72 + }
  73 + }
  74 +
  75 + func getInitModel() -> InitRequestModel? {
  76 + guard let deviceUUID = UIDevice.current.identifierForVendor?.uuidString else {
  77 + return nil
  78 + }
  79 + guard let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {
  80 + return nil
  81 + }
  82 + return InitRequestModel(deviceUUID: deviceUUID,
  83 + manufacturer: .Text.apple,
  84 + model: UIDevice.current.model,
  85 + platform: UIDevice.current.systemName,
  86 + osVersion: UIDevice.current.systemVersion,
  87 + appVersion: appVersion)
  88 + }
  89 +
  90 + private func startRequestProcessing() {
61 guard let startModel = startModelFilling() else { return } 91 guard let startModel = startModelFilling() else { return }
62 - AuthService.share.startRequest(model: startModel) { response in 92 + AuthService.shared.startRequest(model: startModel) { response in
  93 + self.startMessage = response.message
63 print("2️⃣✅\(response.message)✅") 94 print("2️⃣✅\(response.message)✅")
  95 + self.didShowCodeVerificationVC()
64 } fail: { error in 96 } fail: { error in
65 print("2️⃣❌\(error)❌") 97 print("2️⃣❌\(error)❌")
  98 + self.errorProcessing()
  99 + }
  100 + }
  101 +
  102 + func didShowCodeVerificationVC() {
  103 + if startMessage == "SMS successfully sent" {
  104 + let viewController = CodeVerificationViewController()
  105 + viewController.navigationItem.hidesBackButton = true
  106 + navigationController?.pushViewController(viewController, animated: true)
  107 + } else {
  108 + userDoesNotExistNotice()
66 } 109 }
  110 +
  111 + }
  112 +
  113 + private func userDoesNotExistNotice() {
  114 + let alert = UIAlertController(title: "User does not exist", message: "Try again", preferredStyle: .alert)
  115 + alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
  116 + present(alert, animated: true)
  117 + }
  118 +
  119 + private func errorProcessing() {
  120 + let alert = UIAlertController(title: "Network error", message: "Try again later", preferredStyle: .alert)
  121 + alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
  122 + present(alert, animated: true)
67 } 123 }
68 124
69 func startModelFilling() -> StartRequestModel? { 125 func startModelFilling() -> StartRequestModel? {
@@ -76,7 +132,7 @@ class VerificationViewController: UIViewController { @@ -76,7 +132,7 @@ class VerificationViewController: UIViewController {
76 } 132 }
77 } 133 }
78 134
79 - func addDoneButtonOnKeyboard() { 135 + private func addDoneButtonOnKeyboard() {
80 let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)) 136 let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
81 doneToolbar.barStyle = .default 137 doneToolbar.barStyle = .default
82 138
@@ -90,9 +146,8 @@ class VerificationViewController: UIViewController { @@ -90,9 +146,8 @@ class VerificationViewController: UIViewController {
90 mainView.phoneTextField.inputAccessoryView = doneToolbar 146 mainView.phoneTextField.inputAccessoryView = doneToolbar
91 } 147 }
92 148
93 - @objc func doneButtonAction(){ 149 + @objc private func doneButtonAction(){
94 mainView.phoneTextField.resignFirstResponder() 150 mainView.phoneTextField.resignFirstResponder()
95 - didShowCodeVerificationVC()  
96 } 151 }
97 } 152 }
98 153
@@ -109,10 +164,12 @@ extension VerificationViewController { @@ -109,10 +164,12 @@ extension VerificationViewController {
109 sender.isSelected = true 164 sender.isSelected = true
110 mainView.phoneNumberButton.isSelected = false 165 mainView.phoneNumberButton.isSelected = false
111 mainView.handleUI(true) 166 mainView.handleUI(true)
  167 + mainView.phoneTextField.resignFirstResponder()
112 case mainView.phoneNumberButton: 168 case mainView.phoneNumberButton:
113 sender.isSelected = true 169 sender.isSelected = true
114 mainView.emailButton.isSelected = false 170 mainView.emailButton.isSelected = false
115 mainView.handleUI(false) 171 mainView.handleUI(false)
  172 + mainView.emailTextField.resignFirstResponder()
116 default: 173 default:
117 return 174 return
118 } 175 }
@@ -124,28 +181,19 @@ extension VerificationViewController { @@ -124,28 +181,19 @@ extension VerificationViewController {
124 } 181 }
125 182
126 @objc private func didTapContinueButton() { 183 @objc private func didTapContinueButton() {
127 - didShowCodeVerificationVC() 184 + validatingTheLoginField()
128 } 185 }
129 186
130 - private func didShowCodeVerificationVC() { 187 + private func validatingTheLoginField() {
131 guard let email = mainView.emailTextField.text else { return } 188 guard let email = mainView.emailTextField.text else { return }
132 guard let number = mainView.phoneTextField.text else { return } 189 guard let number = mainView.phoneTextField.text else { return }
133 - let userCode: String = .Text.userCode 190 +
134 if email.isEmpty || number.isEmpty{ 191 if email.isEmpty || number.isEmpty{
135 let alert = UIAlertController(title: "Enter email or number fields", message: "", preferredStyle: .alert) 192 let alert = UIAlertController(title: "Enter email or number fields", message: "", preferredStyle: .alert)
136 alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil)) 193 alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
137 present(alert, animated: true) 194 present(alert, animated: true)
138 - } else { if email == userCode || number == userCode {  
139 - let vc = CodeVerificationViewController()  
140 - vc.navigationItem.hidesBackButton = true  
141 - navigationController?.pushViewController(vc, animated: true)  
142 - networking()  
143 - } else { if email != userCode || number != userCode {  
144 - let alert = UIAlertController(title: "User does not exist", message: "", preferredStyle: .alert)  
145 - alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))  
146 - present(alert, animated: true)  
147 - }  
148 - } 195 + } else {
  196 + initDevice()
149 } 197 }
150 } 198 }
151 199
Please register or login to post a comment