3 UserCake Version: 2.0.2
\r
10 public $user_active = 0;
\r
11 private $clean_email;
\r
12 public $status = false;
\r
13 private $clean_password;
\r
15 private $displayname;
\r
16 public $sql_failure = false;
\r
17 public $mail_failure = false;
\r
18 public $email_taken = false;
\r
19 public $username_taken = false;
\r
20 public $displayname_taken = false;
\r
21 public $activation_token = 0;
\r
22 public $success = NULL;
\r
24 function __construct($user,$display,$pass,$email)
\r
26 //Used for display only
\r
27 $this->displayname = $display;
\r
30 $this->clean_email = sanitize($email);
\r
31 $this->clean_password = trim($pass);
\r
32 $this->username = sanitize($user);
\r
34 if(usernameExists($this->username))
\r
36 $this->username_taken = true;
\r
38 else if(displayNameExists($this->displayname))
\r
40 $this->displayname_taken = true;
\r
42 else if(emailExists($this->clean_email))
\r
44 $this->email_taken = true;
\r
48 //No problems have been found.
\r
49 $this->status = true;
\r
53 public function userCakeAddUser()
\r
55 global $mysqli,$emailActivation,$websiteUrl,$db_table_prefix;
\r
57 //Prevent this function being called if there were construction errors
\r
60 //Construct a secure hash for the plain text password
\r
61 $secure_pass = generateHash($this->clean_password);
\r
63 //Construct a unique activation token
\r
64 $this->activation_token = generateActivationToken();
\r
66 //Do we need to send out an activation email?
\r
67 if($emailActivation == "true")
\r
69 //User must activate their account first
\r
70 $this->user_active = 0;
\r
72 $mail = new userCakeMail();
\r
74 //Build the activation message
\r
75 $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token));
\r
77 //Define more if you want to build larger structures
\r
79 "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"),
\r
80 "subjectStrs" => array($activation_message,$this->activation_token,$this->displayname)
\r
83 /* Build the template - Optional, you can just use the sendMail function
\r
84 Instead to pass a message. */
\r
86 if(!$mail->newTemplateMsg("new-registration.txt",$hooks))
\r
88 $this->mail_failure = true;
\r
92 //Send the mail. Specify users email here and subject.
\r
93 //SendMail can have a third parementer for message if you do not wish to build a template.
\r
95 if(!$mail->sendMail($this->clean_email,"New User"))
\r
97 $this->mail_failure = true;
\r
100 $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");
\r
104 //Instant account activation
\r
105 $this->user_active = 1;
\r
106 $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");
\r
110 if(!$this->mail_failure)
\r
112 //Insert the user into the database providing no errors have been found.
\r
113 $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (
\r
119 last_activation_request,
\r
120 lost_password_request,
\r
140 $stmt->bind_param("sssssi", $this->username, $this->displayname, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active);
\r
142 $inserted_id = $mysqli->insert_id;
\r
145 //Insert default permission into matches table
\r
146 $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches (
\r
154 $stmt->bind_param("s", $inserted_id);
\r