<?php
chdir('../');
require_once 'autoload.php';
$admin = new admin_controller;
$session = new session;
$uni = new university_controller;

$info = $uni->index();

date_default_timezone_set($info['timezone']);

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['csrf_token']) && $waf->csrf_validate($_POST['csrf_form_id'], $_POST['csrf_token'], $utility->action_name())) {

$sanitezed_data = $utility->sanitize_request($_POST);

$waf->checkAttempt($sanitezed_data['login-email']);

$data = $admin->auth($sanitezed_data['login-email']);

if (!empty($data)) {

if (password_verify($sanitezed_data['login-password'], $data['hashed_pw'])) {

$session->create_session($data);

header("location:../app/dashboard");


}else{

$waf->recordFailedAttempt($sanitezed_data['login-email']);

$utility->setMessage("warning", 'Invalid login credentials');

header("location:../admin");

}

}else{

$waf->recordFailedAttempt($sanitezed_data['login-email']);

$utility->setMessage("warning", 'Invalid login credentials');

header("location:../admin");

}
}else{
header("location:../admin");
}
?>
