2024-05-02 13:20:40 +05:30
|
|
|
//
|
|
|
|
|
// OTPVC.swift
|
|
|
|
|
// WOKA
|
|
|
|
|
//
|
|
|
|
|
// Created by MacBook Pro on 29/04/24.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2024-05-03 20:27:54 +05:30
|
|
|
enum NavigateToVC{
|
|
|
|
|
case newPass
|
|
|
|
|
case registeration
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 13:20:40 +05:30
|
|
|
class OTPVC : UIViewController{
|
|
|
|
|
|
|
|
|
|
@IBOutlet weak var wokaLogoTopConstriant: NSLayoutConstraint!
|
|
|
|
|
|
|
|
|
|
@IBOutlet weak var tf1: UITextField!
|
|
|
|
|
@IBOutlet weak var tf2: UITextField!
|
|
|
|
|
@IBOutlet weak var tf3: UITextField!
|
|
|
|
|
@IBOutlet weak var tf4: UITextField!
|
|
|
|
|
@IBOutlet weak var nextBtn: LocalisedElementsButton!
|
2024-05-07 19:33:29 +05:30
|
|
|
@IBOutlet weak var resendOTPBtn: LocalisedElementsButton!
|
2024-05-02 13:20:40 +05:30
|
|
|
|
|
|
|
|
@IBOutlet weak var codeSentLabel: UILabel!
|
2024-05-07 19:33:29 +05:30
|
|
|
@IBOutlet weak var otpValidTillLabel: LocalisedElementsLabel!
|
2024-05-02 13:20:40 +05:30
|
|
|
@IBOutlet weak var enterCodeLabel: UILabel!
|
|
|
|
|
@IBOutlet weak var requestThemLabel: LocalisedElementsLabel!
|
|
|
|
|
|
|
|
|
|
var vm = OTPVM()
|
2024-05-03 20:27:54 +05:30
|
|
|
var navigateCheck = NavigateToVC.registeration
|
2024-05-02 13:20:40 +05:30
|
|
|
|
|
|
|
|
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)
|
2024-08-12 19:58:58 +05:30
|
|
|
|
|
|
|
|
if self.isMovingFromParent {
|
|
|
|
|
// Back button was pressed
|
|
|
|
|
PersistentStorage.shared.addOthersCount()
|
|
|
|
|
}
|
2024-05-02 13:20:40 +05:30
|
|
|
}
|
|
|
|
|
|
2024-05-07 19:33:29 +05:30
|
|
|
deinit {
|
|
|
|
|
vm.timer?.invalidate()
|
|
|
|
|
}
|
2024-05-02 13:20:40 +05:30
|
|
|
// MARK: - Button Tap Handler
|
|
|
|
|
|
|
|
|
|
@IBAction func nextBtnTapped(_ sender: LocalisedElementsButton) {
|
2024-08-12 19:58:58 +05:30
|
|
|
PersistentStorage.shared.addOthersCount()
|
2024-05-07 19:33:29 +05:30
|
|
|
vm.validateOTP()
|
2024-05-02 13:20:40 +05:30
|
|
|
}
|
|
|
|
|
|
2024-05-07 19:33:29 +05:30
|
|
|
@IBAction func resendOTPBtnTapped(_ sender: LocalisedElementsButton) {
|
2024-08-12 19:58:58 +05:30
|
|
|
PersistentStorage.shared.addOthersCount()
|
2024-05-07 19:33:29 +05:30
|
|
|
vm.remainingTime = 10 * 60
|
|
|
|
|
vm.resendOTP()
|
|
|
|
|
}
|
2024-05-02 13:20:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - TextField Delegate
|
|
|
|
|
|
|
|
|
|
extension OTPVC : UITextFieldDelegate{
|
|
|
|
|
|
|
|
|
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool{
|
|
|
|
|
// Check if the input text contains only numbers
|
|
|
|
|
if !string.onlyNumber(){return false}
|
|
|
|
|
|
|
|
|
|
// If user pastes text into the text field, check the count and process accordingly
|
|
|
|
|
if string.count == 4{
|
|
|
|
|
self.vm.textFieldDidChange(textField, otpCode: string)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Limit the input to one character
|
|
|
|
|
let maxLength = 1
|
|
|
|
|
let currentString = (textField.text ?? "") as NSString
|
|
|
|
|
let newString = currentString.replacingCharacters(in: range, with: string)
|
|
|
|
|
return newString.count <= maxLength
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
|
|
|
|
// Check if the pasted text contains the content of the general pasteboard
|
|
|
|
|
if text.contains(UIPasteboard.general.string ?? "") {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|