<?php

require_once("config/config.php");
require_once("foo/functions.php");
dbconnect();

if ($_SERVER['REQUEST_METHOD'] === 'GET') {

$sql = "SELECT * FROM `".USERS_TABLE_NAME."` WHERE pwd_reset_hash='{$_GET['token']}'";
$stmt = $pdo->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$user = $row['user_name'];
$email = $row['user_email'];
$token = "";

$dateFromDatabase = strtotime($row['pwd_reset_ts']);
$dateTwelveHoursAgo = strtotime("-12 hours");

if ($dateFromDatabase >= $dateTwelveHoursAgo) {
	update_token($token, $email);
	redirect('update-settings.php?user='.$user.'');	
}
else {
	update_token($token, $email);
    echo "Password reset link has expired";
}
}

?>