Advertisement
lamhottt

forgot.php

Aug 26th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.31 KB | None | 0 0
  1. <?php defined('sys_run_app') OR exit('403 You dont have permission to access / on this server...'); ?>
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6.     <title>Example Forgot Password | Tutorial Garuda Framework Pro</title>
  7.     <meta name="viewport" content="width=device-width, initial-scale=1">
  8. </head>
  9.     <?= _importJQuery(); ?>
  10.     <?= _importBootstrap(); ?>
  11.     <?= _importGF(); ?>
  12.     <?= _importSweetAlert(); ?>
  13. <body>
  14.    
  15.     <div class="container">
  16.       <hr>
  17.       <center><h2>Forgot Password</h2></center>
  18.        <hr>
  19.       <div class="well well-sm">
  20.             <center> <a href="./login">LOGIN</a></center>
  21.       </div>
  22.      
  23.     </div>
  24.  
  25.     <div class="container">
  26.        
  27.         <div class="jumbotron">
  28.                 <div id="my_alert"></div>
  29.                 <input type="text" id="txt_email" class="form-control" name="" placeholder="Email..." required="">
  30.                 <hr>
  31.                 <input type="password" id="txt_old_pass" class="form-control" name="" placeholder="Old Password..." required=""></br>
  32.                 <input type="password" id="txt_pass" class="form-control" name="" placeholder="New Password..." required="">
  33.                 <hr>
  34.                 <div class="panel panel-primary">
  35.                   <div class="panel-heading">Enter Captcha !</div>
  36.                       <div class="panel-body">
  37.                         <img src="" alt="Captcha Image" id="img_captcha" class="img-thumbnail"> &nbsp
  38.                         <button id="btn_refresh_captcha" class="btn btn-default btn-xs">Refresh</button>
  39.                         </br></br>
  40.                         <input type="text" class="form-control" placeholder="Enter Captcha" name="" id="txt_captcha" maxlength="5">
  41.                       </div>
  42.                 </div>
  43.                 <hr>
  44.  
  45.                 <button id="btn_reset" class="btn btn-danger">Reset Password</button>
  46.         </div>
  47.  
  48.     </div>
  49.  
  50.  
  51.     <script type="text/javascript">
  52.         $(document).ready(function(){
  53.                 let captcha;
  54.                 function refreshCaptcha()
  55.                 {  
  56.                     // Ini ajax Garuda Javascript, tanpa GET ataupun POST
  57.                     _loadDoc("./refresh-captcha",function(){
  58.                         // menangkap session captcha dari PHP ke variabel Javascript
  59.                         captcha = "<?= $_SESSION['my_captcha']['image_src'] ?? false ?>";
  60.                         // check jika captcha tidak sama dengan false, maka
  61.                         if (captcha != false)
  62.                         {
  63.                             // masukkan ke image
  64.                             _setImage("img_captcha",captcha);
  65.                         }
  66.                     });
  67.                 }
  68.                
  69.                 refreshCaptcha();
  70.                
  71.                 // membuat fokus ke input txt_email
  72.                 _focus("txt_email");   
  73.  
  74.                 // mendaftarkan event onclick btn_reset
  75.                 _onClick("btn_reset",function(){
  76.                     resetPassword();
  77.                 });
  78.  
  79.  
  80.  
  81.                 _onClick("btn_refresh_captcha",refreshCaptcha);
  82.                
  83.                 // function resetPassword
  84.                 function resetPassword()
  85.                 {
  86.                     let email       = _getValById("txt_email");
  87.                     let get_captcha = _getValById('txt_captcha');
  88.                     let new_pass    = _getValById("txt_pass");
  89.                     let old_pass    = _getValById("txt_old_pass");
  90.                     const token     = _randomStr(5);
  91.  
  92.                     if (email==='')
  93.                     {
  94.                         _writeAlert("my_alert","Upzz you have to type the email !","warning");
  95.                         _focus("txt_email");
  96.                         return;
  97.                     }
  98.  
  99.                     if (_checkEmail(email))
  100.                     {
  101.                         if (old_pass==='')
  102.                         {
  103.                             _focus("txt_old_pass");
  104.                             _writeAlert("my_alert","Upzz you have to type the old password !","warning");
  105.                             return;
  106.                         }
  107.                         if (new_pass==='')
  108.                         {
  109.                             _focus("txt_pass");
  110.                             _writeAlert("my_alert","Upzz you have to type the new password !","warning");
  111.                             return;
  112.                         }
  113.                         if (get_captcha==='')
  114.                         {
  115.                             _focus("txt_captcha");
  116.                             _writeAlert("my_alert","Upzz you have to type the captcha !","warning");
  117.                             return;
  118.                         }
  119.                        
  120.                         _printTo("my_alert","");
  121.                         btn_reset.disabled=true;
  122.                        
  123.                         // Ini ajax dengan POST Garuda Javascript
  124.                         _requestPOST("./process-reset-password","token="+token
  125.                                                                 +"&email="+email
  126.                                                                 +"&captcha="+get_captcha
  127.                                                                 +"&new_pass="+new_pass
  128.                                                                 +"&old_pass="+old_pass,function(res){
  129.                                
  130.                                 if (res)
  131.                                 {
  132.                                     const obj = JSON.parse(res);
  133.                                     if (obj)
  134.                                     {
  135.                                         let result = obj.result;
  136.  
  137.                                         if (result==='W')
  138.                                         {
  139.                                             swal("Upzz !","Captcha is wrong !","error");
  140.                                             _focus("txt_captcha");
  141.                                             // karena  captcha salah, maka refresh captcha
  142.                                             refreshCaptcha();
  143.                                         }
  144.                                         else if (result==='F')
  145.                                         {
  146.                                             swal("Upzz !","Email is wrong !","error");
  147.                                             _focus("txt_email");
  148.                                         }
  149.                                         else if (result==='T')
  150.                                         {
  151.                                             swal("Success ! ","Your password has been reset ! New Password { "+ new_pass + " }","success");
  152.  
  153.                                             // ini untuk menghapus input value
  154.                                             _clear("txt_email");
  155.                                             _clear("txt_pass");
  156.                                             _clear("txt_captcha");
  157.                                             _clear("txt_old_pass");
  158.                                         }
  159.                                         else if (result==='OLDPASS')
  160.                                         {
  161.                                             swal("Upzz !","Old Password is wrong !","error");
  162.                                             _focus("txt_old_pass");
  163.                                         }
  164.                                         btn_reset.disabled=false;
  165.                                     }
  166.                                 }
  167.                         });
  168.                     }
  169.                     else
  170.                     {
  171.                         _writeAlert("my_alert","Upzz your email is not valid !","danger");
  172.                         _focus("txt_email");
  173.                         return;
  174.                     }
  175.  
  176.                
  177.                 }
  178.  
  179.                 // ini untuk custom keyboard saat menekan tombol INSERT
  180.                 _keyCustom(function(){
  181.                     resetPassword();
  182.                 },_keyCode.insert);
  183.                
  184.         });
  185.        
  186.     </script>
  187.  
  188. </body>
  189. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement