MainActivity.kt 1.66 KB
package com.example.vip

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
import org.w3c.dom.Node


class MainActivity : AppCompatActivity() {

    private val firebaseAuth = FirebaseAuth.getInstance()

    // EmailCreate

    // Email SignIn
    private fun loginEmail(){
        firebaseAuth!!.signInWithEmailAndPassword(edit_email.text.toString(), edit_password.text.toString())
            .addOnCompleteListener(this) {
                if (it.isSuccessful) {
                    // Sign in success, update UI with the signed-in user's information
                    Toast.makeText(this, "signInWithEmail success.",Toast.LENGTH_SHORT).show()
                    val user = firebaseAuth?.currentUser

                    if (user!=null){
                        var intent = Intent(this, SignInActivity::class.java)
                        startActivity(intent)

                    }


                } else {
                    // If sign in fails, display a message to the user.
                    Toast.makeText(this, "signInWithEmail failed.",Toast.LENGTH_SHORT).show()

                }
            }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

        emailSigninBtn.setOnClickListener{
            loginEmail()

        }

        emailSignupBtn.setOnClickListener {
            var intent = Intent(this, SignUpActivity::class.java)
            startActivity(intent)
        }

    }


}