Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('sys_run_app') OR exit('403 You dont have permission to access / on this server...'); ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Example Forgot Password | Tutorial Garuda Framework Pro</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <?= _importJQuery(); ?>
- <?= _importBootstrap(); ?>
- <?= _importGF(); ?>
- <?= _importSweetAlert(); ?>
- <body>
- <div class="container">
- <hr>
- <center><h2>Forgot Password</h2></center>
- <hr>
- <div class="well well-sm">
- <center> <a href="./login">LOGIN</a></center>
- </div>
- </div>
- <div class="container">
- <div class="jumbotron">
- <div id="my_alert"></div>
- <input type="text" id="txt_email" class="form-control" name="" placeholder="Email..." required="">
- <hr>
- <input type="password" id="txt_old_pass" class="form-control" name="" placeholder="Old Password..." required=""></br>
- <input type="password" id="txt_pass" class="form-control" name="" placeholder="New Password..." required="">
- <hr>
- <div class="panel panel-primary">
- <div class="panel-heading">Enter Captcha !</div>
- <div class="panel-body">
- <img src="" alt="Captcha Image" id="img_captcha" class="img-thumbnail">  
- <button id="btn_refresh_captcha" class="btn btn-default btn-xs">Refresh</button>
- </br></br>
- <input type="text" class="form-control" placeholder="Enter Captcha" name="" id="txt_captcha" maxlength="5">
- </div>
- </div>
- <hr>
- <button id="btn_reset" class="btn btn-danger">Reset Password</button>
- </div>
- </div>
- <script type="text/javascript">
- $(document).ready(function(){
- let captcha;
- function refreshCaptcha()
- {
- // Ini ajax Garuda Javascript, tanpa GET ataupun POST
- _loadDoc("./refresh-captcha",function(){
- // menangkap session captcha dari PHP ke variabel Javascript
- captcha = "<?= $_SESSION['my_captcha']['image_src'] ?? false ?>";
- // check jika captcha tidak sama dengan false, maka
- if (captcha != false)
- {
- // masukkan ke image
- _setImage("img_captcha",captcha);
- }
- });
- }
- refreshCaptcha();
- // membuat fokus ke input txt_email
- _focus("txt_email");
- // mendaftarkan event onclick btn_reset
- _onClick("btn_reset",function(){
- resetPassword();
- });
- _onClick("btn_refresh_captcha",refreshCaptcha);
- // function resetPassword
- function resetPassword()
- {
- let email = _getValById("txt_email");
- let get_captcha = _getValById('txt_captcha');
- let new_pass = _getValById("txt_pass");
- let old_pass = _getValById("txt_old_pass");
- const token = _randomStr(5);
- if (email==='')
- {
- _writeAlert("my_alert","Upzz you have to type the email !","warning");
- _focus("txt_email");
- return;
- }
- if (_checkEmail(email))
- {
- if (old_pass==='')
- {
- _focus("txt_old_pass");
- _writeAlert("my_alert","Upzz you have to type the old password !","warning");
- return;
- }
- if (new_pass==='')
- {
- _focus("txt_pass");
- _writeAlert("my_alert","Upzz you have to type the new password !","warning");
- return;
- }
- if (get_captcha==='')
- {
- _focus("txt_captcha");
- _writeAlert("my_alert","Upzz you have to type the captcha !","warning");
- return;
- }
- _printTo("my_alert","");
- btn_reset.disabled=true;
- // Ini ajax dengan POST Garuda Javascript
- _requestPOST("./process-reset-password","token="+token
- +"&email="+email
- +"&captcha="+get_captcha
- +"&new_pass="+new_pass
- +"&old_pass="+old_pass,function(res){
- if (res)
- {
- const obj = JSON.parse(res);
- if (obj)
- {
- let result = obj.result;
- if (result==='W')
- {
- swal("Upzz !","Captcha is wrong !","error");
- _focus("txt_captcha");
- // karena captcha salah, maka refresh captcha
- refreshCaptcha();
- }
- else if (result==='F')
- {
- swal("Upzz !","Email is wrong !","error");
- _focus("txt_email");
- }
- else if (result==='T')
- {
- swal("Success ! ","Your password has been reset ! New Password { "+ new_pass + " }","success");
- // ini untuk menghapus input value
- _clear("txt_email");
- _clear("txt_pass");
- _clear("txt_captcha");
- _clear("txt_old_pass");
- }
- else if (result==='OLDPASS')
- {
- swal("Upzz !","Old Password is wrong !","error");
- _focus("txt_old_pass");
- }
- btn_reset.disabled=false;
- }
- }
- });
- }
- else
- {
- _writeAlert("my_alert","Upzz your email is not valid !","danger");
- _focus("txt_email");
- return;
- }
- }
- // ini untuk custom keyboard saat menekan tombol INSERT
- _keyCustom(function(){
- resetPassword();
- },_keyCode.insert);
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement