class LoginActivity : AppCompatActivity() {
class LoginActivity : AppCompatActivity() {
private val mAuth: FirebaseAuth by lazy { FirebaseAuth.getInstance() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
buttonLogIn_LoginAc.setOnClickListener {
val email = editTextEmail_LoginAc.text.toString()
val password = editTextPassword_LoginAc.text.toString()
if (isValidEmailAndPassword(email, password)){
logInByEmail(email, password)
}
}
textViewForgotPassword_LoginAc.setOnClickListener {
goToActivity<ForgotPasswordActivity>()
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
}
buttonCreateAccount_LoginAc.setOnClickListener {
goToActivity<SignUpActivity>()
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
}
}
private fun logInByEmail(email: String, password: String){
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this) {task ->
if (task.isSuccessful) {
toast("User is now logg in")
}else {
toast("an unexpected error occurred, please try again.")
}
}
}
private fun isValidEmailAndPassword(email: String, password: String): Boolean{
return !email.isNullOrEmpty() && !password.isNullOrEmpty()
}}