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

6 years ago
  1. //
  2. // ChangePasswordViewModel.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 12/20/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class ResetPasswordViewModel: SignUpViewModel {
  10. var passwordChanged: Box<Bool?> = Box(nil)
  11. var resetPasswordConnectionTimeOut: Box<Bool?> = Box(nil)
  12. var newPassword: String!
  13. var userId: String!
  14. let user_id = UserDefaults.standard.object(forKey: "com.gmeremit.username") as? String
  15. let user_password = UserDefaults.standard.object(forKey: "com.gmeremit.password") as? String
  16. }
  17. extension ResetPasswordViewModel {
  18. /**
  19. TO set new password
  20. - parameter userID : userId
  21. - parameter password: new password
  22. */
  23. func setUpdatedCredentials(userId: String, password: String) {
  24. self.userId = userId
  25. self.newPassword = password
  26. }
  27. /**
  28. Api request to change the password
  29. */
  30. func changePassword() {
  31. if !Reachability.isConnectedToNetwork() {
  32. self.internetConnection.value = false
  33. } else {
  34. RestApiMananger.sharedInstance.resetPassword(userId: userId, password: newPassword) { result in
  35. switch result {
  36. case .success(_):
  37. self.passwordChanged.value = true
  38. case let .failure(errorJSON):
  39. self.setErrorMessage(message: errorJSON["message"].stringValue)
  40. self.passwordChanged.value = false
  41. case .updateAccessCode:
  42. return
  43. case .logOutUser():
  44. return
  45. case .timeOut:
  46. self.resetPasswordConnectionTimeOut.value = false
  47. }
  48. }
  49. }
  50. }
  51. }