Project

General

Profile

Paste
Download (1.41 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / recovery_pass / recovery_pass.resource.inc @ 7dbec6b0

1
<?php
2

    
3
function _recovery_pass_request_new_password($user = NULL) {
4
  global $language;
5
  $user = trim($user);
6
  $user = user_load_by_name($user);
7

    
8
  // Generate random password.
9
  $random_password = user_password();
10
  // Store Old Hash Password Temporarily.
11
  if (!_recovery_pass_store_old_pass($user)) {
12
    watchdog('recovery_pass', 'Error saving old password for user @id', array('@id' => $user->uid), WATCHDOG_NOTICE, 'link');
13
  }
14
  // Save new password.
15
  user_save($user, array('pass' => $random_password), 'account');
16

    
17
  // Retrive email body and subject.
18
  $message = _recovery_pass_mail_text('email_text', $language, TRUE, $user);
19
  if ($message) {
20
    // Replace [user_new_password] placeholder with new password.
21
    $message = str_replace("[user_new_password]", $random_password, $message);
22
  }
23
  $subject = _recovery_pass_mail_text('email_subject', $language, TRUE, $user);
24
  if (module_exists("htmlmail")) {
25
    // For html mail convert new lines to br.
26
    $message = nl2br($message);
27
  }
28
  $params = array(
29
    'body' => $message,
30
    'subject' => $subject,
31
  );
32
  $to = $user->mail;
33
  $from = variable_get('site_mail');
34
  if (drupal_mail('recovery_pass', 'recovery_pass', $to, language_default(), $params, $from, TRUE)) {
35
    return TRUE;
36
  }
37
  else {
38
    return services_error(t("Error Sending Recovery Mail. Please contact site administrator."), 406);
39
  }
40
}
41

    
42
function _recovery_pass_resource_access() {
43
  return TRUE;
44
}