user_pass

5 user.module user_pass()
6 user.pages.inc user_pass()
7 user.pages.inc user_pass()
8 user.pages.inc user_pass()

1 string reference to 'user_pass'

File

modules/user.module, line 928
Enables the user registration and login system.

Code

function user_pass() {
  global $base_url;
  $edit = $_POST['edit'];

  if ($edit['name'] && !($account = user_load(array('name' => $edit['name'], 'status' => 1)))) {
    form_set_error('name', t('Sorry. The username %name is not recognized.', array('%name' => theme('placeholder', $edit['name']))));
  }
  else if ($edit['mail'] && !($account = user_load(array('mail' => $edit['mail'], 'status' => 1)))) {
    form_set_error('mail', t('Sorry. The e-mail address %email is not recognized.', array('%email' => theme('placeholder', $edit['mail']))));
  }
  if ($account) {
    $from = variable_get('site_mail', ini_get('sendmail_from'));
    $pass = user_password();

    // Save new password:
    user_save($account, array('pass' => $pass));

    // Mail new password:
    $variables = array(
      '%username' => $account->name,
      '%site' => variable_get('site_name', 'drupal'),
      '%password' => $pass,
      '%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 = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
    $mail_success = user_mail($account->mail, $subject, $body, $headers);

    if ($mail_success) {
      watchdog('user', t('Password mailed to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))));
      drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
    }
    else {
      watchdog('user', t('Error mailing password to %name at %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', $account->mail))), WATCHDOG_ERROR);
      drupal_set_message(t('Unable to send mail. Please contact the site admin.'));
    }
    drupal_goto('user');
  }
  else {
    if ($edit) {
      drupal_set_message(t('You must provider either a username or e-mail address.'), 'error');
    }
    // Display form:
    $output = '<p>' . t('Enter your username <strong><em>or</em></strong> your e-mail address.') . '</p>';
    $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64);
    $output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64);
    $output .= form_submit(t('E-mail new password'));
    print theme('page', form($output));
  }
}
Login or register to post comments