
<?php namespace App\Controllers;
use App\Models\UserModel;

class Auth extends BaseController {
    public function login() { return view('login'); }
    public function doLogin() {
        $model = new UserModel();
        $user = $model->where('email', $this->request->getPost('email'))->first();
        if($user && password_verify($this->request->getPost('password'), $user['password'])){
            session()->set($user);
            return redirect()->to($user['role']=='admin' ? '/admin' : '/employee');
        }
        return redirect()->back();
    }
    public function logout() {
        session()->destroy();
        return redirect()->to('/');
    }
}
