Created
October 14, 2019 23:37
-
-
Save mishra3452/8eb61e899afe0700ed1fffe6f4353b4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mindorks.firebaseloginsignup | |
import android.content.Intent | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.text.TextUtils | |
import android.widget.Button | |
import android.widget.EditText | |
import android.widget.Toast | |
import com.google.android.gms.tasks.OnCompleteListener | |
import com.google.firebase.auth.FirebaseAuth | |
class SignupActivity : AppCompatActivity() { | |
private lateinit var auth: FirebaseAuth | |
private lateinit var emailEt: EditText | |
private lateinit var passwordEt: EditText | |
private lateinit var signUpBtn: Button | |
private lateinit var loginBtn: Button | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_signup) | |
auth = FirebaseAuth.getInstance() | |
emailEt = findViewById(R.id.email_edt_text) | |
passwordEt = findViewById(R.id.pass_edt_text) | |
loginBtn = findViewById(R.id.login_btn) | |
signUpBtn = findViewById(R.id.signup_btn) | |
signUpBtn.setOnClickListener{ | |
var email: String = emailEt.text.toString() | |
var password: String = passwordEt.text.toString() | |
if(TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) { | |
Toast.makeText(this, "Please fill all the fields", Toast.LENGTH_LONG).show() | |
} else{ | |
auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, OnCompleteListener{ task -> | |
if(task.isSuccessful){ | |
Toast.makeText(this, "Successfully Registered", Toast.LENGTH_LONG).show() | |
val intent = Intent(this, MainActivity::class.java) | |
startActivity(intent) | |
finish() | |
}else { | |
Toast.makeText(this, "Registration Failed", Toast.LENGTH_LONG).show() | |
} | |
}) | |
} | |
} | |
loginBtn.setOnClickListener{ | |
val intent = Intent(this, LoginActivity::class.java) | |
startActivity(intent) | |
finish() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment