public function userCakeAddUser() { global $mysqli, $emailActivation, $websiteUrl, $db_table_prefix; //Prevent this function being called if there were construction errors if ($this->status) { //Construct a secure hash for the plain text password $secure_pass = generateHash($this->clean_password); //Construct a unique activation token $this->activation_token = generateActivationToken(); //Do we need to send out an activation email? if ($emailActivation == "true") { //User must activate their account first $this->user_active = 0; $mail = new userCakeMail(); //Build the activation message $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE", array($websiteUrl, $this->activation_token)); //Define more if you want to build larger structures $hooks = array("searchStrs" => array("#ACTIVATION-MESSAGE", "#ACTIVATION-KEY", "#USERNAME#"), "subjectStrs" => array($activation_message, $this->activation_token, $this->displayname)); /* Build the template - Optional, you can just use the sendMail function Instead to pass a message. */ if (!$mail->newTemplateMsg("new-registration.txt", $hooks)) { $this->mail_failure = true; } else { //Send the mail. Specify users email here and subject. //SendMail can have a third parementer for message if you do not wish to build a template. if (!$mail->sendMail($this->clean_email, "New User")) { $this->mail_failure = true; } } $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2"); } else { //Instant account activation $this->user_active = 1; $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1"); } if (!$this->mail_failure) { //Insert the user into the database providing no errors have been found. $user = new UcUsers(); $user->setUserName($this->username); $user->setDisplayName($this->displayname); $user->setPassword($secure_pass); $user->setEmail($this->clean_email); $user->setActivationToken($this->activation_token); $user->setLastActivationRequest(time()); $user->setLostPasswordRequest(0); $user->setActive($this->user_active); $user->setTitle('New Member'); $user->setSignUpStamp(time()); $user->setLastSignInStamp(0); $user->save(); $inserted_id = $user->getId(); //Insert default permission into matches table $permission = new UcUserPermissionMatches(); $permission->setUserId($inserted_id); $permission->setPermissionId(1); $permission->save(); } } }