使用电话身份验证时如何管理Firebase实时数据库?使用Kotlin的Android Studio

时间:2019-12-13 17:12:54

标签: android firebase kotlin firebase-realtime-database firebase-authentication

我正在使用此sample code来让用户仅使用那里的电话号码登录,但我需要他们提供更多信息,例如那里的姓名和性别...过去,当我使用电子邮件登录时,用于使用此代码添加这些信息:

    mAuth.createUserWithEmailAndPassword(email, password)
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                val user = User(
                    name,
                    email,
                    gender,
                        0.0.toFloat(),0.0.toFloat(),0.0.toFloat(),0.0.toFloat(),"","",
                        isSameDay().isTheDay())
                FirebaseDatabase.getInstance().getReference("Users")
                    .child(FirebaseAuth.getInstance().currentUser!!.uid)
                    .setValue(user).addOnCompleteListener(OnCompleteListener<Void> { task ->
                        if (task.isSuccessful) {
                            Toast.makeText(this, "Enregistré avec succès", Toast.LENGTH_LONG).show()
                            mProgressbar.dismiss()
                            sendEmailVerification()
                            startActivity(Intent(applicationContext, MainActivity::class.java))
                        }
                    })
            } else {

                if (isConnected() && task.exception.toString() == "com.google.firebase.auth.FirebaseAuthUserCollisionException: The email address is already in use by another account."){
                    mRegisterEmail.error = "Cette adresse email est déjà utilisée par un autre compte!"
                }else if (isConnected()){
                    Toast.makeText(applicationContext, "Echec! \n ${task.exception.toString()}", Toast.LENGTH_LONG).show()
                }
                if(!isConnected()){
                    Toast.makeText(applicationContext, "Connecter à Internet, SVP!", Toast.LENGTH_SHORT).show()
                }
                mProgressbar.dismiss()

            }
        }
}
  

因此,请帮助我找到一种在添加相同信息的同时   使用电话验证..您可以直接将其推送到我的项目中   here

1 个答案:

答案 0 :(得分:0)

我使用此代码解决了这个问题,谢谢

>            user = User(
>                 name,
>                 "email@gmail.com",
>                 gender.text.toString(),
>                 0.0.toFloat(),0.0.toFloat(),0.0.toFloat(),0.0.toFloat(),"","",
>                 isSameDay().isTheDay())
>             FirebaseDatabase.getInstance().getReference("Users")
>                 .child(FirebaseAuth.getInstance().currentUser!!.uid)
>                 .setValue(user).addOnCompleteListener(OnCompleteListener<Void> { task
> ->
>                     if (task.isSuccessful) {
>                         Toast.makeText(this, "Enregistré avec succès", Toast.LENGTH_LONG).show()
>                         mProgressbar.dismiss()
>                     } else {
>                                     Log.e("TAG", "create Account: Fail! ", task.exception)
>                                     Toast.makeText(applicationContext, "Echec! ", Toast.LENGTH_LONG).show()
>                     }
>                 })