Advertisement
Guest User

login.php

a guest
Apr 21st, 2017
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.13 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. if(isset($_SESSION)){session_destroy();}
  24. ?>
  25. <?php require_once $_SERVER['DOCUMENT_ROOT'].'/users/init.php'; ?>
  26. <?php require_once $abs_us_root.$us_url_root.'users/includes/header.php'; ?>
  27. <?php require_once $abs_us_root.$us_url_root.'users/includes/navigation.php'; ?>
  28.  
  29.  
  30. <!--    LOGIN PHP   -->
  31. <?php
  32. $settingsQ = $db->query("SELECT * FROM settings");
  33. $settings = $settingsQ->first();
  34. $error_message = '';
  35. if (@$_REQUEST['err']) $error_message = $_REQUEST['err']; // allow redirects to display a message
  36. $reCaptchaValid=FALSE;
  37.  
  38. if (Input::exists()) {
  39.     $token = Input::get('csrf');
  40.     if(!Token::check($token)){
  41.         //die('Token doesn\'t match! login.php');
  42.     }
  43.     //Check to see if recaptcha is enabled
  44.     if($settings->recaptcha == 1){
  45.         require_once $abs_us_root.$us_url_root.'/includes/recaptcha.config.php';
  46.  
  47.         //reCAPTCHA 2.0 check
  48.         $response = null;
  49.  
  50.         // check secret key
  51.         $reCaptcha = new ReCaptcha($privatekey);
  52.  
  53.         // if submitted check response
  54.         if ($_POST["g-recaptcha-response"]) {
  55.             $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"],$_POST["g-recaptcha-response"]);
  56.         }
  57.         if ($response != null && $response->success) {
  58.             $reCaptchaValid=TRUE;
  59.  
  60.         }else{
  61.             $reCaptchaValid=FALSE;
  62.             $error_message .= 'Please check the reCaptcha.';
  63.         }
  64.     }else{
  65.         $reCaptchaValid=TRUE;
  66.     }
  67.  
  68.     if($reCaptchaValid || $settings->recaptcha == 0){ //if recaptcha valid or recaptcha disabled
  69.  
  70.         $validate = new Validate();
  71.         $validation = $validate->check($_POST, array(
  72.             'username' => array('display' => 'Username','required' => true),
  73.             'password' => array('display' => 'Password', 'required' => true)));
  74.  
  75.         if ($validation->passed()) {
  76.             //Log user in
  77.  
  78.             $remember = (Input::get('remember') === 'on') ? true : false;
  79.             $user = new User();
  80.             $login = $user->loginEmail(Input::get('username'), trim(Input::get('password')), $remember);
  81.             if ($login) {
  82.                 # if user was attempting to get to a page before login, go there
  83.                 if ($dest = sanitizedDest('dest')) {
  84.                     Redirect::to($dest);
  85.                 } elseif (file_exists($abs_us_root.$us_url_root.'usersc/scripts/custom_login_script.php')) {
  86.                     # if site has custom login script, use it
  87.                     # Note that the custom_login_script.php normally contains a Redirect::to() call
  88.                     require_once $abs_us_root.$us_url_root.'usersc/scripts/custom_login_script.php';
  89.                 } else {
  90.                     if (($dest = Config::get('homepage')) ||
  91.                             ($dest = 'account.php')) {
  92.                         #echo "DEBUG: dest=$dest<br />\n";
  93.                         #die;
  94.                         Redirect::to($dest);
  95.                     }
  96.                 }
  97.             } else {
  98.                 $error_message .= 'Log in failed. Please check your username and password and try again.';
  99.             }
  100.         } else{
  101.             $error_message .= '<ul>';
  102.             foreach ($validation->errors() as $error) {
  103.                 $error_message .= '<li>' . $error . '</li>';
  104.             }
  105.             $error_message .= '</ul>';
  106.         }
  107.     }
  108. }
  109. if (!$dest = sanitizedDest('dest')) {
  110.   $dest = '';
  111. }
  112. ?>
  113.  
  114. <!--    REGISTER PHP    -->
  115. <?php
  116. $settingsQ = $db->query("SELECT * FROM settings");
  117. $settings = $settingsQ->first();
  118. if($settings->recaptcha == 1 || $settings->recaptcha == 2){
  119.     require_once $abs_us_root.$us_url_root.'users/includes/recaptcha.config.php';
  120. }
  121. //There is a lot of commented out code for a future release of sign ups with payments
  122. $form_method = 'POST';
  123. $form_action = 'login.php';
  124. $vericode = rand(100000,999999);
  125.  
  126. $form_valid=FALSE;
  127.  
  128. //Decide whether or not to use email activation
  129. $query = $db->query("SELECT * FROM email");
  130. $results = $query->first();
  131. $act = $results->email_act;
  132.  
  133. //Opposite Day for Pre-Activation - Basically if you say in email
  134. //settings that you do NOT want email activation, this lists new
  135. //users as active in the database, otherwise they will become
  136. //active after verifying their email.
  137. if($act==1){
  138.     $pre = 0;
  139. } else {
  140.     $pre = 1;
  141. }
  142.  
  143. /*$token = Input::get('csrf');
  144. if(Input::exists()){
  145.     if(!Token::check($token)){
  146.         die('Token doesn\'t match! register.php');
  147.     }
  148. }*/
  149.  
  150. $reCaptchaValid=FALSE;
  151.  
  152. if(Input::exists()){
  153.  
  154.     $username = Input::get('username');
  155.     $fname = Input::get('fname');
  156.     $lname = Input::get('lname');
  157.     $email = Input::get('email');
  158.     $agreement_checkbox = Input::get('agreement_checkbox');
  159.  
  160.     if ($agreement_checkbox=='on'){
  161.         $agreement_checkbox=TRUE;
  162.     }else{
  163.         $agreement_checkbox=FALSE;
  164.     }
  165.  
  166.     $db = DB::getInstance();
  167.     $settingsQ = $db->query("SELECT * FROM settings");
  168.     $settings = $settingsQ->first();
  169.     $validation = new Validate();
  170.     $validation->check($_POST,array(
  171.       'username' => array(
  172.         'display' => 'Username',
  173.         'required' => true,
  174.         'min' => $settings->min_un,
  175.         'max' => $settings->max_un,
  176.         'unique' => 'users',
  177.       ),
  178.       'fname' => array(
  179.         'display' => 'First Name',
  180.         'required' => true,
  181.         'min' => 2,
  182.         'max' => 35,
  183.       ),
  184.       'lname' => array(
  185.         'display' => 'Last Name',
  186.         'required' => true,
  187.         'min' => 2,
  188.         'max' => 35,
  189.       ),
  190.       'email' => array(
  191.         'display' => 'Email',
  192.         'required' => true,
  193.         'valid_email' => true,
  194.         'unique' => 'users',
  195.       ),
  196.  
  197.       'password' => array(
  198.         'display' => 'Password',
  199.         'required' => true,
  200.         'min' => $settings->min_pw,
  201.         'max' => $settings->max_pw,
  202.       ),
  203.       'confirm' => array(
  204.         'display' => 'Confirm Password',
  205.         'required' => true,
  206.         'matches' => 'password',
  207.       ),
  208.     ));
  209.  
  210.     //if the agreement_checkbox is not checked, add error
  211.     if (!$agreement_checkbox){
  212.         $validation->addError(["Please read and accept terms and conditions"]);
  213.     }
  214.  
  215.     if($validation->passed() && $agreement_checkbox){
  216.         //Logic if ReCAPTCHA is turned ON
  217.     if($settings->recaptcha == 1 || $settings->recaptcha == 2){
  218.             require_once $abs_us_root.$us_url_root.'users/includes/recaptcha.config.php';
  219.             //reCAPTCHA 2.0 check
  220.             $response = null;
  221.  
  222.             // check secret key
  223.             $reCaptcha = new ReCaptcha($privatekey);
  224.  
  225.             // if submitted check response
  226.             if ($_POST["g-recaptcha-response"]) {
  227.                 $response = $reCaptcha->verifyResponse(
  228.                     $_SERVER["REMOTE_ADDR"],
  229.                     $_POST["g-recaptcha-response"]);
  230.             }
  231.             if ($response != null && $response->success) {
  232.                 // account creation code goes here
  233.                 $reCaptchaValid=TRUE;
  234.                 $form_valid=TRUE;
  235.             }else{
  236.                 $reCaptchaValid=FALSE;
  237.                 $form_valid=FALSE;
  238.                 $validation->addError(["Please check the reCaptcha box."]);
  239.             }
  240.  
  241.         } //else for recaptcha
  242.  
  243.         if($reCaptchaValid || $settings->recaptcha == 0){
  244.  
  245.             //add user to the database
  246.             $user = new User();
  247.             $join_date = date("Y-m-d H:i:s");
  248.             $params = array(
  249.                 'fname' => Input::get('fname'),
  250.                 'email' => $email,
  251.                 'vericode' => $vericode,
  252.             );
  253.  
  254.             if($act == 1) {
  255.                 //Verify email address settings
  256.                 $to = rawurlencode($email);
  257.                 $subject = 'Welcome to '.$settings->site_name;
  258.                 $body = email_body('_email_template_verify.php',$params);
  259.                 email($to,$subject,$body);
  260.             }
  261.             try {
  262.                 // echo "Trying to create user";
  263.                 $user->create(array(
  264.                     'username' => Input::get('username'),
  265.                     'fname' => Input::get('fname'),
  266.                     'lname' => Input::get('lname'),
  267.                     'email' => Input::get('email'),
  268.                     'password' =>
  269.                     password_hash(Input::get('password'), PASSWORD_BCRYPT, array('cost' => 12)),
  270.                     'permissions' => 1,
  271.                     'account_owner' => 1,
  272.                     'stripe_cust_id' => '',
  273.                     'join_date' => $join_date,
  274.                     'company' => Input::get('company'),
  275.                     'email_verified' => $pre,
  276.                     'active' => 1,
  277.                     'vericode' => $vericode,
  278.                 ));
  279.             } catch (Exception $e) {
  280.                 die($e->getMessage());
  281.             }
  282.             Redirect::to($us_url_root.'users/joinThankYou.php');
  283.         }
  284.  
  285.     } //Validation and agreement checbox
  286. } //Input exists
  287.  
  288. ?>
  289.  
  290. <div id="page-wrapper">
  291.     <div class="container">
  292.         <div class="row">
  293.             <div class="col-md-6">
  294.                 <div class="col-xs-12">
  295.                     <div class="bg-danger"><?=$error_message;?></div>
  296.                     <?php
  297.                         if($settings->glogin==1 && !$user->isLoggedIn()){
  298.                         require_once $abs_us_root.$us_url_root.'users/includes/google_oauth_login.php';
  299.                         }
  300.                         if($settings->fblogin==1 && !$user->isLoggedIn()){
  301.                         require_once $abs_us_root.$us_url_root.'users/includes/facebook_oauth.php';
  302.                         }
  303.                     ?>
  304.                     <form name="login" class="form-signin" action="login.php" method="post">
  305.                         <h3 class="form-signin-heading">OBSTOJEČ UPORABNIK</h3>
  306.                         <br>
  307.                         <input type="hidden" name="dest" value="<?= $dest ?>" />
  308.  
  309.                         <div class="form-group">
  310.                             <input  class="form-control" type="text" name="username" id="username" placeholder="Username/Email" required autofocus>
  311.                         </div>
  312.  
  313.                         <div class="form-group">
  314.                            
  315.                             <input type="password" class="form-control"  name="password" id="password"  placeholder="Password" required autocomplete="off">
  316.                         </div>
  317.  
  318.                         <?php
  319.                         if($settings->recaptcha == 1){
  320.                         ?>
  321.                         <div class="form-group">
  322.                             <label>Please check the box below to continue</label>
  323.                             <div class="g-recaptcha" data-sitekey="<?=$publickey; ?>"></div>
  324.                         </div>
  325.                         <?php } ?>
  326.  
  327.                         <div class="form-group">
  328.                             <label for="remember">
  329.                             <input type="checkbox" name="remember" id="remember" > Remember Me</label>
  330.                         </div>
  331.  
  332.                         <input type="hidden" name="csrf" value="<?=Token::generate(); ?>">
  333.                         <input type="hidden" name="login" value="<?=login ?>">
  334.                         <button class="submit btn btn-success full-width" type="submit">VPIŠI SE</button>
  335.                     </form>
  336.                     <br>
  337.                     <button class="submit btn btn-default full-width" href='forgot_password.php'>Pozabil sem geslo</button>
  338.                    
  339.                     <hr>
  340.                 </div>
  341.             </div>
  342.                    
  343.             <div class="col-md-6 vertical-line">
  344.                 <div class="col-xs-12">
  345.                     <?php
  346.                         if($settings->glogin==1 && !$user->isLoggedIn()){
  347.                             $abs_us_root.$us_url_root.'users/includes/google_oauth_login.php';
  348.                         }
  349.                         if($settings->fblogin==1 && !$user->isLoggedIn()){
  350.                             require_once $abs_us_root.$us_url_root.'users/includes/facebook_oauth.php';
  351.                         }
  352.                         require $abs_us_root.$us_url_root.'usersc/views/_join.php';
  353.                     ?>
  354.                 </div>
  355.             </div>
  356.         </div>
  357.     </div>
  358. </div>
  359.  
  360.     <!-- footers -->
  361. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  362.  
  363.     <!-- Place any per-page javascript here -->
  364.  
  365. <?php   if($settings->recaptcha == 1 || $settings->recaptcha == 2){ ?>
  366. <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  367. <?php } ?>
  368. <?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