<?php
chdir('../');
require_once 'autoload.php';
$admin = new admin_controller;
$pw_reset_tokens = new reset_pw_tokens_controller;
$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())) {

$new_password = $_POST['new-password'];

$reset_token = $pw_reset_tokens->show($_POST['reset_token']);

$data = $admin->show($reset_token['admin_id']);

$reset_data['hashed_pw'] = password_hash($new_password, PASSWORD_BCRYPT);

$admin->update($reset_token['admin_id'], $reset_data);

$pw_reset_tokens->destroy($_POST['reset_token']);

$utility->setMessage("success", 'Your password has been changed');

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

}else{

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

}
?>
