--- /dev/null
+<?php\r
+/*\r
+UserCake Version: 2.0.2\r
+http://usercake.com\r
+*/\r
+\r
+\r
+class User \r
+{\r
+ public $user_active = 0;\r
+ private $clean_email;\r
+ public $status = false;\r
+ private $clean_password;\r
+ private $username;\r
+ private $displayname;\r
+ public $sql_failure = false;\r
+ public $mail_failure = false;\r
+ public $email_taken = false;\r
+ public $username_taken = false;\r
+ public $displayname_taken = false;\r
+ public $activation_token = 0;\r
+ public $success = NULL;\r
+ \r
+ function __construct($user,$display,$pass,$email)\r
+ {\r
+ //Used for display only\r
+ $this->displayname = $display;\r
+ \r
+ //Sanitize\r
+ $this->clean_email = sanitize($email);\r
+ $this->clean_password = trim($pass);\r
+ $this->username = sanitize($user);\r
+ \r
+ if(usernameExists($this->username))\r
+ {\r
+ $this->username_taken = true;\r
+ }\r
+ else if(displayNameExists($this->displayname))\r
+ {\r
+ $this->displayname_taken = true;\r
+ }\r
+ else if(emailExists($this->clean_email))\r
+ {\r
+ $this->email_taken = true;\r
+ }\r
+ else\r
+ {\r
+ //No problems have been found.\r
+ $this->status = true;\r
+ }\r
+ }\r
+ \r
+ public function userCakeAddUser()\r
+ {\r
+ global $mysqli,$emailActivation,$websiteUrl,$db_table_prefix;\r
+ \r
+ //Prevent this function being called if there were construction errors\r
+ if($this->status)\r
+ {\r
+ //Construct a secure hash for the plain text password\r
+ $secure_pass = generateHash($this->clean_password);\r
+ \r
+ //Construct a unique activation token\r
+ $this->activation_token = generateActivationToken();\r
+ \r
+ //Do we need to send out an activation email?\r
+ if($emailActivation == "true")\r
+ {\r
+ //User must activate their account first\r
+ $this->user_active = 0;\r
+ \r
+ $mail = new userCakeMail();\r
+ \r
+ //Build the activation message\r
+ $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token));\r
+ \r
+ //Define more if you want to build larger structures\r
+ $hooks = array(\r
+ "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"),\r
+ "subjectStrs" => array($activation_message,$this->activation_token,$this->displayname)\r
+ );\r
+ \r
+ /* Build the template - Optional, you can just use the sendMail function \r
+ Instead to pass a message. */\r
+ \r
+ if(!$mail->newTemplateMsg("new-registration.txt",$hooks))\r
+ {\r
+ $this->mail_failure = true;\r
+ }\r
+ else\r
+ {\r
+ //Send the mail. Specify users email here and subject. \r
+ //SendMail can have a third parementer for message if you do not wish to build a template.\r
+ \r
+ if(!$mail->sendMail($this->clean_email,"New User"))\r
+ {\r
+ $this->mail_failure = true;\r
+ }\r
+ }\r
+ $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");\r
+ }\r
+ else\r
+ {\r
+ //Instant account activation\r
+ $this->user_active = 1;\r
+ $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");\r
+ } \r
+ \r
+ \r
+ if(!$this->mail_failure)\r
+ {\r
+ //Insert the user into the database providing no errors have been found.\r
+ $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (\r
+ user_name,\r
+ display_name,\r
+ password,\r
+ email,\r
+ activation_token,\r
+ last_activation_request,\r
+ lost_password_request, \r
+ active,\r
+ title,\r
+ sign_up_stamp,\r
+ last_sign_in_stamp\r
+ )\r
+ VALUES (\r
+ ?,\r
+ ?,\r
+ ?,\r
+ ?,\r
+ ?,\r
+ '".time()."',\r
+ '0',\r
+ ?,\r
+ 'New Member',\r
+ '".time()."',\r
+ '0'\r
+ )");\r
+ \r
+ $stmt->bind_param("sssssi", $this->username, $this->displayname, $secure_pass, $this->clean_email, $this->activation_token, $this->user_active);\r
+ $stmt->execute();\r
+ $inserted_id = $mysqli->insert_id;\r
+ $stmt->close();\r
+ \r
+ //Insert default permission into matches table\r
+ $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."user_permission_matches (\r
+ user_id,\r
+ permission_id\r
+ )\r
+ VALUES (\r
+ ?,\r
+ '1'\r
+ )");\r
+ $stmt->bind_param("s", $inserted_id);\r
+ $stmt->execute();\r
+ $stmt->close();\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+?>
\ No newline at end of file