1. Are you ready for the Galaxy S20? Here is everything we know so far!

Hello, i am making tasks correctly but it still gives me sign up fail, whats wrong

Discussion in 'Android Development' started by shakoc, Jan 17, 2020.

  1. shakoc

    shakoc Lurker
    Thread Starter

    Code (Text):
    1. package com.trashysofts.auct
    2.  
    3.  
    4. import android.content.Intent
    5. import android.os.Bundle
    6. import android.util.Patterns
    7. import android.widget.Toast
    8. import androidx.appcompat.app.AppCompatActivity
    9. import com.google.firebase.auth.FirebaseAuth
    10. import kotlinx.android.synthetic.main.register_layout.*
    11.  
    12. class RegisterActivity : AppCompatActivity() {
    13.  
    14.     private lateinit var auth: FirebaseAuth
    15.  
    16.     override fun onCreate(savedInstanceState: Bundle?) {
    17.         super.onCreate(savedInstanceState)
    18.         setContentView(R.layout.register_layout)
    19.         auth = FirebaseAuth.getInstance()
    20.         buttonJoin.setOnClickListener {
    21.             signUpUser()
    22.         }
    23.  
    24.     }
    25.  
    26.     private fun signUpUser() {
    27.         if (emailTextSignUp.text.toString().isEmpty()) {
    28.             emailTextSignUp.error = "Please enter email"
    29.             emailTextSignUp.requestFocus()
    30.             return
    31.         }
    32.         if (!Patterns.EMAIL_ADDRESS.matcher(emailTextSignUp.text.toString()).matches()) {
    33.             emailTextSignUp.error = "Please enter valid email"
    34.             emailTextSignUp.requestFocus()
    35.             return
    36.         }
    37.         if (passwordTextSignUp.text.toString().isEmpty()) {
    38.             passwordTextSignUp.error = "Please enter password"
    39.             passwordTextSignUp.requestFocus()
    40.             return
    41.         }
    42.         auth.createUserWithEmailAndPassword(emailTextSignUp.text.toString(), passwordTextSignUp.text.toString())
    43.             .addOnCompleteListener(this) { task ->
    44.                 if (task.isSuccessful) {
    45.                     startActivity(Intent(this,LoginActivity::class.java))
    46.                     finish()
    47.                 } else {
    48.                     Toast.makeText(baseContext, "Sign Up failed",
    49.                         Toast.LENGTH_SHORT).show()
    50.                 }
    51.             }
    52.     }
    53. }
    54.  
     

    Advertisement

Loading...

Share This Page

Loading...