Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 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 if (!securePage($_SERVER['PHP_SELF'])){die();} ?>
  28. <?php
  29. $settingsQ = $db->query("SELECT * FROM settings");
  30. $settings = $settingsQ->first();
  31. if($settings->recaptcha == 1 || $settings->recaptcha == 2){
  32. require_once("includes/recaptcha.config.php");
  33. }
  34. //There is a lot of commented out code for a future release of sign ups with payments
  35. $form_method = 'POST';
  36. $form_action = 'join.php';
  37. $vericode = rand(100000,999999);
  38.  
  39. $form_valid=FALSE;
  40.  
  41. //Decide whether or not to use email activation
  42. $query = $db->query("SELECT * FROM email");
  43. $results = $query->first();
  44. $act = $results->email_act;
  45.  
  46. //Opposite Day for Pre-Activation - Basically if you say in email
  47. //settings that you do NOT want email activation, this lists new
  48. //users as active in the database, otherwise they will become
  49. //active after verifying their email.
  50. if($act==1){
  51. $pre = 0;
  52. } else {
  53. $pre = 1;
  54. }
  55.  
  56. $token = Input::get('csrf');
  57. if(Input::exists()){
  58. if(!Token::check($token)){
  59. die('Token doesn\'t match!');
  60. }
  61. }
  62.  
  63. $reCaptchaValid=FALSE;
  64.  
  65. if(Input::exists()){
  66.  
  67. $username = Input::get('username');
  68. $fname = Input::get('fname');
  69. $lname = Input::get('lname');
  70. $email = Input::get('email');
  71. $agreement_checkbox = Input::get('agreement_checkbox');
  72.  
  73. if ($agreement_checkbox=='on'){
  74. $agreement_checkbox=TRUE;
  75. }else{
  76. $agreement_checkbox=FALSE;
  77. }
  78.  
  79. $db = DB::getInstance();
  80. $settingsQ = $db->query("SELECT * FROM settings");
  81. $settings = $settingsQ->first();
  82. $validation = new Validate();
  83. $validation->check($_POST,array(
  84. 'username' => array(
  85. 'display' => 'Username',
  86. 'required' => true,
  87. 'min' => $settings->min_un,
  88. 'max' => $settings->max_un,
  89. 'unique' => 'users',
  90. ),
  91. 'fname' => array(
  92. 'display' => 'First Name',
  93. 'required' => true,
  94. 'min' => 2,
  95. 'max' => 35,
  96. ),
  97. 'lname' => array(
  98. 'display' => 'Last Name',
  99. 'required' => true,
  100. 'min' => 2,
  101. 'max' => 35,
  102. ),
  103. 'email' => array(
  104. 'display' => 'Email',
  105. 'required' => true,
  106. 'valid_email' => true,
  107. 'unique' => 'users',
  108. ),
  109.  
  110. 'password' => array(
  111. 'display' => 'Password',
  112. 'required' => true,
  113. 'min' => $settings->min_pw,
  114. 'max' => $settings->max_pw,
  115. ),
  116. 'confirm' => array(
  117. 'display' => 'Confirm Password',
  118. 'required' => true,
  119. 'matches' => 'password',
  120. ),
  121. ));
  122.  
  123. //if the agreement_checkbox is not checked, add error
  124. if (!$agreement_checkbox){
  125. $validation->addError(["Please read and accept terms and conditions"]);
  126. }
  127.  
  128. if($validation->passed() && $agreement_checkbox){
  129. //Logic if ReCAPTCHA is turned ON
  130. if($settings->recaptcha == 1 || $settings->recaptcha == 2){
  131. require_once("includes/recaptcha.config.php");
  132. //reCAPTCHA 2.0 check
  133. $response = null;
  134.  
  135. // check secret key
  136. $reCaptcha = new ReCaptcha($privatekey);
  137.  
  138. // if submitted check response
  139. if ($_POST["g-recaptcha-response"]) {
  140. $response = $reCaptcha->verifyResponse(
  141. $_SERVER["REMOTE_ADDR"],
  142. $_POST["g-recaptcha-response"]);
  143. }
  144. if ($response != null && $response->success) {
  145. // account creation code goes here
  146. $reCaptchaValid=TRUE;
  147. $form_valid=TRUE;
  148. }else{
  149. $reCaptchaValid=FALSE;
  150. $form_valid=FALSE;
  151. $validation->addError(["Please check the reCaptcha box."]);
  152. }
  153.  
  154. } //else for recaptcha
  155.  
  156. if($reCaptchaValid || $settings->recaptcha == 0){
  157.  
  158. //add user to the database
  159. $user = new User();
  160. $join_date = date("Y-m-d H:i:s");
  161. $params = array(
  162. 'fname' => Input::get('fname'),
  163. 'email' => $email,
  164. 'vericode' => $vericode,
  165. );
  166.  
  167. if($act == 1) {
  168. //Verify email address settings
  169. $to = rawurlencode($email);
  170. $subject = 'Welcome to '.$settings->site_name;
  171. $body = email_body('_email_template_verify.php',$params);
  172. email($to,$subject,$body);
  173. }
  174. try {
  175. // echo "Trying to create user";
  176. $user->create(array(
  177. 'username' => Input::get('username'),
  178. 'fname' => Input::get('fname'),
  179. 'lname' => Input::get('lname'),
  180. 'email' => Input::get('email'),
  181. 'password' =>
  182. password_hash(Input::get('password'), PASSWORD_BCRYPT, array('cost' => 12)),
  183. 'permissions' => 1,
  184. 'account_owner' => 1,
  185. 'stripe_cust_id' => '',
  186. 'join_date' => $join_date,
  187. 'company' => Input::get('company'),
  188. 'email_verified' => $pre,
  189. 'active' => 1,
  190. 'vericode' => $vericode,
  191. ));
  192. } catch (Exception $e) {
  193. die($e->getMessage());
  194. }
  195. Redirect::to($us_url_root.'users/joinThankYou.php');
  196. }
  197.  
  198. } //Validation and agreement checbox
  199. } //Input exists
  200.  
  201. ?>
  202. <?php header('X-Frame-Options: DENY'); ?>
  203. <div id="page-wrapper">
  204. <div class="container">
  205. <?php
  206. if($settings->glogin==1 && !$user->isLoggedIn()){
  207. require_once $abs_us_root.$us_url_root.'users/includes/google_oauth_login.php';
  208. }
  209. if($settings->fblogin==1 && !$user->isLoggedIn()){
  210. require_once $abs_us_root.$us_url_root.'users/includes/facebook_oauth.php';
  211. }
  212. require 'views/_join.php';
  213. ?>
  214.  
  215. </div>
  216. </div>
  217.  
  218. <!-- footers -->
  219. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  220.  
  221. <?php if($settings->recaptcha == 1 || $settings->recaptcha == 2){ ?>
  222. <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  223. <?php } ?>
  224.  
  225. <?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