<?php
require_once '../models/db_connection.php';
require_once '../models/user_model.php';
    $key = $_GET['key'];
    $decrypt = base64_decode($key);
    if (isset($_POST['reset'])) {
        $newpass = $_POST['setpass'];
        $confpass = $_POST['confpass'];
        if ($newpass == $confpass) {
            $newpassword = password_hash($_POST['setpass'], PASSWORD_DEFAULT);
            $change = mysqli_query($conn, "UPDATE users SET password='$newpassword' WHERE email='$decrypt'");
        echo "<script>
        alert('Course deleted successfully');
        window.location.href = 'login.php';
    </script>";
        } else {
            $error = "<div class='text-danger'>Passwords do not match</div>";
        }
    }

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Regal Admin</title>
    <?php include("../templates/header.php"); ?>
</head>

<body>
    <?php
    if (isset($_GET["message"])) {
        $message = $_GET["message"];
        echo "<script>alert('" . $message . "')</script>";
    }
    ?>
    <div class="container-scroller">
        <div class="container-fluid page-body-wrapper full-page-wrapper">
            <div class="content-wrapper d-flex align-items-center auth px-0">
                <div class="row w-100 mx-0">
                    <div class="col-lg-4 mx-auto">
                        <div class="auth-form-light text-left py-5 px-4 px-sm-5">
                                <div class="text-danger">
                                    <?php
                                            if(isset($error)){
                                                echo $error;
                                            }
                                    ?>
                                </div>
                            <h4>Login Form</h4>
                            <h6 class="font-weight-light">Enter Your New Password</h6>
                            <form class="pt-3" action="" method="POST">
                                <div class="form-group">
                                    <input type="password" class="form-control form-control-lg" id="exampleInputUsername1" placeholder="enter New Password" name="setpass" Required>
                                </div>
                                <div class="form-group">
                                    <input type="password" class="form-control form-control-lg" id="exampleInputEmail1" placeholder="Re-enter new password" name="confpass" Required>
                                </div>

                                <div class="mb-4">

                                </div>
                                <div class="mt-3">
                                    <button class="btn btn-block btn-info btn-lg font-weight-medium auth-form-btn" type='submit' name="reset">Reset Password</button>
                                    
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <!-- content-wrapper ends -->
        </div>
        <!-- page-body-wrapper ends -->
    </div>
    <?php include("../templates/inc_scripts.php"); ?>
</body>

</html>