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

查看:79
本文介绍了如何在不验证电子邮件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 中尝试该演示应用程序

Try the demo app at FirebaseUI

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

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