[Only registered and activated users can see links. Click Here To Register...]
this is the better version with a better design and the timer things in it go use it
EDIT: Registration class that does not use email verification
Code:
<?php
if (Loggedin())
die("loggedin");
$errors = array('message' => '', 'state' => 'error');
if (empty($_POST['username'])
|| empty($_POST['password'])
|| empty($_POST['password2'])
) {
$errors['state'] = "error";
$errors['message'] = "All Fields are Required!<br>";
}
if ($_allowSecretCode && empty($_POST['secretn'])) {
$errors['state'] = "error";
$errors['message'] = "Secret Code is Required!";
}
if ($_rrequireEmail && empty($_POST['email'])) {
$errors['state'] = "error";
$errors['message'] = "Email is Required!";
} else if (empty($errors['message'])) {
/* POST data */
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'] ?? "";
$secret = $_POST['secretn'] ?? "";
if (!alphanum($username))
$errors['message'] .= "The Username field may only contain alpha-numeric characters.<br>";
if (!alphanum($password))
$errors['message'] .= "The Password field may only contain alpha-numeric characters.<br>";
if (!alphanum($password2))
$errors['message'] .= "The Password Confirm field may only contain alpha-numeric characters.<br>";
if ($_allowSecretCode && !empty($secret) && !isnum($secret))
$errors['message'] .= "The SecretCode field must contain only numbers.<br>";
if ($_rrequireEmail && !filter_var($email, FILTER_VALIDATE_EMAIL))
$errors['message'] .= "Incorrect email format";
else if (empty($errors['message'])) {
/* exists? */
$userexist = _Count("select * from $array[3]..TB_User where StrUserID=:User", array(':User' => $username));
$userawaitsverify = _Count("select * from $array[3]..TB_Unverified where Username=:User", array(':User' => $username));
$emailexist = _Count("select * from $array[3]..TB_User where Email=:email", array(':email' => $email));
$emailexistverify = _Count("select * from $array[3]..TB_Unverified where Email=:email", array(':email' => $email));
if ($userexist > 0 || $userawaitsverify > 0)
$errors['message'] .= "Username Already Exists!<br>";
if ($emailexist > 0 || $emailexistverify > 0 && $_rrequireEmail)
$errors['message'] .= "Email Already Exists!<br>";
if ($_allowSecretCode && empty($secret))
$errors['message'] .= "Secret Code Cannot be empty.!<br>";
if ($password != $password2)
$errors['message'] .= "Passwords Doesn't Match!";
else if ($userexist <= 0 && $userawaitsverify <= 0 && $password == $password2
|| $_rrequireEmail && $emailexist <= 0 && $emailexistverify <= 0) {
$secretcol = $_allowSecretCode ? "," . $_secretCodeColumn : "";
$secretval = $_allowSecretCode ? ",:secret" : "";
$emailcol = $_rrequireEmail ? ",Email" : "";
$emailval = $_rrequireEmail ? ",:email" : "";
$userdata = array(':user' => $username, ':pass' => md5($password));
if ($_allowSecretCode && !empty($secret))
$userdata[':secret'] = $secret;
if ($_rrequireEmail && !empty($email))
$userdata[':email'] = $email;
$ip = $_SERVER['REMOTE_ADDR'];
$date = date("Y-m-d H:i:s");
$userdata['ip'] = $ip;
$userdata['date'] = $date;
$userdata['verify'] = rand(5555, 99999999);
$insertuser = query("insert into $array[3]..TB_User (StrUserID,Password $secretcol $emailcol) values (:user,:pass $secretval $emailval)", $userdata);
//$query = "insert into $array[3]..TB_Unverified (Username,Password,RegIP,Date,VerificationCode $secretcol $emailcol) values (:user,:pass,:ip,:date,:verify $secretval $emailval)";
$insertuser = query($query, $userdata);
$emailSubject = "$serverName account verification";
$emailContent = "Dear $username,<br>Please verify your $serverName account using the link below<br>
<a href='$serverURL?p=v&k=$userdata[verify]'>Verify</a>";
//&& SendEmail($email, $emailSubject, $emailContent)
if ($insertuser) {
$errors['state'] = "success";
$errors['message'] = "Your Account Was Successfully Created!";
}
}
}
}
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function SendEmail($email, $subject, $content)
{
global $replyEmail;
global $serverEmail;
global $serverName;
global $smtpHost;
global $smtpUser;
global $smtpPass;
global $smtpPort;
require PATH . 'include/src/PHPMailer.php';
require PATH . 'include/src/SMTP.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
//$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $smtpHost; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $smtpUser; // SMTP username
$mail->Password = $smtpPass; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $smtpPort; // TCP port to connect to
//Recipients
$mail->setFrom($serverEmail, $serverName);
$mail->addAddress($email); // Add a recipient
$mail->addReplyTo($replyEmail, $serverName);
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $content;
return $mail->send();
} catch (Exception $e) {
_log("mailLog.log", $e->getMessage());
return false;
}
}
echo json_encode($errors);
exit;