You are here

function custom_email_registration_name_submit in Email Registration 6

Custom submit handler to fix redirect for immediate logins #648450

1 string reference to 'custom_email_registration_name_submit'
email_registration_form_user_register_alter in ./email_registration.module
Implementation of hook_form_FORMID_alter().

File

./email_registration.module, line 148
For registration process without a username

Code

function custom_email_registration_name_submit($form, &$form_state) {
  if (!isset($form_state['user'])) {
    return;
  }
  $admin = user_access('administer users');
  $account = $form_state['user'];
  if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {

    // No e-mail verification is required, create new user account, and login
    // user immediately.
    $auth = array(
      'pass' => $form_state['values']['pass'],
      'name' => $account->name,
    );
    if (user_authenticate($auth)) {

      // Authenticated, add a message and go to the users account
      // Since the standard workflow doesn't work, no other messages should appear.
      drupal_set_message(t('Registration successful. You are now logged in.'));
      $form_state['redirect'] = 'user/' . $account->uid;
    }
  }
}