<?php
  class Login extends Controller {
    private LoginModel $loginModel; 
    public function __construct(){
      $file  = file_exists('../app/config/install.php');
      if(isLoggedIn() && $file === true){
            redirect('dashboard');
      }else if($file === false){
            redirect('install');
      }

      $this->loginModel = $this->model('LoginModel');
    }
    public function index(){
      $this->view('dashboard/auth/login');
    }
    public function login()
    {
      $username = $_POST['username'];
      $password = $_POST['password'];
      $data = array('username'=>$username,'password'=>$password);
      $res = $this->loginModel->login($data);
      if($res === true){
        redirect('dashboard/');
      }else{
        $_SESSION['login_error'] = true;
        redirect('login/');
      }
    }


  }