我使用Firebase的电子邮件和密码方法注册我的用户 . 像这样:
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser signed = task.getResult().getUser();
writeNewUser(signed.getUid());
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
updateUser(b);
}
}, 3000);
} else {
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
onSignupFailed();
}
}, 3000);
}
}
});
用户's email has been successfully registered, I would like Firebase to send a verification email. I know this is possible using Firebase'之后 sendEmailVerification
. 除了发送此电子邮件,我还想要用户's account to be disabled until they verify the email. This would also require using Firebase' s isEmailVerified
功能 . 但是,我没有成功让Firebase发送验证邮件,我无法弄清楚是否要禁用并启用发送验证邮件的帐户以及验证后的电子邮件 .
4 回答
此问题是关于如何使用Firebase发送验证电子邮件 . OP无法弄清楚如何禁用和启用发送验证电子邮件的帐户以及验证后的帐户 .
此外,firebase文档中没有正确记录这一点 . 所以我正在编写一个逐步的程序,如果他/她面临问题,有人可能会遵循这个程序 .
1) User can use createUserWithEmailAndPassword method.
例:
If the new account was created, the user is also signed in, and the AuthStateListener runs the onAuthStateChanged callback. In the callback, you can manage the work of sending the verification email to the user.
Example:
Now the send verification email can be written like:
Now coming to LoginActivity:
在这里,如果用户成功登录,那么我们可以简单地调用一个方法来编写逻辑,以检查电子邮件是否已经过验证 .
Example:
Now consider the checkIfEmailVerified method:
所以我在这里检查电子邮件是否已经过验证 . 如果没有,则注销用户 .
所以这是我正确跟踪事物的方法 .
使用
FirebaseAuth.getInstance().getCurrentUser().sendEmailVerification()
和FirebaseAuth.getInstance().getCurrentUser().isEmailVerified()
无法通过Firebase SDK停用该帐户 . 您可以做的是使用包含Firebase身份验证ID令牌的
GetTokenResult
并根据您的自定义后端对其进行验证,或者为与该用户对应的Firebase数据库设置一个标志 . 就个人而言,我会使用Firebase数据库中的标志将验证发送到用户的电子邮件
检查用户是否已经过验证
要首先使用Firebase发送电子邮件链接,您需要使用我们在Firebase上创建用户的实例来抓取FirebaseAuth实例:
方法返回成功后,我们使用Firebase用户实例向用户发送验证链接,如下所示:
看到这个链接:https://technicalguidee.000webhostapp.com/2018/10/email-verification-through-link-using-firebase-authentication-product-android .