<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Staff Login</title>
    <link
      rel="stylesheet"
      href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
      integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous"
    />
    <link rel="icon" href="img/logo.png" type="image/png" />
    <script
      src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
      integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
      integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
      integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
      crossorigin="anonymous"
    ></script>
    <link rel="stylesheet" href="/assets/style.css" />
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"
    />
  <!-- toastr -->
  <link href="../js/toastr.css" rel="stylesheet">
</head>
<body>
    <section class="bg-light2">
        <div class="container">
            <div class="row justify-content-center">   
          <div class="col-lg-4 col-md-12 col-sm-6 login mx-5 pt-3 mt-4 mb-4">
            <div class="row justify-content-center">
                <div class="col-lg-5 col-md-6 col-sm-6">
                  <img
                    class="logo_center mx-auto"
                    src="/img/logo.png"
                    style="height: 130px;width:130px"
                    alt="2"
                  />
                </div>
              </div>
            <div class="row pt-3 justify-content-center">
              <div class="col-lg-12 col-md-6 col-sm-6">
                <h4 class="text-center fw-bold">Forget Password</h4>
              </div>
            </div>
              <div class="row">
                <div class="col-lg-12 col-md-6 col-sm-6">
                  <label for="username" class="user_id">Enter Username (Matric Number/Staff ID)</label>
                  <p>
                    <input
                    id="username"
                      type="text"
                      placeholder="e.g ND/21/COM/FT/000"
                      class=" form-control p-2 shadow-none"
                      
                    />
                  </p>
                </div>
               
              </div>
              <div class="row">
                <div class="col-lg-12 mt-4">
                  <button onclick="resetPassword()" class="btn_col btn btn-block">
                    Reset
                  </button>
                </div>
              </div>
            </div>
        </div>
    </section>

 
    <script src="../js/popper1.min.js"></script>
    <script src="../js/corass-auth.js"></script>
    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="../js/jquery1-3.4.1.min.js"></script>
    <script src="../js/toastr.min.js"></script>
    <script>
       function resetPassword(){
        const username = document.getElementById("username").value;
        if(!username){
          toastr.options.progressBar = true;
            toastr.error(
             "Username can not be empty",
              "ERROR", {
                timeOut: 9000
              }
            );
            return
        }
        
        jQuery.ajax({
          url: `/user/forgotpassword`,
          method: 'POST',
          data: {
            username,
          },
          error: function (request, error) {
            console.log(error)
            toastr.options.progressBar = true;
            toastr.error(
              "Account not found, Please ensure an email is linked to your account",
              "ERROR", {
                timeOut: 9000
              }
            );
            
          },
          success: function (data) {
            if (data.success === true) {
              alert("Your password has been sent to you mail")
              toastr.options.progressBar = true;
              toastr.success(
                data.message,
                "SUCCESS", {
                  timeOut: 9000
                }
              );
              window.location.href = "/student-login"
            }

          }
        });
       }
    </script>
</body>
</html>