//
//  LoginPage.swift
//  Mindtap_Official
//
//  Created by Lunar on 5/25/21.
//

import UIKit

import Firebase
import FirebaseAuth

class LoginPage: UIViewController {

    @IBOutlet weak var EmailInfo: UITextField!
    @IBOutlet weak var inSuffInfo: UILabel!
    @IBOutlet weak var PasswordInfo: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    

    @IBAction func TestLogin(_ sender: UIButton) {
        
        let email = EmailInfo.text!
        let password = PasswordInfo.text!


            
            
        
        Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
            
            if error != nil {
                //couldnt sign in
                self.inSuffInfo.text = "Username or password is incorrect"
        
            } else {
                //user signed in succefully
                print("signed in")
            
                self.transitionToHome()
            }
            
        }
        
 
    }
        
        func transitionToHome() {
            let homeViewController =
                storyboard?.instantiateViewController(identifier:
                Constants.Storyboard.homeViewController) as?
                MainMenu
            
            view.window?.rootViewController = homeViewController
            view.window?.makeKeyAndVisible()
            
        }
  

    }

