naminator

class.newuser.php

Jul 17th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. <?php
  2. /*
  3. UserCake Version: 2.0.2
  4. http://usercake.com
  5. */
  6.  
  7.  
  8. class User
  9. {
  10. public $user_active = 0;
  11. private $clean_email;
  12. public $status = false;
  13. private $clean_password;
  14. private $username;
  15. private $displayname;
  16. public $sql_failure = false;
  17. public $mail_failure = false;
  18. public $email_taken = false;
  19. public $username_taken = false;
  20. public $displayname_taken = false;
  21. public $activation_token = 0;
  22. public $success = NULL;
  23. private $tname;
  24.  
  25. function __construct($user,$display,$pass,$email,$tname)
  26. {
  27. //Used for display only
  28. $this->displayname = $display;
  29.  
  30. //Sanitize
  31. $this->clean_email = sanitize($email);
  32. $this->clean_password = trim($pass);
  33. $this->username = sanitize($user);
  34. $this->tname=sanitize($tname);
  35.  
  36. if(usernameExists($this->username))
  37. {
  38. $this->username_taken = true;
  39. }
  40. else if(displayNameExists($this->displayname))
  41. {
  42. $this->displayname_taken = true;
  43. }
  44. else if(emailExists($this->clean_email))
  45. {
  46. $this->email_taken = true;
  47. }
  48. else
  49. {
  50. //No problems have been found.
  51. $this->status = true;
  52. }
  53. }
  54.  
  55. public function userCakeAddUser()
  56. {
  57. global $mysqli,$emailActivation,$websiteUrl,$db_table_prefix;
  58.  
  59. //Prevent this function being called if there were construction errors
  60. if($this->status)
  61. {
  62. //Construct a secure hash for the plain text password
  63. $secure_pass = generateHash($this->clean_password);
  64.  
  65. //Construct a unique activation token
  66. $this->activation_token = generateActivationToken();
  67.  
  68. //Do we need to send out an activation email?
  69. if($emailActivation == "true")
  70. {
  71. //User must activate their account first
  72. $this->user_active = 0;
  73.  
  74. $mail = new userCakeMail();
  75.  
  76. //Build the activation message
  77. $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token));
  78.  
  79. //Define more if you want to build larger structures
  80. $hooks = array(
  81. "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"),
  82. "subjectStrs" => array($activation_message,$this->activation_token,$this->displayname)
  83. );
  84.  
  85. /* Build the template - Optional, you can just use the sendMail function
  86. Instead to pass a message. */
  87.  
  88. if(!$mail->newTemplateMsg("new-registration.txt",$hooks))
  89. {
  90. $this->mail_failure = true;
  91. }
  92. else
  93. {
  94. //Send the mail. Specify users email here and subject.
  95. //SendMail can have a third parementer for message if you do not wish to build a template.
  96.  
  97. if(!$mail->sendMail($this->clean_email,"New User"))
  98. {
  99. $this->mail_failure = true;
  100. }
  101. }
  102. $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");
  103. }
  104. else
  105. {
  106. //Instant account activation
  107. $this->user_active = 1;
  108. $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");
  109. }
  110.  
  111.  
  112. if(!$this->mail_failure)
  113. {
  114. //Insert the user into the database providing no errors have been found.
  115. $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (
  116. user_name,
  117. display_name,
  118. password,
  119. email,
  120. activation_token,
  121. last_activation_request,
  122. lost_password_request,
  123. active,
  124. title,
  125. sign_up_stamp,
  126. last_sign_in_stamp,
  127. tname
  128. )
  129. VALUES (
  130. ?,
  131. ?,
  132. ?,
  133. ?,
  134. ?,
  135. '".time()."',
  136. '0',
  137. ?,
  138. 'New Member',
  139. '".time()."',
  140. '0',
  141. ?
  142. )");
  143. //echo $this->username." ".$this->displayname." ".$secure_pass." ".$this->clean_email." ".$this->activation_token." ".$this->user_active." ".$this->tname;
  144. $stmt->bind_param("sssssis", $this->username, $this->displayname, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active,$this->tname);
  145. echo $stmt->error;
  146. $inserted_id = $mysqli->insert_id;
  147. $stmt->close();
  148.  
  149. //Insert default permission into matches table
  150. $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches (
  151. user_id,
  152. permission_id
  153. )
  154. VALUES (
  155. ?,
  156. '1'
  157. )");
  158. $stmt->bind_param("s", $inserted_id);
  159. $stmt->execute();
  160. $stmt->close();
  161. }
  162. }
  163. }
  164. }
  165.  
  166. ?>
Advertisement
Add Comment
Please, Sign In to add comment