【发布时间】:2020-04-04 18:25:37
【问题描述】:
在我的应用中更改密码的功能:
@IBAction func changePassword(_ sender: Any) {
let isMatched = NSPredicate(format:"SELF MATCHES %@", regexAllValidation).evaluate(with: newPasswordField.text)
if (isMatched == true){
let auth = Auth()
auth.changePassword(oldPassword: oldPasswordField.text!,newPassword: newPasswordField.text!)
displayAlert(title: "Correct password", message: "Password changed!")
}
}
类认证:
func changePassword(oldPassword: String, newPassword: String){
let user =
AppDelegate.defaultUserPool().currentUser()?.changePassword(oldPassword, proposedPassword: newPassword)
AppDelegate.defaultUserPool().currentUser()?.clearSession()
}
当我使用错误的旧密码调用此函数时,我在控制台中收到:
Response body:
{"__type":"NotAuthorizedException","message":"Incorrect username or password."}
"x-amzn-errormessage" = "Incorrect username or password.";
"x-amzn-errortype" = "NotAuthorizedException:";
我想显示一条警报,通知用户密码错误。 怎么做?
【问题讨论】:
-
这个函数
AppDelegate.defaultUserPool().currentUser()?.changePassword必须有一个闭包,通常叫它completion,它有吗?
标签: swift amazon-cognito