<?php

require_once "../../src/UserAccountControl.php";
if (isset($_POST)) {
    $User = new User();
    if (isset($_POST['email'])) {
        $result = $User->forgotCreds("step_1", $_POST['email']);
    } elseif (isset($_POST['authcode'])) {
        if ($_POST['password'] != $_POST['password_again']) {
            $result = ['status' => false, 'error' => "Your passwords don't match."];
        }
        $result = $User->forgotCreds("step_2", $_POST['authcode'], $_POST['password']);
    }
    if (is_array($result)) {
        echo json_encode($result);
    } else {
        echo $result;
    }
}