<?php

date_default_timezone_set("Africa/Lagos");
require_once '../../vendor/autoload.php';
require_once '../../include/DatabaseConn.php';
require_once '../../include/Constants.php';

$db = new DatabaseConn();
$link = $db->connect();

$std = new stdClass();

$id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_EMAIL);


header("content-type: application/json");

if (is_null($id)) {
    $error = 'Token missing in request body';
    $std->error = $error;
    echo (json_encode($std));
    die();
} else {
    $twofa = 0;

    mysqli_query($link, "update usettings set twofa = $twofa WHERE `user` = '$id'");
    mysqli_query($link, "update users set fa = NULL, secret = NULL  WHERE email = '$id'");

    if (mysqli_affected_rows($link) == 1) {
        $std->msg = "Operation Successful";
        echo (json_encode($std));
        die();
    } else {
        $error = 'Already reset';
        $std->error = $error;
        echo (json_encode($std));
        die();
    }
}

