如何阻止用户在未验证电子邮件 ID 的情况下登录首先在 Firebase 中? [英] How to stop users from signing in without verifying e-mail I.D. first in Firebase?

查看:15
本文介绍了如何阻止用户在未验证电子邮件 ID 的情况下登录首先在 Firebase 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Studio 中创建了一个应用程序,除了少数其他字段外,用户还使用电子邮件和密码进行注册.这是我正在使用的代码:

I have created an app in Android Studio where the user signs up with email and password besides few other fields. This is the code I am using:

公共类 MainActivity 扩展 AppCompatActivity {

public class MainActivity extends AppCompatActivity {

EditText etName, etService, etDes, etCost, etContact, etPass, etEmail;
Button offer;
CountryCodePicker ccp;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    etName = findViewById(R.id.enterName);
    etService = findViewById(R.id.enterService);
    etDes = findViewById(R.id.enterDescription);
    etCost = findViewById(R.id.enterCost);
    etContact = findViewById(R.id.enterContact);
    etPass = findViewById(R.id.enterPassword);
    etEmail = findViewById(R.id.enterEmail);
    ccp = findViewById(R.id.ccpLogin);

    ccp.registerCarrierNumberEditText(etContact);

    offer = findViewById(R.id.offerBtn);

    mAuth=FirebaseAuth.getInstance();

    offer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            final String putEmail=etEmail.getText().toString();
            final String putPass=etPass.getText().toString();

            //final String fullNumber = ccp.getFullNumberWithPlus();

            //final String key=fullNumber+putEmail;

            if(notEmpty()){
            mAuth.createUserWithEmailAndPassword(putEmail, putPass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful())
                    {
                        final String putName=etName.getText().toString();
                        final String putService=etService.getText().toString();
                        final String putDes=etDes.getText().toString();
                        final String putCost=etCost.getText().toString();
                        final String putEmail=etEmail.getText().toString();
                        final String putPass=etPass.getText().toString();

                        final String fullNumber = ccp.getFullNumberWithPlus();

                        sendVerificationEmail();
                        //checkVerification(putName,putService,putDes,putCost,fullNumber,putPass,putEmail);
                    }
                    else
                        Toast.makeText(MainActivity.this, "Failed to send EMail", Toast.LENGTH_LONG).show();
                }
            });
            }
            else
                Toast.makeText(MainActivity.this, "All Fields Are Required", Toast.LENGTH_LONG).show();
        }
    });
}

现在我的问题是有什么方法可以阻止用户在不先验证他们的电子邮件 ID 的情况下注册?createUserWithEmailAndPassword() 方法似乎在验证用户的电子邮件 ID 之前首先登录用户,我认为这违背了使用电子邮件验证的真正目的,即阻止用户使用虚假或无效的电子邮件 ID 访问数据库.此外,如果用户尚未验证他的电子邮件 ID,那么我似乎无法从 Firebase 的身份验证"下的用户"部分中删除用户,因为那时他已经创建并登录了.

Now my question is is there any way that I can stop users from signing up without verifying their email ids first? The createUserWithEmailAndPassword() method seems to sign in the user first before their email id is verified which, I think, defeats the very purpose of using email verification i.e. to stop users from reaching the database with a fake or invalid email id. Also there seems to be no way that I can delete the user from Firebase "Users" section under "Authentication" if the user hasn't verified his email id as by then he has already been created and signed in.

推荐答案

您可以使用 FirebaseUI.它负责登录用户界面、登录过程并让您有机会处理电子邮件验证,请查看有关如何进行 FirebaseUI 电子邮件验证的问题:

You can use the FirebaseUI. It takes care of the login-ui, login process and gives you a chance to handle the email verification, check out this question about how to do the FirebaseUI email verification:

Firebase Auth UIFirebaseUI 的电子邮件验证

FirebaseUI

这篇关于如何阻止用户在未验证电子邮件 ID 的情况下登录首先在 Firebase 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆