106 lines
5.0 KiB
Swift
106 lines
5.0 KiB
Swift
//
|
|
// EmailVM.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 29/04/24.
|
|
//
|
|
|
|
import UIKit
|
|
import Alamofire
|
|
|
|
class EmailVM{
|
|
|
|
weak var vc : EmailVC!
|
|
|
|
func initView(){
|
|
let color1 = #colorLiteral(red: 0.144693464, green: 0.1426281333, blue: 0.6686832905, alpha: 1)
|
|
let color2 = #colorLiteral(red: 0.6901960784, green: 0.2745098039, blue: 0.7568627451, alpha: 1)
|
|
vc.nextBtn.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0))
|
|
vc.nextBtn.roundCorner()
|
|
vc.enterEmailTF.roundCorner()
|
|
|
|
// Set up text field delegate
|
|
vc.enterEmailTF.delegate = vc.self
|
|
|
|
vc.enterEmailTF.addRightButton(title: "", tintColor: UIColor.red, btnImage: UIImage(systemName: "exclamationmark.circle.fill"), target: self, action: #selector(validationIconTapped))
|
|
vc.enterEmailTF.rightView?.isHidden = true
|
|
|
|
self.vc.wokaLogoTopConstriant.constant = CheckPhoneHomeBtnOrNotch.shareInstance.topConstriant()
|
|
|
|
//Checking UserType to update the text
|
|
if AuthFunc.shareInstance.userType == .adult{
|
|
vc.enterEmailTF.placeholder = K.AuthenticationStringConstant.enterEmail.localized(loc: K.GVar.localized)
|
|
vc.emailVerifyLabel.isHidden = true
|
|
vc.beSafeLabel.text = K.AuthenticationStringConstant.safeAbove.localized(loc: K.GVar.localized)
|
|
vc.emailLabel.text = K.AuthenticationStringConstant.emailAbove.localized(loc: K.GVar.localized)
|
|
}else{
|
|
vc.enterEmailTF.placeholder = K.AuthenticationStringConstant.enterParentsEmail.localized(loc: K.GVar.localized)
|
|
vc.beSafeLabel.text = K.AuthenticationStringConstant.safeBelow.localized(loc: K.GVar.localized)
|
|
vc.emailLabel.text = K.AuthenticationStringConstant.emailBelow.localized(loc: K.GVar.localized)
|
|
}
|
|
}
|
|
|
|
// Function to handle tap on validation icon
|
|
@objc func validationIconTapped() {
|
|
let errorView = errorViews.object(forKey: vc.enterEmailTF)
|
|
if let errorView = errorView {
|
|
errorView.isHidden.toggle()
|
|
}
|
|
}
|
|
|
|
func checkEmail(){
|
|
let params: Parameters = [
|
|
"email": vc.enterEmailTF.text!,
|
|
"user_type": "2"
|
|
]
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Auth.check_exist_email, method: .post ,parameters: params) {(result : Result<BaseResponseModel<UserDataDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
// print(data.message)
|
|
switch data.success{
|
|
case 0:
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
case 1:
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
default:
|
|
break
|
|
}
|
|
// switch data.errorCode{
|
|
// case 0: // this means no error
|
|
// Utilities.dismissProgressHUD()
|
|
// if let data = data.result {
|
|
// let sb = UIStoryboard(name: K.StoryBoard.geoFencing, bundle: nil)
|
|
// let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.GeoFencing.geoFencingMapVC) as! GeoFencingMapVC
|
|
// vcPush.vm.patientLocationLink = data
|
|
// self.navigationController?.setNavigationBarHidden(false, animated: true)
|
|
// self.navigationController?.pushViewController(vcPush, animated: true)
|
|
// }else{
|
|
// let sb = UIStoryboard(name: K.StoryBoard.geoFencing, bundle: nil)
|
|
// let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.GeoFencing.geoFencingMapVC) as! GeoFencingMapVC
|
|
// self.navigationController?.setNavigationBarHidden(false, animated: true)
|
|
// self.navigationController?.pushViewController(vcPush, animated: true)
|
|
// }
|
|
// case 1: // handle error
|
|
// Utilities.dismissProgressHUD()
|
|
// self.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
// default:
|
|
// Utilities.dismissProgressHUD()
|
|
// break
|
|
// }
|
|
case .failure(let error):
|
|
Utilities.dismissProgressHUD()
|
|
print(error)
|
|
// Utilities.dismissProgressHUD()
|
|
// switch error {
|
|
// case .noNetwork(let message) , .custom(let message), .unknown(let message):
|
|
// Utilities.alertWithBtn(title: "", msgBody: message, okBtnStr: "OK", vc: self)
|
|
// default:
|
|
// self.toast(msg: String(describing: error) , time: 2)
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|