?>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Registration for Note Taking App</title>
    <link rel="stylesheet" href="notes.css" />
</head>
<body>

<?php 
if (isset($_POST['submit'])) {
    if (isset($_POST['password']) && isset($_POST['password_confirmation']) && isset($_POST['username'])) {
        if ($_POST['password'] == $_POST['password_confirmation']) {
            if ($authHandler->registerUser($_POST['username'], $_POST['password'])) {
                if ($authHandler->loginUser($_POST['username'], $_POST['password'])) {
                    $success = true;
                    echo '<div class="notification success">Successfully registered, you are now logged in.
                            Forwarding... </div>';
                    // forwards the user to the notes page.
                    echo "<script>\n                            setTimeout(function(){\n                                window.location.href='./notes.php';\n                            },2000);\n                        </script>";
                }
            } else {
                echo '<div class="notification error">Someone else is already using this username. Please try a different name.</div>';
            }
        } else {
            echo "<div class='notification error'>The passwords did not match, please try again.</div>";
        }
    }
}