/** * Send an email to the user with a link to validate/confirm his email address. * * If the email could get sent, it saves the used "request_id" into the user's Session. * * @param string URL, where to redirect the user after he clicked the validation link (gets saved in Session). * @return boolean True, if the email could get sent; false if not */ function send_validate_email($redirect_to_after, $blog = NULL, $email_changed = false) { global $app_name, $Session, $secure_htsrv_url, $baseurl, $servertimenow; global $Settings, $UserSettings; // Display messages depending on user email status display_user_email_status_message($this->ID); if ($Settings->get('validation_process') == 'easy') { // validation process is set to easy, send and easy activation email return send_easy_validate_emails(array($this->ID), false, $email_changed); } if (mail_is_blocked($this->email)) { // prevent trying to send an email to a blocked email address ( Note this is checked in the send_easy_validate_emails too ) return false; } if (empty($redirect_to_after)) { // redirect to was not set $redirect_to_after = param('redirect_to', 'url', ''); if (empty($redirect_to_after)) { if (is_admin_page()) { $redirect_to_after = regenerate_url('action'); } else { $redirect_to_after = $this->get_userpage_url(); } } } $request_id = generate_random_key(22); $blog_param = empty($blog) ? '' : '&inskin=1&blog=' . $blog; // Change locale here to localize the email subject and content locale_temp_switch($this->get('locale')); $email_template_params = array('status' => $this->status, 'blog_param' => $blog_param, 'request_id' => $request_id); $r = send_mail_to_User($this->ID, T_('Activate your account: $login$'), 'account_activate', $email_template_params, true); locale_restore_previous(); if ($r) { // save request_id into Session $request_ids = $Session->get('core.validatemail.request_ids'); if (!is_array($request_ids) || $email_changed) { // create new request ids array if it doesn't exist yet, or if user email changed ( this way the old request into the old email address won't be valid ) $request_ids = array(); } $request_ids[] = $request_id; $Session->set('core.validatemail.request_ids', $request_ids, 86400 * 2); // expires in two days (or when clicked) // set a redirect_to session variable because this way after the account will be activated we will know where to redirect $Session->set('core.validatemail.redirect_to', $redirect_to_after); $Session->dbsave(); // save immediately // update last activation email timestamp $UserSettings->set('last_activation_email', date2mysql($servertimenow), $this->ID); $UserSettings->dbupdate(); } return $r; }
$SQL->FROM_add('LEFT JOIN T_users__usersettings reminder_sent ON reminder_sent.uset_user_ID = user_ID AND reminder_sent.uset_name = "activation_reminder_count"'); // check that user status is 'new' or 'emailchanged' or 'deactivated', and send reminders only for these users. $SQL->WHERE($status_condition); // check if user has an email address $SQL->WHERE_and('LENGTH(TRIM(user_email)) > 0'); // check that user email is not blocked $SQL->WHERE_and('user_email NOT IN ( SELECT emadr_address FROM T_email__address WHERE ' . get_mail_blocked_condition() . ' )'); // check that user was created more than x ( = confugred activate account reminder threshold ) seconds ago! $threshold_date = date2mysql($servertimenow - $activate_account_reminder_threshold); $SQL->WHERE_and('user_created_datetime < ' . $DB->quote($threshold_date)); // check how many reminders was sent to the user and when => send reminders only if required $SQL->WHERE_and(implode(' OR ', $reminder_delay_conditions)); // check if user wants to recevice activation reminder or not $SQL->WHERE_and('notif_setting.uset_value IS NULL OR notif_setting.uset_value <> ' . $DB->quote('0')); $UserCache =& get_UserCache(); $UserCache->clear(); // load all users to reminded into the UserCache $UserCache->load_by_sql($SQL); // Send activation reminder to every user loaded into the UserCache ( there are only not activated users ) $reminder_sent = send_easy_validate_emails($UserCache->get_ID_array()); // Set failed activation status for all users who didn't receive activation reminder or account validation email in the last seven days, // and user was created more then a week, and have received at least one activation email. $failed_activation_date = date2mysql($servertimenow - $failed_activation_threshold); $DB->query('UPDATE T_users LEFT JOIN T_users__usersettings ON uset_user_ID = user_ID SET user_status = "failedactivation" WHERE ( uset_name = "last_activation_email" AND uset_value IS NOT NULL AND uset_value < ' . $DB->quote($failed_activation_date) . ' ) AND ( user_created_datetime < ' . $DB->quote($failed_activation_date) . ' ) AND ' . $status_condition); $result_message = sprintf(T_('%d account activation reminder emails were sent!'), $reminder_sent); return 1; /* ok */