Advertisement
pbowers

UserSpice: login.php - allow redirect to referring page

Sep 19th, 2016
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 KB | None | 0 0
  1. <?php
  2. /*
  3. UserSpice 4
  4. An Open Source PHP User Management System
  5. by the UserSpice Team at http://UserSpice.com
  6.  
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. // error_reporting(E_ALL);
  21. // ini_set('display_errors', 1);
  22. ini_set("allow_url_fopen", 1);
  23. ?>
  24. <?php require_once 'init.php'; ?>
  25. <?php require_once $abs_us_root.$us_url_root.'users/includes/header.php'; ?>
  26. <?php require_once $abs_us_root.$us_url_root.'users/includes/navigation.php'; ?>
  27. <?php
  28. $settingsQ = $db->query("SELECT * FROM settings");
  29. $settings = $settingsQ->first();
  30. $error_message = '';
  31. if (@$_REQUEST['err']) $error_message = $_REQUEST['err']; // allow redirects to display a message
  32. $reCaptchaValid=FALSE;
  33.  
  34. if (Input::exists()) {
  35.     $token = Input::get('csrf');
  36.     if(!Token::check($token)){
  37.         die('Token doesn\'t match!');
  38.     }
  39.     //Check to see if recaptcha is enabled
  40.     if($settings->recaptcha == 1){
  41.         require_once 'includes/recaptcha.config.php';
  42.  
  43.         //reCAPTCHA 2.0 check
  44.         $response = null;
  45.  
  46.         // check secret key
  47.         $reCaptcha = new ReCaptcha($privatekey);
  48.  
  49.         // if submitted check response
  50.         if ($_POST["g-recaptcha-response"]) {
  51.             $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"],$_POST["g-recaptcha-response"]);
  52.         }
  53.         if ($response != null && $response->success) {
  54.             $reCaptchaValid=TRUE;
  55.  
  56.         }else{
  57.             $reCaptchaValid=FALSE;
  58.             $error_message .= 'Please check the reCaptcha.';
  59.         }
  60.     }else{
  61.         $reCaptchaValid=TRUE;
  62.     }
  63.  
  64.     if($reCaptchaValid || $settings->recaptcha == 0){ //if recaptcha valid or recaptcha disabled
  65.  
  66.         $validate = new Validate();
  67.         $validation = $validate->check($_POST, array(
  68.             'username' => array('display' => 'Username','required' => true),
  69.             'password' => array('display' => 'Password', 'required' => true)));
  70.  
  71.         if ($validation->passed()) {
  72.             //Log user in
  73.  
  74.             $remember = (Input::get('remember') === 'on') ? true : false;
  75.             $user = new User();
  76.             $login = $user->loginEmail(Input::get('username'), trim(Input::get('password')), $remember);
  77.             if ($login) {
  78.                 if(file_exists($abs_us_root.$us_url_root.'usersc/scripts/custom_login_script.php')){
  79.                     # Note that the custom_login_script often contains a Redirect::to() call
  80.                     require_once $abs_us_root.$us_url_root.'usersc/scripts/custom_login_script.php';
  81.                 }else{
  82.                     var_dump($_POST);
  83.                     if (($dest = Input::get('afterLoginGoto')) ||
  84.                             ($dest = Config::get('homepage')) ||
  85.                             ($dest = 'account.php')) {
  86.                         Redirect::to($dest);
  87.                     }
  88.                 }
  89.             } else {
  90.                 $error_message .= 'Log in failed. Please check your username and password and try again.';
  91.             }
  92.         } else{
  93.             $error_message .= '<ul>';
  94.             foreach ($validation->errors() as $error) {
  95.                 $error_message .= '<li>' . $error . '</li>';
  96.             }
  97.             $error_message .= '</ul>';
  98.         }
  99.     }
  100. }
  101.  
  102. ?>
  103.  
  104. <div id="page-wrapper">
  105. <div class="container">
  106. <div class="row">
  107.     <div class="col-xs-12">
  108.     <div class="bg-danger"><?=$error_message;?></div>
  109.     <form name="login" class="form-signin" action="login.php" method="post">
  110.     <h2 class="form-signin-heading"></i> <?=lang("SIGNIN_TITLE","");?></h2>
  111.     <input type="hidden" name="afterLoginGoto" value="<?= @$_REQUEST['afterLoginGoto'] ?>" />
  112.  
  113.     <div class="form-group">
  114.         <label for="username" >Username OR Email</label>
  115.         <input  class="form-control" type="text" name="username" id="username" placeholder="Username/Email" required autofocus>
  116.     </div>
  117.  
  118.     <div class="form-group">
  119.         <label for="password">Password</label>
  120.         <input type="password" class="form-control"  name="password" id="password"  placeholder="Password" required autocomplete="off">
  121.     </div>
  122.  
  123.     <?php
  124.     if($settings->recaptcha == 1){
  125.     ?>
  126.     <div class="form-group">
  127.     <label>Please check the box below to continue</label>
  128.     <div class="g-recaptcha" data-sitekey="<?=$publickey; ?>"></div>
  129.     </div>
  130.     <?php } ?>
  131.  
  132.     <div class="form-group">
  133.     <label for="remember">
  134.     <input type="checkbox" name="remember" id="remember" > Remember Me</label>
  135.     </div>
  136.  
  137.     <input type="hidden" name="csrf" value="<?=Token::generate(); ?>">
  138.     <button class="submit  btn  btn-primary" type="submit"><i class="fa fa-sign-in"></i> <?=lang("SIGNIN_BUTTONTEXT","");?></button>
  139.  
  140.     </form>
  141.     </div>
  142. </div>
  143. <div class="row">
  144.     <div class="col-xs-6"><br>
  145.         <a class="pull-left" href='forgot_password.php'><i class="fa fa-wrench"></i> Forgot Password</a><br><br>
  146.     </div>
  147.     <div class="col-xs-6"><br>
  148.         <a class="pull-right" href='join.php'><i class="fa fa-plus-square"></i> <?=lang("SIGNUP_TEXT","");?></a><br><br>
  149.     </div>
  150. </div>
  151. </div>
  152. </div>
  153.  
  154.     <!-- footers -->
  155. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  156.  
  157.     <!-- Place any per-page javascript here -->
  158.  
  159. <?php   if($settings->recaptcha == 1){ ?>
  160. <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  161. <?php } ?>
  162. <?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement