<?php
session_start();
    include 'lib/dbcon.php';
    include 'lib/functions.php';

    if (isset($_REQUEST['username']) && isset($_REQUEST['token'])) {

        $msg_u = $_REQUEST['username'];
        $msg_t = $_REQUEST['token'];
    }
    else {
        //header("Location: forgot.php");
    }
?>

<!DOCTYPE html>
<html>

<head>
 
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" name="viewport">
  <title>Login</title>
  <!-- General CSS Files -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

  
  
  <!-- Custom style CSS -->
  <link rel='shortcut icon' type='image/x-icon' href='assets/images/logo.jpeg' />
<link rel="stylesheet" href="assets/css/app.min.css">
  <link rel="stylesheet" href="assets/bundles/bootstrap-social/bootstrap-social.css">
  <!-- Template CSS -->
  <link rel="stylesheet" href="assets/css/style.css">
  <link rel="stylesheet" href="assets/css/components.css">
  <!-- Custom style CSS -->
  <link rel='shortcut icon' type='image/x-icon' href='assets/img/a-logo.png' />

  <!-- General JS Scripts -->
  <script src="assets/js/app.min.js"></script>

  <!-- General JS Scripts -->
 

  <style>
  
 </style>
</head>
    
<body class="background-image-body">
    
   <div class="container mt-5">
        <div class="row">
          <div class="col-12 col-sm-8 offset-sm-2 col-md-6 offset-md-3 col-lg-6 offset-lg-3 col-xl-4 offset-xl-4">
            <div class="login-brand login-brand-color">
                <img alt="image" src="assets/img/a-logo.png" style="width: 300px; height: 55px; object-fit: contain;" />
            </div>
            <div class="card card-auth">
              <div class="card-header card-header-auth">
                <h4>UPDATE PASSWORD</h4>
              </div>
              <div class="card-body">
              <!--   <?php //if (isset($msg_err)): ?>
                    <?php //echo $msg_err; ?>
                <?php //endif ?> -->
           <?php if (isset($_SESSION['msg_scs'])): ?>
            <p class="alert alert-success"><?= $_SESSION['msg_scs'];?><a href="index.php">login here</a></p>
          <?php endif ?>
          <?php unset($_SESSION['msg_scs']);?>
         
          <?php if (isset($_SESSION['msg_err'])): ?>
            <p class="alert alert-danger"><?= $_SESSION['msg_err'];?></p>
          <?php endif ?>
          <?php unset($_SESSION['msg_err']);?>
                                <form method="POST" action="password_update.php">

                                <div class="form-group">
                                    <label for="password">New Password</label>
                                    <input id="password" type="password" class="form-control pwstrength" data-indicator="pwindicator"
                                           name="password" tabindex="2" required>
                                    <div id="pwindicator" class="pwindicator">
                                        <div class="bar"></div>
                                        <div class="label"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="password-confirm">Confirm Password</label>
                                    <input id="password_confirm" type="password" class="form-control" name="password_confirm"
                                           tabindex="2" required>
                                </div>
                                <div class="form-group">
                                    <input type="hidden" name="user" id="user" value="<?= $msg_u; ?>">
                                    <input type="hidden" name="token" id="token" value="<?= $msg_t; ?>">
                                    
                                    <button type="submit" name="rp" id="rp" class="btn btn-danger btn-lg btn-block" tabindex="4">
                                        Reset Password
                                    </button>
                                </div>
                            </form>
                                
                            </div>                      
                        </div>
<script>
    $(document).ready(function(){
        $('#reset-password-form').on('submit', function(e){
            e.preventDefault();
            var pass = $('#password');
            var c_pass = $('#password_confirm');
            var user = $('#user');
            var token = $('#token')
            var action = $('#action');

            if (pass.val() == '') {
                pass.css('border', '1px solid red');
                alert("Required Password");
            }
            else if (c_pass.val() == '') {
                c_pass.css('border', '1px solid red');
                alert("Required Confirm Password");
            }
            else if (pass.val()!=c_pass.val()) {
                c_pass.css('border', '1px solid red');
                alert("Password Not Matched");
            }
            else {
                //alert("LOoks Good");
                $.ajax({
                    url:'reset-password-query.php',
                    type:'POST',
                    data:$('#reset-password-form').serialize(),
                    beforeSend:function(){
                        $('#rp').html('Updating your password.......');
                    },
                    success:function(data){
                        $('#reset-password-form')[0].reset();
                        $('.text-muted').html(data);
                        $('#rp').html('Reset Password');

                    }
                });
            }

        });
    });
</script>

                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- Vendor JS -->
    
        

</body>

</html>
