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

UCC git Repository :: git.ucc.asn.au