Exemple #1
0
 public function UserAdminAddUser()
 {
     global $db, $emailActivation, $websiteUrl, $websiteName, $db_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?
         $user_count = $db->sql_query("SELECT * FROM {$db->users}");
         if ($emailActivation && isset($user_count->num_rows) && $user_count->num_rows > 0) {
             //User must activate their account first
             $this->user_active = 0;
             $mail = new UserAdminMail();
             $activation_url = $websiteUrl . "lobby/activate-account.php?token=" . $this->activation_token;
             //Define more if you want to build larger structures
             $hooks = array("searchStrs" => array("#ACTIVATION-URL#", "#USERNAME#", "#WEBSITENAME#", "#WEBSITEURL#"), "subjectStrs" => array($activation_url, $this->unclean_username, $websiteName, $websiteUrl));
             /* Build the template - Optional, you can just use the sendMail function 
                Instead to pass a message. */
             if (!$mail->newTemplateMsg("new-registration.html", $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;
                 }
             }
         }
         if (!$this->mail_failure) {
             //Insert the user into the database providing no errors have been found.
             $sql = "INSERT INTO {$db->users} (\r\n                                `username`,\r\n                                `username_clean`,\r\n                                `password`,\r\n                                `email`,\r\n                                `activationtoken`,\r\n                                `last_activation_request`,\r\n                                `LostpasswordRequest`, \r\n                                `active`,\r\n                                `group_id`,\r\n                                `sign_up_date`,\r\n                                `last_sign_in`\r\n                                )\r\n                                VALUES (\r\n                                '" . $db->sql_escape($this->unclean_username) . "',\r\n                                '" . $db->sql_escape($this->clean_username) . "',\r\n                                '" . $secure_pass . "',\r\n                                '" . $db->sql_escape($this->clean_email) . "',\r\n                                '" . $this->activation_token . "',\r\n                                '" . time() . "',\r\n                                '0',\r\n                                '" . $this->user_active . "',\r\n                                '" . $this->group_id . "',\r\n                                '" . time() . "',\r\n                                '0'\r\n                                )";
             return $db->sql_query($sql);
         }
     }
 }
 } else {
     $userdetails = fetchUserDetails($username);
     //See if the user's account is activation
     if ($userdetails["active"] == 1) {
         $errors[] = lang("ACCOUNT_ALREADY_ACTIVE");
     } else {
         $hours_diff = round((time() - $userdetails["last_activation_request"]) / (3600 * $resend_activation_threshold), 0);
         if ($resend_activation_threshold != 0 && $hours_diff <= $resend_activation_threshold) {
             $errors[] = lang("ACCOUNT_LINK_ALREADY_SENT", array($resend_activation_threshold));
         } else {
             //For security create a new activation url;
             $new_activation_token = generateactivationtoken();
             if (!updatelast_activation_request($new_activation_token, $username, $email)) {
                 $errors[] = lang("SQL_ERROR");
             } else {
                 $mail = new UserAdminMail();
                 $activation_url = $websiteUrl . "contests/activate-account.php?token=" . $new_activation_token;
                 //Setup our custom hooks
                 $hooks = array("searchStrs" => array("#ACTIVATION-URL#", "#USERNAME#"), "subjectStrs" => array($activation_url, $userdetails["username"]));
                 if (!$mail->newTemplateMsg("resend-activation.php", $hooks)) {
                     $errors[] = lang("MAIL_TEMPLATE_BUILD_ERROR");
                 } else {
                     if (!$mail->sendMail($userdetails["email"], "Activate your UserAdmin Account")) {
                         $errors[] = lang("MAIL_ERROR");
                     } else {
                         //Success, user details have been updated in the db now mail this information out.
                         $success_message = lang("ACCOUNT_NEW_ACTIVATION_SENT");
                     }
                 }
             }
         }
Exemple #3
0
     }
 }
 if (count($errors) == 0) {
     //Check that the username / email are associated to the same account
     if (!emailusernameLinked($email, $username)) {
         $errors[] = lang("ACCOUNT_USER_OR_EMAIL_INVALID");
     } else {
         //Check if the user has any outstanding lost password requests
         $userdetails = fetchUserDetails($username);
         if ($userdetails["LostpasswordRequest"] == 1) {
             $errors[] = lang("FORGOTPASS_REQUEST_EXISTS");
         } else {
             //email the user asking to confirm this change password request
             //We can use the template builder here
             //We use the activation token again for the url key it gets regenerated everytime it's used.
             $mail = new UserAdminMail();
             $confirm_url = lang("CONFIRM") . "\n" . $websiteUrl . "contests/forgot-password.php?confirm=" . $userdetails["activationtoken"];
             $deny_url = "DENY" . "\n" . $websiteUrl . "contests/forgot-password.php?deny=" . $userdetails["activationtoken"];
             //Setup our custom hooks
             $hooks = array("searchStrs" => array("#CONFIRM-URL#", "#DENY-URL#", "#USERNAME#"), "subjectStrs" => array($confirm_url, $deny_url, $userdetails["username"]));
             if (!$mail->newTemplateMsg("lost-password-request.php", $hooks)) {
                 $errors[] = lang("MAIL_TEMPLATE_BUILD_ERROR");
             } else {
                 if (!$mail->sendMail($userdetails["email"], "Lost password request")) {
                     $errors[] = lang("MAIL_ERROR");
                 } else {
                     //Update the DB to show this account has an outstanding request
                     flagLostpasswordRequest($username, 1);
                     $success_message = lang("FORGOTPASS_REQUEST_SUCCESS");
                 }
             }