【问题标题】:Problem with verifying the user authentication验证用户身份验证的问题
【发布时间】:2021-02-09 18:26:34
【问题描述】:

我是 java 编程的初学者我正在尝试在应用程序中创建 2 路登录系统,第一个是电子邮件,第二个是电话号码,但我一直在识别用户是用电话登录的用户号码或电子邮件 在我的初始屏幕上,首先我检查了用户是否为空或否,如果它不为空,然后我检查用户电子邮件是否已验证,如果用户电子邮件已验证,则用户可以转到主应用程序,但如果用户电子邮件没有经过验证,那么他应该去验证页面,在那里他应该首先验证他的帐户,但如果用户使用他的电话号码登录,他应该只去主应用程序但我的问题是什么时候用电话号码注册,我打开应用程序,它会进入验证电子邮件页面。

public class SplashScreen extends AppCompatActivity
{
   ImageView icon;
   TextView app;
   RelativeLayout relativeLayout;
   Animation layout;
   private FirebaseAuth mAuth;
   FirebaseUser firebaseUser;

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

    firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    mAuth = FirebaseAuth.getInstance();


    app = findViewById(R.id.splash_scren_app);
    relativeLayout = findViewById(R.id.splash_srceen);
    icon = findViewById(R.id.splash_srceen_icon);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            relativeLayout.setVisibility(View.VISIBLE);
            relativeLayout.setAnimation(layout);

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    app.setVisibility(View.VISIBLE);
                    icon.setVisibility(View.VISIBLE);
                }
            },500);
        }
    },1000);

    if (firebaseUser!=null)
    {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run()
            {
                if (firebaseUser.isEmailVerified())
                {
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                    finish();
                }
                else
                {
                    Intent intent = new Intent(SplashScreen.this,EmailVerification.class);
                    startActivity(intent);
                    finish();
                }
            }
        },5000);
    }
    else
    {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                Intent intent = new Intent(SplashScreen.this,WelcomeScreen.class);
                startActivity(intent);
                finish();
            }
        },5000);
    }
  }
}

【问题讨论】:

    标签: java firebase firebase-authentication android-studio-3.0


    【解决方案1】:

    你的逻辑有问题

    if (firebaseUser.isEmailVerified())
                    {
                        Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                        startActivity(intent);
                        finish();
                    }
                    else
                    {
                        Intent intent = new Intent(SplashScreen.this,EmailVerification.class);
                        startActivity(intent);
                        finish();
                    }
    

    改为这样做

    if (firebaseUser.isEmailVerified() || firebase.getPhoneNumber() != null)
                    {
                        Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                        startActivity(intent);
                        finish();
                    }
                    else
                    {
                        if(firebaseUser.isEmailVerified()){
                        Intent intent = new Intent(SplashScreen.this,EmailVerification.class);
                        startActivity(intent);
                        finish();
                        }
                        else if (firebase.getPhoneNumber() != null){
                         //go to the phone verify activity
                         }
                    }
    

    【讨论】:

    • 将我的答案标记为正确,以便人们知道:D
    猜你喜欢
    • 1970-01-01
    • 2017-02-08
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 2019-07-24
    • 1970-01-01
    相关资源
    最近更新 更多