/** * Register a new user into the database * @param string $username * @param string $password * @param string $verifypassword * @param string $email * @return boolean */ public function register($username, $password, $verifypassword, $email) { if (!Cookie::get('auth_session')) { // Input Verification : if (strlen($username) == 0) { $this->errormsg[] = $this->lang['register_username_empty']; } elseif (strlen($username) > MAX_USERNAME_LENGTH) { $this->errormsg[] = $this->lang['register_username_long']; } elseif (strlen($username) < MIN_USERNAME_LENGTH) { $this->errormsg[] = $this->lang['register_username_short']; } if (strlen($password) == 0) { $this->errormsg[] = $this->lang['register_password_empty']; } elseif (strlen($password) > MAX_PASSWORD_LENGTH) { $this->errormsg[] = $this->lang['register_password_long']; } elseif (strlen($password) < MIN_PASSWORD_LENGTH) { $this->errormsg[] = $this->lang['register_password_short']; } elseif ($password !== $verifypassword) { $this->errormsg[] = $this->lang['register_password_nomatch']; } elseif (strstr($password, $username)) { $this->errormsg[] = $this->lang['register_password_username']; } if (strlen($email) == 0) { $this->errormsg[] = $this->lang['register_email_empty']; } elseif (strlen($email) > MAX_EMAIL_LENGTH) { $this->errormsg[] = $this->lang['register_email_long']; } elseif (strlen($email) < MIN_EMAIL_LENGTH) { $this->errormsg[] = $this->lang['register_email_short']; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->errormsg[] = $this->lang['register_email_invalid']; } if (count($this->errormsg) == 0) { // Input is valid $query = $this->db->select("SELECT * FROM " . PREFIX . "users WHERE username=:username", array(":username" => $username)); $count = count($query); if ($count != 0) { // Username already exists $this->logActivity("UNKNOWN", "AUTH_REGISTER_FAIL", "Username ({$username}) already exists"); $this->errormsg[] = $this->lang['register_username_exist']; return false; } else { // Username is not taken $query = $this->db->select("SELECT * FROM " . PREFIX . "users WHERE email=:email", array(":email" => $email)); $count = count($query); if ($count != 0) { // Email address is already used $this->logActivity("UNKNOWN", "AUTH_REGISTER_FAIL", "Email ({$email}) already exists"); $this->errormsg[] = $this->lang['register_email_exist']; return false; } else { // Email address isn't already used $password = $this->hashPass($password); $activekey = $this->randomKey(RANDOM_KEY_LENGTH); $this->db->insert(PREFIX . "users", array("username" => $username, "password" => $password, "email" => $email, "activekey" => $activekey)); //EMAIL MESSAGE USING PHPMAILER $mail = new \Helpers\PhpMailer\Mail(); $mail->setFrom(EMAIL_FROM); $mail->addAddress($email); $mail->subject(SITE_NAME); $body = "Hello {$username}<br/><br/>"; $body .= "You recently registered a new account on " . SITE_NAME . "<br/>"; $body .= "To activate your account please click the following link<br/><br/>"; $body .= "<b><a href='" . BASE_URL . ACTIVATION_ROUTE . "?username={$username}&key={$activekey}'>Activate my account</a></b>"; $mail->body($body); $mail->send(); $this->logActivity($username, "AUTH_REGISTER_SUCCESS", "Account created and activation email sent"); $this->successmsg[] = $this->lang['register_success']; return true; } } } else { //some error return false; } } else { // User is logged in $this->errormsg[] = $this->lang['register_email_loggedin']; return false; } }
/** * Resends email verification * @param $email * @return bool * @throws \Helpers\PhpMailer\phpmailerException */ public function resendActivation($email) { if (!Cookie::get('auth_session')) { // Input Verification : if (strlen($email) == 0) { $auth_error[] = $this->lang['register_email_empty']; } elseif (strlen($email) > MAX_EMAIL_LENGTH) { $auth_error[] = $this->lang['register_email_long']; } elseif (strlen($email) < MIN_EMAIL_LENGTH) { $auth_error[] = $this->lang['register_email_short']; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $auth_error[] = $this->lang['register_email_invalid']; } if (count($auth_error) == 0) { // Input is valid // Check DataBase to see if email user is activated $query = $this->authorize->getAccountInfoEmail($email); $count = count($query); if ($count != 0 && $query[0]->isactive == 0) { // User Account Is not yet active. Lets get data to resend their activation with new key $username = $query[0]->username; $activekey = $this->randomKey(RANDOM_KEY_LENGTH); // Store the new key in the user's database $info = array('activekey' => $activekey); $where = array('username' => $username); $this->authorize->updateInDB('users', $info, $where); //EMAIL MESSAGE USING PHPMAILER $mail = new \Helpers\PhpMailer\Mail(); $mail->addAddress($email); $mail->subject(SITETITLE . " - Account Activation Link"); $body = "Hello {$username}<br/><br/>"; $body .= "You recently registered a new account on " . SITETITLE . "<br/>"; $body .= "To activate your account please click the following link<br/><br/>"; $body .= "<b><a href='" . BASE_URL . ACTIVATION_ROUTE . "/username/{$username}/key/{$activekey}'>Activate my account</a></b>"; $body .= "<br><br> You May Copy and Paste this URL in your Browser Address Bar: <br>"; $body .= BASE_URL . ACTIVATION_ROUTE . "/username/{$username}/key/{$activekey}"; $body .= "<br><br> You Requested to have this email resent to your email."; $mail->body($body); $mail->send(); $this->logActivity($username, "AUTH_REGISTER_SUCCESS", "Account created and activation email sent"); $this->success[] = $this->lang['register_success']; return true; } else { return false; } } else { //some error return false; } } else { // User is logged in $auth_error[] = $this->lang['register_email_loggedin']; return false; } }