Files
Woka_Native_iOS/WOKA/Authentication/Controller/OTPVC.swift
BilalKhanWDI 3c69db0032 - Added send OTP api
- Added verify  OTP api
- Modified the flow
- Made a authfunc to handle the type of user and the language selected
- Added OTP fields combine logic. Also handled the otp blank checks.
- Added API for intrestes get
2024-05-07 19:33:29 +05:30

94 lines
2.8 KiB
Swift

//
// OTPVC.swift
// WOKA
//
// Created by MacBook Pro on 29/04/24.
//
import UIKit
enum NavigateToVC{
case newPass
case registeration
}
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!
@IBOutlet weak var resendOTPBtn: LocalisedElementsButton!
@IBOutlet weak var codeSentLabel: UILabel!
@IBOutlet weak var otpValidTillLabel: LocalisedElementsLabel!
@IBOutlet weak var enterCodeLabel: UILabel!
@IBOutlet weak var requestThemLabel: LocalisedElementsLabel!
var vm = OTPVM()
var navigateCheck = NavigateToVC.registeration
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)
}
deinit {
vm.timer?.invalidate()
}
// MARK: - Button Tap Handler
@IBAction func nextBtnTapped(_ sender: LocalisedElementsButton) {
vm.validateOTP()
}
@IBAction func resendOTPBtnTapped(_ sender: LocalisedElementsButton) {
vm.remainingTime = 10 * 60
vm.resendOTP()
}
}
// 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
}
}