Advertisement
pbowers

UserSpice: login.php - allow error message in redirect

Sep 7th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.22 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.  
  40.     //Check to see if recaptcha is enabled
  41.     if($settings->recaptcha == 1){
  42.         require_once 'includes/recaptcha.config.php';
  43.  
  44.         //reCAPTCHA 2.0 check
  45.         $response = null;
  46.  
  47.         // check secret key
  48.         $reCaptcha = new ReCaptcha($privatekey);
  49.  
  50.         // if submitted check response
  51.         if ($_POST["g-recaptcha-response"]) {
  52.             $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"],$_POST["g-recaptcha-response"]);
  53.         }
  54.         if ($response != null && $response->success) {
  55.             $reCaptchaValid=TRUE;
  56.  
  57.         }else{
  58.             $reCaptchaValid=FALSE;
  59.             $error_message .= 'Please check the reCaptcha.';
  60.         }
  61.     }else{
  62.         $reCaptchaValid=TRUE;
  63.     }
  64.  
  65.     if($reCaptchaValid || $settings->recaptcha == 0){ //if recaptcha valid or recaptcha disabled
  66.  
  67.         $validate = new Validate();
  68.         $validation = $validate->check($_POST, array('username' => array('display' => 'Username','required' => true),'password' => array('display' => 'Password', 'required' => true)));
  69.  
  70.         if ($validation->passed()) {
  71.             //Log user in
  72.  
  73.             $remember = (Input::get('remember') === 'on') ? true : false;
  74.             $user = new User();
  75.             $login = $user->loginEmail(Input::get('username'), trim(Input::get('password')), $remember);
  76.             if ($login) {
  77.                 if(file_exists($abs_us_root.$us_url_root.'usersc/scripts/custom_login_script.php')){
  78.                     require_once $abs_us_root.$us_url_root.'usersc/scripts/custom_login_script.php';
  79.                 }else{
  80.                     //Feel free to change where the user goes after login!
  81.                     Redirect::to('account.php');
  82.                 }
  83.             } else {
  84.                 $error_message .= 'Log in failed. Please check your username and password and try again.';
  85.             }
  86.         } else{
  87.             $error_message .= '<ul>';
  88.             foreach ($validation->errors() as $error) {
  89.                 $error_message .= '<li>' . $error . '</li>';
  90.             }
  91.             $error_message .= '</ul>';
  92.         }
  93.     }
  94. }
  95.  
  96. ?>
  97.  
  98. <div id="page-wrapper">
  99. <div class="container">
  100. <div class="row">
  101.     <div class="col-xs-12">
  102.     <div class="bg-danger"><?=$error_message;?></div>
  103.     <form name="login" class="form-signin" action="login.php" method="post">
  104.     <h2 class="form-signin-heading"></i> <?=lang("SIGNIN_TITLE","");?></h2>
  105.  
  106.     <div class="form-group">
  107.         <label for="username" >Username OR Email</label>
  108.         <input  class="form-control" type="text" name="username" id="username" placeholder="Username/Email" required autofocus>
  109.     </div>
  110.  
  111.     <div class="form-group">
  112.         <label for="password">Password</label>
  113.         <input type="password" class="form-control"  name="password" id="password"  placeholder="Password" required autocomplete="off">
  114.     </div>
  115.  
  116.     <?php
  117.     if($settings->recaptcha == 1){
  118.     ?>
  119.     <div class="form-group">
  120.     <label>Please check the box below to continue</label>
  121.     <div class="g-recaptcha" data-sitekey="<?=$publickey; ?>"></div>
  122.     </div>
  123.     <?php } ?>
  124.  
  125.     <div class="form-group">
  126.     <label for="remember">
  127.     <input type="checkbox" name="remember" id="remember" > Remember Me</label>
  128.     </div>
  129.  
  130.     <input type="hidden" name="csrf" value="<?=Token::generate(); ?>">
  131.     <button class="submit  btn  btn-primary" type="submit"><i class="fa fa-sign-in"></i> <?=lang("SIGNIN_BUTTONTEXT","");?></button>
  132.  
  133.     </form>
  134.     </div>
  135. </div>
  136. <div class="row">
  137.     <div class="col-xs-6"><br>
  138.         <a class="pull-left" href='forgot_password.php'><i class="fa fa-wrench"></i> Forgot Password</a><br><br>
  139.     </div>
  140.     <div class="col-xs-6"><br>
  141.         <a class="pull-right" href='join.php'><i class="fa fa-plus-square"></i> <?=lang("SIGNUP_TEXT","");?></a><br><br>
  142.     </div>
  143. </div>
  144. </div>
  145. </div>
  146.  
  147.     <!-- footers -->
  148. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  149.  
  150.     <!-- Place any per-page javascript here -->
  151.  
  152. <?php   if($settings->recaptcha == 1){ ?>
  153. <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  154. <?php } ?>
  155. <?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