Hey all, Kinda new to php but have managed to create a website with a login script (cheated and used usercake) but have modified it to my own needs mostly. However I now need to make it so that when the user registers it sends it to me not to the user (so that I can approve it), Have gone through and found what I think is mostly it but still a little confused and wondered if I can get some pointers as to what to change to make it do this.
I currently have a register page, which checks the following three files:
newuser.php
//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");
}
class.mail.php
<?php
class userCakeMail {
public $contents = NULL;
//Function used for replacing hooks in our templates
public function newTemplateMsg($template,$additionalHooks)
{
global $mail_templates_dir,$debug_mode;
$this->contents = file_get_contents($mail_templates_dir.$template);
//Check to see we can access the file / it has some contents
if(!$this->contents || empty($this->contents))
{
return false;
}
else
{
//Replace default hooks
$this->contents = replaceDefaultHook($this->contents);
//Replace defined / custom hooks
$this->contents = str_replace($additionalHooks["searchStrs"],$additionalHooks["subjectStrs"],$this->contents);
return true;
}
}
public function sendMail($email,$subject,$msg = NULL)
{
global $websiteName,$emailAddress;
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$header .= "From: ". $websiteName . " <" . $emailAddress . ">\r\n";
//Check to see if we sending a template email.
if($msg == NULL)
$msg = $this->contents;
$message = $msg;
$message = wordwrap($message, 70);
return mail($email,$subject,$message,$header);
}
}
?>
function.php
//Input new activation token, and update the time of the most recent activation request
function updateLastActivationRequest($new_activation_token,$username,$email)
{
global $mysqli,$db_table_prefix;
$stmt = $mysqli->prepare("UPDATE ".$db_table_prefix."users
SET activation_token = ?,
last_activation_request = ?
WHERE email = ?
AND
user_name = ?");
$stmt->bind_param("ssss", $new_activation_token, time(), $email, $username);
$result = $stmt->execute();
$stmt->close();
return $result;
}
//Generate a random password, and new token
function updatePasswordFromToken($pass,$token)
{
global $mysqli,$db_table_prefix;
$new_activation_token = generateActivationToken();
$stmt = $mysqli->prepare("UPDATE ".$db_table_prefix."users
SET password = ?,
activation_token = ?
WHERE
activation_token = ?");
$stmt->bind_param("sss", $pass, $new_activation_token, $token);
$result = $stmt->execute();
$stmt->close();
return $result;
}