Files
Woka_Native_iOS/WOKA/Authentication/ViewModel/NewPasswordVM.swift
Bilal ecfa31b57f - Removed the pod for center collection view. Now instead of library i have created a custom flowlayout
- Added the Forgot password otp send api.
- Done the error handling and navigation for the same.
- Added api for password updated.
- Added necessary Checks for the password.
- Fixed the versioning issue of the centered flow layout. Also fixed the errors, for the complex calculations , splitted the calculations to avoid crash.
2024-05-10 20:43:57 +05:30

62 lines
2.2 KiB
Swift

//
// NewPasswordVM.swift
// WOKA
//
// Created by Bilal on 10/05/2024.
//
import UIKit
import Alamofire
class NewPasswordVM{
weak var vc : NewPasswordVC!
var userName : String?
func initView(){
vc.enterNewPasswordTF.enablePasswordToggle()
vc.confirmPassTF.enablePasswordToggle()
vc.enterNewPasswordTF.delegate = self.vc
vc.confirmPassTF.delegate = self.vc
vc.enterNewPasswordTF.roundCorner()
vc.confirmPassTF.roundCorner()
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()
}
func updatePassword(){
guard let userName else{return}
let params: Parameters = [
"username": userName,
"password": vc.enterNewPasswordTF.text!,
"password_confirmation": vc.confirmPassTF.text!
]
Utilities.startProgressHUD()
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Auth.update_password, method: .post ,parameters: params) {(result : Result<BaseResponseModel<ForgotPassDM>, NetworkManager.APIError>) in
switch result{
case .success(let data):
switch data.success{
case 0: // some error
Utilities.dismissProgressHUD()
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
case 1: // Success
Utilities.dismissProgressHUD()
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 1) {
}
default:
Utilities.dismissProgressHUD()
self.vc.toast(msg: K.ConstantString.unRecognised , time: 1)
}
case .failure(let error):
Utilities.dismissProgressHUD()
self.vc.toast(msg: error.localizedDescription , time: 2)
}
}
}
}