This is a minor issue but it boggled my mind for a bit.

I noticed on my site that when users registered at /user/register they got the email intended for users created by an administrator. This was misleading, because it suggested they could log in when in reality we want them to contact us before approving their account. A few users became confused.

(Our account creation scheme is "Who can create accounts? Visitors, but administrator approval is required")

It turns out that I had made the following form_alter (a lot of code removed for clarity):

/*
 * Implements hook_form_FORM_ID_alter().
 */
function customcode_form_user_register_form_alter(&$form, &$form_state, $form_id) {
...
  if (isset($form['account']['notify'])) {
    $form['account']['notify']['#default_value'] = TRUE;
  }//if
...
}

I did this so that the people interacting with our userbase and creating accounts would not have to remember to tick "Notify user of new account".

But this broke the (convoluted) conditional logic in user_register_submit() in user.module (lines 3836-3865):

  if ($admin && !$notify) {
    drupal_set_message(t('Created a new user account for <a href="@url">%name</a>. No e-mail has been sent.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
  }
  // No e-mail verification required; log in user immediately.
  elseif (!$admin && !variable_get('user_email_verification', TRUE) && $account->status) {
    ...
    drupal_set_message(t('Registration successful. You are now logged in.'));
    ...
  }
  // No administrator approval required.
  elseif ($account->status || $notify) {
    ...
    if ($notify) {
      drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
    }
    else {
      drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.'));
      $form_state['redirect'] = '';
    }
  }
  // Administrator approval required.
  else {
    ...
    drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, a welcome message with further instructions has been sent to your e-mail address.'));
    ...
  }

Because notify was TRUE (line 2803 of the same file says $notify = !empty($form_state['values']['notify']);), it was sending the admin email.

This is minor because I did a form alter for it to happen. But I think that this form alter is pretty reasonable and that others may be doing similar things. Maybe I should have looked at user.module before adding this, but I'd rather have code work as I'd expect. It might also help to make the logic a little less crazy in that if statement - perhaps we could make use of the form flag administer_users that I'm now using in my form alter:

  //don't do this on the normal user register form or it sends the wrong email
  if ($form['administer_users']['#value'] == TRUE) {
    $form['account']['notify']['#default_value'] = TRUE;
  }

If anyone agrees I could write a patch for the logic but I won't if it turns out I'm just coming from a different code philosophy than you real Drupallers :)

Comments

devvmh’s picture

Issue summary: View changes

specified account creation scheme more exactly

andres_de’s picture

Version: 7.22 » 7.43
Issue summary: View changes

I ran into the same issue, so this "problem" still exists and I'm very glad that I found this note.

I helped myself with:

    if (user_access('administer users')) {
      $form['account']['notify']['#default_value'] = 1;
    }

With this only administrators with the permission 'administer users' get the form field "Notify user of new account" prefilled.

thanks! and greetings
andreas

andres_de’s picture

Issue summary: View changes

I'm so stupid - I deleted the original issue text.

andres_de’s picture

Issue summary: View changes
andres_de’s picture

Issue summary: View changes
David_Rothstein’s picture

Version: 7.22 » 7.x-dev
Priority: Minor » Normal

It's not actually deleted :) I went ahead and clicked "Revert" to restore the issue summary back to the earlier revision.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.