如何在注册后发送验证电子邮件

时间:2018-02-06 21:03:13

标签: android firebase firebase-authentication

我正在使用Firebase进行用户注册,但在注册后我找不到任何方法来发送验证邮件。

auth = FirebaseAuth.getInstance();

auth.createUserWithEmailAndPassword(email, password)
    .addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
            progressBar.setVisibility(View.GONE);
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful()) {
                Toast.makeText(SignupActivity.this, "Authentication failed." + task.getException(),
                        Toast.LENGTH_SHORT).show();
            } else {
                FirebaseUser user = auth.getCurrentUser()

                startActivity(new Intent(SignupActivity.this, MainActivity.class));
                finish();
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

您可以使用sendEmailVerification方法向用户发送地址验证电子邮件。例如:

FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();

user.sendEmailVerification()
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "Email sent.");
            }
        }
    });

此处有更多信息:https://firebase.google.com/docs/auth/android/manage-users