【问题标题】:Forgot password button firebase iOS忘记密码按钮 Firebase iOS
【发布时间】: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 的参数。

标签: ios swift firebase


【解决方案1】:

正如 cmets 中所述,您的问题有点不清楚。您必须提供电子邮件才能发送密码重置电子邮件。您不能使用其他任何东西,除非您严格编写函数来查找用户名/用户/用户 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>}

【讨论】:

    猜你喜欢
    • 2016-11-04
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2012-07-25
    • 1970-01-01
    • 2012-12-20
    • 2013-05-17
    相关资源
    最近更新 更多