Browse Source

password upded function added

pull/1/head
gme_2 6 years ago
parent
commit
f651d30392
  1. 17
      GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift
  2. 140
      GMERemittance/Profile/ProfileChangePasswordViewController.swift

17
GMERemittance/Module/Register/Application Logic/Interactor/RegisterInteractor.swift

@ -56,20 +56,7 @@ class RegisterInteractor {
return "172017F9EC11222E8107142733" return "172017F9EC11222E8107142733"
} }
// func hasOnlyAlphanumeric() -> (String) -> Bool {
// let alphaCharacterSet = CharacterSet.alphanumerics
// return {text in
// text.rangeOfCharacter(from: alphaCharacterSet) != nil
// }
// }
//
// func hasOnlyLettersWithSpaces(_ text: String) -> Bool {
// let alphaCharacterSet = CharacterSet.letters
// let spaceCharacterSet = CharacterSet.init(charactersIn: " ")
// let alphaWithSpacesCharacterSet = alphaCharacterSet.union(spaceCharacterSet)
//
// return text.rangeOfCharacter(from: alphaWithSpacesCharacterSet) != nil
// }
private func isValidPasword(password: String, confirmPassword: String) -> (isValid: Bool, error: String) { private func isValidPasword(password: String, confirmPassword: String) -> (isValid: Bool, error: String) {
var error = "" var error = ""
@ -127,7 +114,7 @@ class RegisterInteractor {
} }
// MARK: Converting entities // MARK: Converting entities
private func isValid(userName: String, password: String, confirmPassword: String, dob: String) -> (isValid: Bool, error: Error){
private func isValid(userName: String, password: String, confirmPassword: String, dob: String) -> (isValid: Bool, error: Error) {
var error = "" var error = ""
var isValid = true var isValid = true
// user name // user name

140
GMERemittance/Profile/ProfileChangePasswordViewController.swift

@ -29,25 +29,155 @@ class ProfileChangePasswordViewController: UIViewController {
} }
// "{
// ""UserId"":""pathaksumitra4@gmail.com"",
// ""OldPassword"":""P23FAB"",
// ""NewPassword"":""swift""
//
//}"
@IBAction func savePasswordChanges(_ sender: Any) { @IBAction func savePasswordChanges(_ sender: Any) {
let currentPassword = self.textFieldCurrentPassword.text! let currentPassword = self.textFieldCurrentPassword.text!
let newPassword = self.textFieldNewPassword.text! let newPassword = self.textFieldNewPassword.text!
let confirmPassword = self.textFieldConfirmPassword.text! let confirmPassword = self.textFieldConfirmPassword.text!
let result = self.isValid(currentPassword: currentPassword, password: newPassword, confirmPassword: confirmPassword)
if result.isValid {
let userId = Utility.getMyUserName()
let param =
[
"UserId" : userId,
"OldPassword": currentPassword,
"NewPassword": newPassword
]
self.updatePassword(param: param)
}else {
let message = result.error
self.alert(message: message.localizedDescription)
}
}
func updatePassword(param: [String: String]) {
self.updatePassword(params: param, success: { (message) in
self.alert(message: message, title: "Success", okAction: {
self.navigationController?.popViewController(animated: true)
})
}) { (error) in
self.alert(message: error.localizedDescription)
}
} }
}
extension ProfileChangePasswordViewController {
private func isValidPasword(password: String, confirmPassword: String) -> (isValid: Bool, error: String) {
var error = ""
var isValid = true
// >= 9, 1 special character, 1 number
func isValidLength() -> Bool {
return password.count >= 9
}
func hasNumber() -> Bool {
let characterSet = CharacterSet.init(charactersIn: "1234567890")
return password.rangeOfCharacter(from: characterSet) != nil
}
func hasLetter() -> Bool {
let characterSet = CharacterSet.letters
return password.rangeOfCharacter(from: characterSet) != nil
}
func hasSpecialCharacter() -> Bool {
let characterSet = CharacterSet.alphanumerics
return password.rangeOfCharacter(from: characterSet.inverted) != nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
if password.isEmpty {
error = error + "\n Password cannot be empty"
isValid = false
}else {
if !isValidLength() {
error = error + "\n Password should be greater than 8 character."
isValid = false
return (isValid, error)
}
let validPassword = hasNumber() && hasLetter() && hasSpecialCharacter()
if !validPassword {
isValid = false
error = error + "\n Password should contain at least 1 number, 1 letter and 1 special character"
return (isValid, error)
}
if password != confirmPassword {
error = error + "\n Passwords does not match."
isValid = false
}
}
return (isValid, error)
} }
// MARK: Converting entities
private func isValid(currentPassword: String, password: String, confirmPassword: String) -> (isValid: Bool, error: Error) {
var error = ""
var isValid = true
// user name
if currentPassword.isEmpty {
error = error + "current password field is required.";
isValid = false
}
let result = self.isValidPasword(password: password, confirmPassword: confirmPassword)
if !result.isValid {
error = error + result.error
isValid = false
}
func popOutCurrentViewController() {
dismiss(animated: true, completion: nil)
navigationController?.popViewController(animated: true)
let _error = NSError.init(domain: "LoginInteractor", code: 0, userInfo: [NSLocalizedDescriptionKey : error])
return (isValid, _error)
} }
} }
extension ProfileChangePasswordViewController: UpdatePasswordService {
}
protocol UpdatePasswordService: ApiServiceType {
func updatePassword(params: [String: String], success: @escaping (String?) -> (), failure: @escaping (Error) -> ())
}
extension UpdatePasswordService {
func updatePassword(params: [String: String], success: @escaping (String?) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "mobile/ChangePassword"
auth.request(method: .post, url: url, params: params, needsAuthorization: false, success: { (response: SuccessMessageContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
failure(error)
}else {
success(response.data?.message)
}
}) { (error) in
failure(error)
}
}
}
Loading…
Cancel
Save