Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 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){
  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. $company = Input::get('company');
  72. $agreement_checkbox = Input::get('agreement_checkbox');
  73.  
  74. if ($agreement_checkbox=='on'){
  75. $agreement_checkbox=TRUE;
  76. }else{
  77. $agreement_checkbox=FALSE;
  78. }
  79.  
  80. $db = DB::getInstance();
  81. $settingsQ = $db->query("SELECT * FROM settings");
  82. $settings = $settingsQ->first();
  83. $validation = new Validate();
  84. $validation->check($_POST,array(
  85. 'username' => array(
  86. 'display' => 'Username',
  87. 'required' => true,
  88. 'min' => 5,
  89. 'max' => 35,
  90. 'unique' => 'users',
  91. ),
  92. 'fname' => array(
  93. 'display' => 'First Name',
  94. 'required' => true,
  95. 'min' => 2,
  96. 'max' => 35,
  97. ),
  98. 'lname' => array(
  99. 'display' => 'Last Name',
  100. 'required' => true,
  101. 'min' => 2,
  102. 'max' => 35,
  103. ),
  104. 'email' => array(
  105. 'display' => 'Email',
  106. 'required' => true,
  107. 'valid_email' => true,
  108. 'unique' => 'users',
  109. ),
  110. 'company' => array(
  111. 'display' => 'Company Name',
  112. 'required' => false,
  113. 'min' => 0,
  114. 'max' => 75,
  115. ),
  116. 'password' => array(
  117. 'display' => 'Password',
  118. 'required' => true,
  119. 'min' => 6,
  120. 'max' => 25,
  121. ),
  122. 'confirm' => array(
  123. 'display' => 'Confirm Password',
  124. 'required' => true,
  125. 'matches' => 'password',
  126. ),
  127. ));
  128.  
  129. //if the agreement_checkbox is not checked, add error
  130. if (!$agreement_checkbox){
  131. $validation->addError(["Please read and accept terms and conditions"]);
  132. }
  133.  
  134. if($validation->passed() && $agreement_checkbox){
  135. //Logic if ReCAPTCHA is turned ON
  136. if($settings->recaptcha == 1){
  137. require_once("includes/recaptcha.config.php");
  138. //reCAPTCHA 2.0 check
  139. $response = null;
  140.  
  141. // check secret key
  142. $reCaptcha = new ReCaptcha($privatekey);
  143.  
  144. // if submitted check response
  145. if ($_POST["g-recaptcha-response"]) {
  146. $response = $reCaptcha->verifyResponse(
  147. $_SERVER["REMOTE_ADDR"],
  148. $_POST["g-recaptcha-response"]);
  149. }
  150. if ($response != null && $response->success) {
  151. // account creation code goes here
  152. $reCaptchaValid=TRUE;
  153. $form_valid=TRUE;
  154. }else{
  155. $reCaptchaValid=FALSE;
  156. $form_valid=FALSE;
  157. $validation->addError(["Please check the reCaptcha box."]);
  158. }
  159.  
  160. } //else for recaptcha
  161.  
  162. if($reCaptchaValid || $settings->recaptcha == 0){
  163.  
  164. //add user to the database
  165. $user = new User();
  166. $join_date = date("Y-m-d H:i:s");
  167. $params = array(
  168. 'fname' => Input::get('fname'),
  169. 'email' => rawurlencode($email),
  170. 'vericode' => $vericode,
  171. );
  172.  
  173. if($act == 1) {
  174. //Verify email address settings
  175. $to = rawurlencode($email);
  176. $subject = 'Welcome to UserSpice!';
  177. $body = email_body('_email_template_verify.php',$params);
  178. email($email,$subject,$body);
  179. }
  180. try {
  181. // echo "Trying to create user";
  182. $user->create(array(
  183. 'username' => Input::get('username'),
  184. 'fname' => Input::get('fname'),
  185. 'lname' => Input::get('lname'),
  186. 'email' => Input::get('email'),
  187. 'password' =>
  188. password_hash(Input::get('password'), PASSWORD_BCRYPT, array('cost' => 12)),
  189. 'permissions' => 1,
  190. 'account_owner' => 1,
  191. 'stripe_cust_id' => '',
  192. 'join_date' => $join_date,
  193. 'company' => Input::get('company'),
  194. 'email_verified' => $pre,
  195. 'active' => 1,
  196. 'vericode' => $vericode,
  197. ));
  198. } catch (Exception $e) {
  199. die($e->getMessage());
  200. }
  201. Redirect::to($us_url_root.'users/joinThankYou.php');
  202. }
  203.  
  204. } //Validation and agreement checbox
  205. } //Input exists
  206.  
  207. ?>
  208. <?php
  209. if ($user->isLoggedIn()) {
  210. Redirect::to('account.php');
  211. }
  212. ?>
  213.  
  214. <div id="page-wrapper">
  215. <div class="container">
  216. <?php
  217. require 'views/_join.php';
  218. ?>
  219.  
  220. </div>
  221. </div>
  222.  
  223. <!-- footers -->
  224. <?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  225.  
  226. <?php if($settings->recaptcha == 1){ ?>
  227. <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  228. <?php } ?>
  229. <?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