- My list Games on add remove fav, only calling Games api and reloading in background - My list Karaoke on add remove fav, only calling Karaoke api and reloading in background -Finalised clicks count for every module
126 lines
3.8 KiB
Swift
126 lines
3.8 KiB
Swift
//
|
|
// EmailVC.swift
|
|
// WOKA
|
|
//
|
|
// Created by Bilal on 26/04/2024.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class EmailVC: UIViewController {
|
|
|
|
@IBOutlet weak var nextBtn: LocalisedElementsButton!
|
|
@IBOutlet weak var enterEmailTF: UITextField!
|
|
@IBOutlet weak var wokaLogoTopConstriant: NSLayoutConstraint!
|
|
|
|
@IBOutlet weak var beSafeLabel: UILabel!
|
|
@IBOutlet weak var emailLabel: UILabel!
|
|
@IBOutlet weak var emailVerifyLabel: LocalisedElementsLabel!
|
|
|
|
var vm = EmailVM()
|
|
|
|
// MARK: - LifeCycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
vm.vc = self
|
|
vm.initView()
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
navigationController?.setNavigationBarHidden(false, animated: animated)
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
navigationController?.setNavigationBarHidden(true, animated: animated)
|
|
|
|
if self.isMovingFromParent {
|
|
// Back button was pressed
|
|
PersistentStorage.shared.addOthersCount()
|
|
}
|
|
}
|
|
|
|
@IBAction func nextBtnTapped(_ sender: LocalisedElementsButton) {
|
|
PersistentStorage.shared.addOthersCount()
|
|
/*
|
|
If child registers dont call api to check email, directly hit sendotp and navigate to otp screen
|
|
if parent registers check if the email exist or not and then hit sendotp
|
|
*/
|
|
Utilities.startProgressHUD()
|
|
DispatchQueue.main.async { [weak self] in
|
|
guard let self else{return}
|
|
//validate email fiirst
|
|
let emailValidate = EmailValidation(email: enterEmailTF.text!).validate()
|
|
if emailValidate != .isCorrect{
|
|
enterEmailTF.rightView?.isHidden = false
|
|
enterEmailTF.setError(emailValidate.rawValue.localized(loc: AuthFunc.shareInstance.languageSelected.rawValue), show: true)
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
|
|
/*
|
|
as per the user type
|
|
*/
|
|
|
|
switch AuthFunc.shareInstance.userType{
|
|
//if parent verify the email
|
|
case .adult:
|
|
vm.checkEmail()
|
|
// if kid then directly send the otp by checking the format of email
|
|
case .kid:
|
|
vm.sendOTP()
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: - TextField Delegate
|
|
|
|
extension EmailVC : UITextFieldDelegate{
|
|
|
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool{
|
|
switch textField{
|
|
case enterEmailTF:
|
|
if let rightView = textField.rightView {
|
|
// Hide the right view
|
|
rightView.isHidden = true
|
|
|
|
// Check if the right view is hidden
|
|
if rightView.isHidden {
|
|
// If hidden, hide the associated error view
|
|
if let errorView = errorViews.object(forKey: enterEmailTF) {
|
|
errorView.isHidden = true
|
|
}
|
|
}
|
|
}
|
|
|
|
return ValidatorClass.sharedInstanec.limitCharacter(length: 255,textField, shouldChangeCharactersIn: range, replacementString: string)
|
|
default:
|
|
return true
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension UITextField{
|
|
func hideError(){
|
|
if let rightView = self.rightView {
|
|
// Hide the right view
|
|
rightView.isHidden = true
|
|
|
|
// Check if the right view is hidden
|
|
if rightView.isHidden {
|
|
// If hidden, hide the associated error view
|
|
if let errorView = errorViews.object(forKey: self) {
|
|
errorView.isHidden = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|