【发布时间】:2018-05-30 14:32:18
【问题描述】:
我正在尝试使用 Firebase 在我的应用程序中创建一个忘记密码按钮,但它仅在我编写要在代码中更改密码的电子邮件时才有效,这是“错误”的代码行.
Auth.auth().sendPasswordReset(withEmail: "email@email"
代码中不写邮箱怎么修改账号密码?问题是如果我不在代码中写他的电子邮件地址,注册用户无法重置他的密码,它只适用于给定的电子邮件地址 以下是完整代码
@IBAction func resetPasswordTapped(_ sender: UIButton) {
var loginTextField: UITextField?
let alertController = UIAlertController(title: "Password Recovery", message: "Please enter your email address", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
if loginTextField?.text != "" {
Auth.auth().sendPasswordReset(withEmail: ("email@email") { (error) in
if (error == nil) {
self.showErrorAlert(title: "Password reset", msg: "Check your inbox to reset your password")
} else {
print(error)
self.showErrorAlert(title: "Unidentified email address", msg: "Please re-enter the email you registered with")
}
}
}
print("textfield is empty")
})
let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
}
alertController.addAction(ok)
alertController.addAction(cancel)
alertController.addTextField { (textField) -> Void in
// Enter the textfiled customization code here.
loginTextField = textField
loginTextField?.placeholder = "Enter your login ID"
}
present(alertController, animated: true, completion: nil)
}
func showErrorAlert(title: String, msg: String) {
let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)}
【问题讨论】:
-
你在问什么有点不清楚;您是说如果您在代码中包含电子邮件地址字符串,它可以工作,但您不知道如何获取电子邮件?
-
问题是如果我不在代码中写他的电子邮件地址,注册用户无法重置他的密码
-
我认为这是设计使然,firebase 通过电子邮件发送密码重置,因为我假设用户 signedUpWithEmailAndPassword()。您是在问如何让用户在应用中立即重置密码?
-
您首先需要让用户输入他们注册时使用的电子邮件,然后将该电子邮件用作 withEmail 的参数。