diff options
author | Dries Buytaert <dries@buytaert.net> | 2005-01-06 20:38:19 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2005-01-06 20:38:19 +0000 |
commit | 7f890fd1b1daab9114dc151c8cd7f027c4a7e2f0 (patch) | |
tree | 3fab106dd026d69acbbdc82e203c3330f49d4a97 | |
parent | 9d6253374de94cb1423e76fab9015fa938f37ec1 (diff) | |
download | brdo-7f890fd1b1daab9114dc151c8cd7f027c4a7e2f0.tar.gz brdo-7f890fd1b1daab9114dc151c8cd7f027c4a7e2f0.tar.bz2 |
- Patch #15184 by drumm: clean up user password mailing.
+ After mailing the password, set a message and go to the login form (was print a message as the entire page).
+ Provide feedback if neither field was filled in.
+ Make it a full menu callback instead of going through user_page().
+ Fixed some indentation.
+ Changed some double quotes to single quotes.
+ Made sure all if statements have {}.
-rw-r--r-- | modules/user.module | 71 | ||||
-rw-r--r-- | modules/user/user.module | 71 |
2 files changed, 68 insertions, 74 deletions
diff --git a/modules/user.module b/modules/user.module index d25689b0a..6c9852b92 100644 --- a/modules/user.module +++ b/modules/user.module @@ -650,7 +650,7 @@ function user_menu($may_cache) { $items[] = array('path' => 'user/register', 'title' => t('register'), 'callback' => 'user_page', 'access' => $user->uid == 0 && variable_get('user_register', 1), 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'user/password', 'title' => t('request new password'), - 'callback' => 'user_page', 'access' => $user->uid == 0, 'type' => MENU_LOCAL_TASK); + 'callback' => 'user_pass', 'access' => $user->uid == 0, 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'user/help', 'title' => t('help'), 'callback' => 'user_help_page', 'type' => MENU_CALLBACK); @@ -909,49 +909,50 @@ function user_logout() { drupal_goto(); } -function user_pass($edit = array()) { +function user_pass() { global $base_url; + $edit = $_POST['edit']; - if ($edit['name']) { - $account = user_load(array('name' => $edit['name'], 'status' => 1)); - if (!$account) form_set_error('name', t('Sorry. The username %name is not recognized.', array('%name' => '<em>'. $edit['name'] .'</em>'))); + 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' => '<em>'. $edit['name'] .'</em>'))); + } + 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' => '<em>'. $edit['mail'] .'</em>'))); } - else if ($edit['mail']) { - $account = user_load(array('mail' => $edit['mail'], 'status' => 1)); - if (!$account) form_set_error('name', t('Sorry. The e-mail address %email is not recognized.', array('%email' => '<em>'. $edit['mail'] .'</em>'))); + else if ($edit) { + drupal_set_message(t('You must provider either a username or e-mail address.'), 'error'); } 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' => "<em>$account->name</em>" , '%email' => "<em>$account->mail</em>"))); - return t('Your password and further instructions have been sent to your e-mail address.'); - } - else { - watchdog('error', t('Error mailing password to %name at %email.', array('%name' => "<em>$account->name</em>", '%email' => "<em>$account->mail</em>"))); - return t('Unable to send mail. Please contact the site admin.'); - } + $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' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>'))); + drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.')); } else { - + watchdog('error', t('Error mailing password to %name at %email.', array('%name' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>'))); + drupal_set_message(t('Unable to send mail. Please contact the site admin.')); + } + drupal_goto('user'); + } + else { // Display form: - $output .= '<p>'. t('Enter your username <strong><em>or</em></strong> your e-mail address.') .'</p>'; + $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')); - return form($output, 'post', url('user/password')); + print theme('page', form($output)); } } @@ -1206,10 +1207,6 @@ function user_page() { } switch ($op) { - case t('E-mail new password'): - case 'password': - print theme('page', user_pass($edit)); - break; case t('Create new account'): case 'register': print theme('page', user_register($edit)); diff --git a/modules/user/user.module b/modules/user/user.module index d25689b0a..6c9852b92 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -650,7 +650,7 @@ function user_menu($may_cache) { $items[] = array('path' => 'user/register', 'title' => t('register'), 'callback' => 'user_page', 'access' => $user->uid == 0 && variable_get('user_register', 1), 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'user/password', 'title' => t('request new password'), - 'callback' => 'user_page', 'access' => $user->uid == 0, 'type' => MENU_LOCAL_TASK); + 'callback' => 'user_pass', 'access' => $user->uid == 0, 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'user/help', 'title' => t('help'), 'callback' => 'user_help_page', 'type' => MENU_CALLBACK); @@ -909,49 +909,50 @@ function user_logout() { drupal_goto(); } -function user_pass($edit = array()) { +function user_pass() { global $base_url; + $edit = $_POST['edit']; - if ($edit['name']) { - $account = user_load(array('name' => $edit['name'], 'status' => 1)); - if (!$account) form_set_error('name', t('Sorry. The username %name is not recognized.', array('%name' => '<em>'. $edit['name'] .'</em>'))); + 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' => '<em>'. $edit['name'] .'</em>'))); + } + 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' => '<em>'. $edit['mail'] .'</em>'))); } - else if ($edit['mail']) { - $account = user_load(array('mail' => $edit['mail'], 'status' => 1)); - if (!$account) form_set_error('name', t('Sorry. The e-mail address %email is not recognized.', array('%email' => '<em>'. $edit['mail'] .'</em>'))); + else if ($edit) { + drupal_set_message(t('You must provider either a username or e-mail address.'), 'error'); } 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' => "<em>$account->name</em>" , '%email' => "<em>$account->mail</em>"))); - return t('Your password and further instructions have been sent to your e-mail address.'); - } - else { - watchdog('error', t('Error mailing password to %name at %email.', array('%name' => "<em>$account->name</em>", '%email' => "<em>$account->mail</em>"))); - return t('Unable to send mail. Please contact the site admin.'); - } + $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' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>'))); + drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.')); } else { - + watchdog('error', t('Error mailing password to %name at %email.', array('%name' => '<em>'. $account->name .'</em>', '%email' => '<em>'. $account->mail .'</em>'))); + drupal_set_message(t('Unable to send mail. Please contact the site admin.')); + } + drupal_goto('user'); + } + else { // Display form: - $output .= '<p>'. t('Enter your username <strong><em>or</em></strong> your e-mail address.') .'</p>'; + $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')); - return form($output, 'post', url('user/password')); + print theme('page', form($output)); } } @@ -1206,10 +1207,6 @@ function user_page() { } switch ($op) { - case t('E-mail new password'): - case 'password': - print theme('page', user_pass($edit)); - break; case t('Create new account'): case 'register': print theme('page', user_register($edit)); |