Files
Woka_Native_iOS/WOKA/Authentication/ViewModel/UserDetailsRegisterVM.swift
Bilal 5fdd255130 - fixed home name label content hugging issue
- added edit btn to full name
- Linked the add child to the userregisteration details
- Added Hindi Lingual file to profile view
- Made the custom alert for deactivate account
- updated the username check logic
- Added logout api and handled the user logout
- Handled the logout when device change globally
2024-06-06 20:19:22 +05:30

112 lines
5.0 KiB
Swift

//
// UserDetailsRegisterVM.swift
// WOKA
//
// Created by MacBook Pro on 29/04/24.
//
import UIKit
import Alamofire
class UserDetailsRegisterVM{
weak var vc : UserDetailsRegisterVC!
// This will become true only if parent is adding child
var createChildAccount : Bool?
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()
tfMod(textField: [vc.enterNameTF, vc.enterPasswordTF, vc.enterUserNameTF])
hindiEnglishLanguage()
vc.enterNameTF.delegate = self.vc
vc.enterPasswordTF.delegate = self.vc
vc.enterUserNameTF.delegate = self.vc
//Adding eye to the password tf
vc.enterPasswordTF.enablePasswordToggle()
vc.enterPasswordTF.rightView?.isHidden = true
//Adding error view to the name tf
vc.enterNameTF.addRightButton(title: "", tintColor: UIColor.red, btnImage: UIImage(systemName: "exclamationmark.circle.fill"), target: self, action: #selector(errorName))
vc.enterNameTF.rightView?.isHidden = true
vc.enterUserNameTF.addRightButton(title: "", tintColor: UIColor.red, btnImage: UIImage(systemName: "exclamationmark.circle.fill"), target: self, action: #selector(errorUserName))
vc.enterUserNameTF.rightView?.isHidden = true
if let createChildAccount{ // this is from the home screen when a parent can adda child
vc.dontSharePassLabel.isHidden = true
vc.viewTitleLabel.text = "Add Child Account".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vc.userNameTitleLabel.text = "USERNAME".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vc.nameTitleLabel.text = "CHILD NAME?".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vc.passTitleLabel.text = "PASSWORD".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
}else{
AuthFunc.shareInstance.userType == .adult ? (vc.dontSharePassLabel.isHidden = true) : (vc.dontSharePassLabel.isHidden = false)
}
}
@objc func errorName(){
let errorView = errorViews.object(forKey: vc.enterNameTF)
if let errorView = errorView {
errorView.isHidden.toggle()
}
}
@objc func errorUserName(){
let errorView = errorViews.object(forKey: vc.enterUserNameTF)
if let errorView = errorView {
errorView.isHidden.toggle()
}
}
func hindiEnglishLanguage(){
vc.enterNameTF.placeholder = K.AuthenticationStringConstant.enterName.localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vc.enterUserNameTF.placeholder = K.AuthenticationStringConstant.selectUsername.localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
vc.enterPasswordTF.placeholder = K.AuthenticationStringConstant.enterPassword.localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
}
private func tfMod(textField : [UITextField]){
for i in textField{
i.roundCorner(radius: i.frame.height / 2)
i.delegate = vc.self
}
}
// MARK: - Get Intrests
func checkUsernameExist(onCompletion: @escaping (Bool) -> Void){
let params: Parameters = [
"email": AuthFunc.shareInstance.regData.email!,
"username": vc.enterUserNameTF.text!,
"user_type": (createChildAccount != nil) ? "1" : (AuthFunc.shareInstance.userType == .adult ? "2" :"1")
]
let headers : HTTPHeaders = ["Accept-Language" : AuthFunc.shareInstance.languageSelected == .english ? "English" : "Hindi"]
Utilities.startProgressHUD(msg: K.ConstantString.userNameVerify)
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Auth.check_exist_username, method: .post,parameters: params, headers: headers) {(result : Result<BaseResponseModel<IntrestTopicDM>, NetworkManager.APIError>) in
switch result{
case .success(let data):
//0 -> Username already used. , 1-> Username available
switch data.success{
case 0:
Utilities.dismissProgressHUD()
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
onCompletion(false)
case 1:
Utilities.dismissProgressHUD()
onCompletion(true)
default:
break
}
case .failure(let error):
Utilities.dismissProgressHUD()
self.vc.toast(msg: error.localizedDescription, time: 2)
onCompletion(false)
}
}
}
}