ios - 忘记密码按钮 firebase iOS

标签 ios swift firebase

我正在尝试使用 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)}

最佳答案

正如评论中所述,您的问题有点不清楚。您必须提供电子邮件才能发送密码重置电子邮件。您不能使用其他任何东西,除非您严格编写函数来查找用户名/用户/用户 ID 以查找电子邮件。这有点不必要。

这是我在我的应用程序中使用的示例

{this.state.showPasswordReset ? <div>
                <p>Input the email you signed up with, and we will email you directions to reset your password.</p>
                <form >
                    <TextField
                        hintText="email"
                        floatingLabelText="email"
                        multiLine={false}
                        rows={1}
                        name='email'
                        type='text'
                        value={this.state.email}
                        onChange={(email) => this.setState({ email })}
                    />
                </form>
                <RaisedButton label='Send Password Reset Email' onClick={this.sendPasswordResetEmail.bind(this)} primary={true} type='submit' />
                {/* <Button style={{ backgroundColor: '#757575', margin: 5 }} block onPress={this.sendPasswordResetEmail.bind(this)}>Send Password Reset Email</Button> */}
            </div>
                : <div>
                    <p>Forgot your password? Reset it <p style={{ color: 'red', textDecorationLine: "underline", }} onClick={() => this.setState({ showPasswordReset: !this.state.showPasswordReset })}>here</p></p>
                </div>}

关于ios - 忘记密码按钮 firebase iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47848300/

相关文章:

android - Firestore - 如何在 Kotlin 中排除数据类对象的字段

firebase - 使用 rxDart 合并 Firestore 流

ios - Firebase 远程配置错误 8003,Unity,iOS

ios - 将不同的图钉图像与不同的位置 iOS 相关联

ios - 如何在 Xcode 5 中手动将仅限 iPhone 的应用程序转换为 Universal?

ios - 将 SKNode 从其当前位置移动一个 Tile

arrays - 快速性能 : map() and reduce() vs for loops

android - 如何在需要找到目标文档的地方创建 firestore 事务

ios - 图表中选定切片的颜色

ios - Swift:加载带有动画的 .Xib