简体   繁体   中英

User isn't registered

I am trying to build an app using Kotlin. The user isn't registered in the firebase. I am new to Kotlin. I can't figure out the problem. Here is the code. In the code, all the toast functions work. It shows the toast when those entering fields are empty. But it does not registers the user. Don't know why. Where is the problem? Please help.

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageButton
import com.google.firebase.auth.ktx.actionCodeSettings
import android.text.TextUtils
import android.widget.EditText
import android.widget.Toast
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseUser




class register_page : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register_page)

    val sign_up_button = findViewById<ImageButton>(R.id.sign_up_btn)
    val sign_up_name = findViewById<EditText>(R.id.sign_up_name)
    val sign_up_email = findViewById<EditText>(R.id.sign_up_email)
    val sign_up_password = findViewById<EditText>(R.id.sign_up_password)

    sign_up_button.setOnClickListener {
        when {
            TextUtils.isEmpty(sign_up_name.text.toString().trim { it <= ' ' }) -> {
                Toast.makeText(
                    this@register_page,
                    "Please enter a name.",
                    Toast.LENGTH_SHORT
                ).show()
            }


            TextUtils.isEmpty(sign_up_email.text.toString().trim { it <= ' ' }) -> {
                Toast.makeText(
                    this@register_page,
                    "Please enter an email.",
                    Toast.LENGTH_SHORT
                ).show()
            }


            TextUtils.isEmpty(sign_up_password.text.toString().trim { it <= ' ' }) -> {
                Toast.makeText(
                    this@register_page,
                    "Please enter a password.",
                    Toast.LENGTH_SHORT
                ).show()
            }


            else -> {
                val email: String = sign_up_email.text.toString().trim { it <= ' ' }
                val password: String = sign_up_password.text.toString().trim { it <= ' ' }
                val user_name: String = sign_up_name.text.toString().trim { it <= ' ' }

                FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password)
                    .addOnCompleteListener(
                        OnCompleteListener<AuthResult> { task ->

                            //If registration is successfully done
                            if (task.isSuccessful) {
                                val firebaseUser = task.result!!.user!!

                                Toast.makeText(
                                    this@register_page,
                                    "Registration successful.",
                                    Toast.LENGTH_SHORT
                                ).show()


                                val intent =
                                    Intent(this@register_page, MainActivity::class.java)
                                intent.flags =
                                    Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
                                intent.putExtra("user_id", firebaseUser.uid)
                                intent.putExtra("email_id", firebaseUser.email)
                                startActivity(intent)
                                finish()
                            } else {
                                Toast.makeText(
                                    this@register_page,
                                    task.exception!!.message.toString(),
                                    Toast.LENGTH_SHORT
                                ).show()
                            }
                        }
                    )
            }

        }

    }

}

}

始终确保包名称相同。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM