<?php

session_start();

require_once './include/Constants.php';
require_once "./vendor/autoload.php";
require_once "./include/DatabaseConn.php";
require_once './models/Settings.php';
require_once "./models/User.php";



if (isset($_POST['token'])) {
    $token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING);
    $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING);
    
    if ($token == null || $token == FALSE) {
        $error = "Invalid code";
        die($error);
    } else {
        $token = trim($token);
        $db = new DatabaseConn();
        $link = $db->connect();
        $stmt = mysqli_prepare($link, "update users set `token` = ? where email = ?");
        $stmt->bind_param("ss", $token, $email);
        $stmt->execute();
        $stmt->store_result();

        die("OK");
    }
}

$title = 'Confirm Account ' . APP_NAME;
?>