You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
//
|
|
// ChangePasswordViewModel.swift
|
|
// GMERemittance
|
|
//
|
|
// Created by Sujal on 12/20/17.
|
|
// Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class ResetPasswordViewModel: SignUpViewModel {
|
|
var passwordChanged: Box<Bool?> = Box(nil)
|
|
var resetPasswordConnectionTimeOut: Box<Bool?> = Box(nil)
|
|
var newPassword: String!
|
|
var userId: String!
|
|
|
|
let user_id = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String
|
|
let user_password = UserDefaults.standard.object(forKey: "com.gmeremit.password") as? String
|
|
}
|
|
|
|
extension ResetPasswordViewModel {
|
|
|
|
/**
|
|
TO set new password
|
|
- parameter userID : userId
|
|
- parameter password: new password
|
|
*/
|
|
func setUpdatedCredentials(userId: String, password: String) {
|
|
self.userId = userId
|
|
self.newPassword = password
|
|
}
|
|
|
|
/**
|
|
Api request to change the password
|
|
*/
|
|
func changePassword() {
|
|
if !Reachability.isConnectedToNetwork() {
|
|
self.internetConnection.value = false
|
|
} else {
|
|
RestApiMananger.sharedInstance.resetPassword(userId: userId, password: newPassword) { result in
|
|
switch result {
|
|
case .success(_):
|
|
self.passwordChanged.value = true
|
|
case let .failure(errorJSON):
|
|
self.setErrorMessage(message: errorJSON["message"].stringValue)
|
|
self.passwordChanged.value = false
|
|
case .updateAccessCode:
|
|
return
|
|
case .logOutUser():
|
|
return
|
|
case .timeOut:
|
|
self.resetPasswordConnectionTimeOut.value = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|