You are here

function password_policy_send_login in Password Policy 5

Sends one time login url to the user based on 'user_pass_submit'

1 call to password_policy_send_login()
password_policy_unblock in ./password_policy.module
Unblocks the expired account

File

./password_policy.module, line 827

Code

function password_policy_send_login($account = NUL) {
  global $base_url;
  $from = variable_get('site_mail', ini_get('sendmail_from'));

  // Mail one time login URL and instructions.
  $variables = array(
    '!username' => $account->name,
    '!site' => variable_get('site_name', 'drupal'),
    '!login_url' => user_pass_reset_url($account),
    '!uri' => $base_url,
    '!uri_brief' => substr($base_url, strlen('http://')),
    '%mailto' => $account->mail,
    '%date' => format_date(time()),
    '%login_uri' => url('user', NULL, NULL, TRUE),
    '!edit_uri' => url('user/' . $account->uid . '/edit', NULL, NULL, TRUE),
  );
  $subject = _user_mail_text('pass_subject', $variables);
  $body = _user_mail_text('pass_body', $variables);
  $headers = array(
    'From' => $from,
    'Reply-to' => $from,
    'X-Mailer' => 'Drupal',
    'Return-path' => $from,
    'Errors-to' => $from,
  );
  $mail_success = drupal_mail('password-policy-send-login', $account->mail, $subject, $body, $from, $headers);
  if ($mail_success) {
    watchdog('password_policy', t('Password reset instructions mailed to %name at %email.', array(
      '%name' => $account->name,
      '%email' => $account->mail,
    )));
    drupal_set_message(t('Further instructions have been sent to %name e-mail address.', array(
      '%name' => $account->name,
    )));
  }
  else {
    watchdog('password_policy', t('Error mailing password reset instructions to %name at %email.', array(
      '%name' => $account->name,
      '%email' => $account->mail,
    )), WATCHDOG_ERROR);
    drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
  }
}