Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.59 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.  
  115. <!--    REGISTER PHP    -->
  116. <?php
  117. $settingsQ = $db->query("SELECT * FROM settings");
  118. $settings = $settingsQ->first();
  119. if($settings->recaptcha == 1 || $settings->recaptcha == 2){
  120.     require_once $abs_us_root.$us_url_root.'users/includes/recaptcha.config.php';
  121. }
  122. //There is a lot of commented out code for a future release of sign ups with payments
  123. $form_method = 'POST';
  124. $form_action = 'login.php';
  125. $vericode = rand(100000,999999);
  126.  
  127. $form_valid=FALSE;
  128.  
  129. //Decide whether or not to use email activation
  130. $query = $db->query("SELECT * FROM email");
  131. $results = $query->first();
  132. $act = $results->email_act;
  133.  
  134. //Opposite Day for Pre-Activation - Basically if you say in email
  135. //settings that you do NOT want email activation, this lists new
  136. //users as active in the database, otherwise they will become
  137. //active after verifying their email.
  138. if($act==1){
  139.     $pre = 0;
  140. } else {
  141.     $pre = 1;
  142. }
  143.  
  144. $token = Input::get('csrf');
  145. if(Input::exists()){
  146.     if(!Token::check($token)){
  147.         die('Token doesn\'t match! register.php');
  148.     }
  149. }
  150.  
  151. $reCaptchaValid=FALSE;
  152.  
  153. if(Input::exists()){
  154.  
  155.     $username = Input::get('username');
  156.     $fname = Input::get('fname');
  157.     $lname = Input::get('lname');
  158.     $email = Input::get('email');
  159.     $agreement_checkbox = Input::get('agreement_checkbox');
  160.  
  161.     if ($agreement_checkbox=='on'){
  162.         $agreement_checkbox=TRUE;
  163.     }else{
  164.         $agreement_checkbox=FALSE;
  165.     }
  166.  
  167.     $db = DB::getInstance();
  168.     $settingsQ = $db->query("SELECT * FROM settings");
  169.     $settings = $settingsQ->first();
  170.     $validation = new Validate();
  171.     $validation->check($_POST,array(
  172.       'username' => array(
  173.         'display' => 'Username',
  174.         'required' => true,
  175.         'min' => $settings->min_un,
  176.         'max' => $settings->max_un,
  177.         'unique' => 'users',
  178.       ),
  179.       'fname' => array(
  180.         'display' => 'First Name',
  181.         'required' => true,
  182.         'min' => 2,
  183.         'max' => 35,
  184.       ),
  185.       'lname' => array(
  186.         'display' => 'Last Name',
  187.         'required' => true,
  188.         'min' => 2,
  189.         'max' => 35,
  190.       ),
  191.       'email' => array(
  192.         'display' => 'Email',
  193.         'required' => true,
  194.         'valid_email' => true,
  195.         'unique' => 'users',
  196.       ),
  197.  
  198.       'password' => array(
  199.         'display' => 'Password',
  200.         'required' => true,
  201.         'min' => $settings->min_pw,
  202.         'max' => $settings->max_pw,
  203.       ),
  204.       'confirm' => array(
  205.         'display' => 'Confirm Password',
  206.         'required' => true,
  207.         'matches' => 'password',
  208.       ),
  209.     ));
  210.  
  211.     //if the agreement_checkbox is not checked, add error
  212.     if (!$agreement_checkbox){
  213.         $validation->addError(["Please read and accept terms and conditions"]);
  214.     }
  215.  
  216.     if($validation->passed() && $agreement_checkbox){
  217.         //Logic if ReCAPTCHA is turned ON
  218.     if($settings->recaptcha == 1 || $settings->recaptcha == 2){
  219.             require_once $abs_us_root.$us_url_root.'users/includes/recaptcha.config.php';
  220.             //reCAPTCHA 2.0 check
  221.             $response = null;
  222.  
  223.             // check secret key
  224.             $reCaptcha = new ReCaptcha($privatekey);
  225.  
  226.             // if submitted check response
  227.             if ($_POST["g-recaptcha-response"]) {
  228.                 $response = $reCaptcha->verifyResponse(
  229.                     $_SERVER["REMOTE_ADDR"],
  230.                     $_POST["g-recaptcha-response"]);
  231.             }
  232.             if ($response != null && $response->success) {
  233.                 // account creation code goes here
  234.                 $reCaptchaValid=TRUE;
  235.                 $form_valid=TRUE;
  236.             }else{
  237.                 $reCaptchaValid=FALSE;
  238.                 $form_valid=FALSE;
  239.                 $validation->addError(["Please check the reCaptcha box."]);
  240.             }
  241.  
  242.         } //else for recaptcha
  243.  
  244.         if($reCaptchaValid || $settings->recaptcha == 0){
  245.  
  246.             //add user to the database
  247.             $user = new User();
  248.             $join_date = date("Y-m-d H:i:s");
  249.             $params = array(
  250.                 'fname' => Input::get('fname'),
  251.                 'email' => $email,
  252.                 'vericode' => $vericode,
  253.             );
  254.  
  255.             if($act == 1) {
  256.                 //Verify email address settings
  257.                 $to = rawurlencode($email);
  258.                 $subject = 'Welcome to '.$settings->site_name;
  259.                 $body = email_body('_email_template_verify.php',$params);
  260.                 email($to,$subject,$body);
  261.             }
  262.             try {
  263.                 // echo "Trying to create user";
  264.                 $user->create(array(
  265.                     'username' => Input::get('username'),
  266.                     'fname' => Input::get('fname'),
  267.                     'lname' => Input::get('lname'),
  268.                     'email' => Input::get('email'),
  269.                     'password' =>
  270.                     password_hash(Input::get('password'), PASSWORD_BCRYPT, array('cost' => 12)),
  271.                     'permissions' => 1,
  272.                     'account_owner' => 1,
  273.                     'stripe_cust_id' => '',
  274.                     'join_date' => $join_date,
  275.                     'company' => Input::get('company'),
  276.                     'email_verified' => $pre,
  277.                     'active' => 1,
  278.                     'vericode' => $vericode,
  279.                 ));
  280.             } catch (Exception $e) {
  281.                 die($e->getMessage());
  282.             }
  283.             Redirect::to($us_url_root.'users/joinThankYou.php');
  284.         }
  285.  
  286.     } //Validation and agreement checbox
  287. } //Input exists
  288.  
  289. ?>
  290.  
  291. <div id="page-wrapper">
  292.     <div class="container">
  293.         <div class="row">
  294.             <div class="col-md-6">
  295.                 <div class="col-xs-12">
  296.                     <div class="bg-danger"><?=$error_message;?></div>
  297.                     <?php
  298.                         if($settings->glogin==1 && !$user->isLoggedIn()){
  299.                         require_once $abs_us_root.$us_url_root.'users/includes/google_oauth_login.php';
  300.                         }
  301.                         if($settings->fblogin==1 && !$user->isLoggedIn()){
  302.                         require_once $abs_us_root.$us_url_root.'users/includes/facebook_oauth.php';
  303.                         }
  304.                     ?>
  305.                     <form name="login" class="form-signin" action="login.php" method="post">
  306.                         <h3 class="form-signin-heading">OBSTOJEČ UPORABNIK</h3>
  307.                         <br>
  308.                         <input type="hidden" name="dest" value="<?= $dest ?>" />
  309.  
  310.                         <div class="form-group">
  311.                             <input  class="form-control" type="text" name="username" id="username" placeholder="Username/Email" required autofocus>
  312.                         </div>
  313.  
  314.                         <div class="form-group">
  315.                            
  316.                             <input type="password" class="form-control"  name="password" id="password"  placeholder="Password" required autocomplete="off">
  317.                         </div>
  318.  
  319.                         <?php
  320.                         if($settings->recaptcha == 1){
  321.                         ?>
  322.                         <div class="form-group">
  323.                             <label>Please check the box below to continue</label>
  324.                             <div class="g-recaptcha" data-sitekey="<?=$publickey; ?>"></div>
  325.                         </div>
  326.                         <?php } ?>
  327.  
  328.                         <div class="form-group">
  329.                             <label for="remember">
  330.                             <input type="checkbox" name="remember" id="remember" > Remember Me</label>
  331.                         </div>
  332.  
  333.                         <input type="hidden" name="csrf" value="<?=Token::generate(); ?>">
  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