<?php
include('../db/model.php');
$db = new Model();
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST['username'];
    $password = $_POST['password'];

    $user=$db->GetUserByUserName($username);

    if (isset($user)) {
        if (count($user)>0) {

            if (password_verify($password, $user['password'])) {
                $_SESSION['login'] = true;
                $_SESSION['username'] = $user['username'];
                $_SESSION['fullName'] = strtoupper($user['full_name']);
                $_SESSION['desig'] = $user['desig_code'];

                header("Location: ../content/dashboard.php");
            } else {
                $_SESSION['login'] = false;
                header("Location: ../index.php");
            }
        } else {
            $_SESSION['login'] = false;
            header("Location: ../index.php");
        }
    } else {
        $_SESSION['login'] = false;
        header("Location: ../index.php");
    }
}
