You are here

logintoboggan.module in LoginToboggan 7

Same filename and directory in other branches
  1. 8 logintoboggan.module
  2. 5 logintoboggan.module
  3. 6 logintoboggan.module

LoginToboggan module

This module enhances the configuration abilities of Drupal's default login system.

File

logintoboggan.module
View source
<?php

/**
 * @file
 *  LoginToboggan module
 *
 * This module enhances the configuration abilities of Drupal's default login system.
 */

/**
 * @todo
 *
 */

/**
 * @wishlist
 *
 */

/**
 * @defgroup logintoboggan_core Core drupal hooks
 */

/**
 * Implement hook_cron().
 */
function logintoboggan_cron() {

  // If set password is enabled, and a purge interval is set, check for
  // unvalidated users to purge.
  if (($purge_interval = variable_get('logintoboggan_purge_unvalidated_user_interval', 0)) && !variable_get('user_email_verification', TRUE)) {
    $validating_id = logintoboggan_validating_id();

    // As a safety check, make sure that we have a non-core role as the
    // pre-auth role -- otherwise skip.
    if (!in_array($validating_id, array(
      DRUPAL_ANONYMOUS_RID,
      DRUPAL_AUTHENTICATED_RID,
    ))) {
      $purge_time = REQUEST_TIME - $purge_interval;
      $accounts = db_query("SELECT u.uid, u.name FROM {users} u INNER JOIN {users_roles} ur ON u.uid = ur.uid WHERE ur.rid = :rid AND u.created < :created", array(
        ':rid' => $validating_id,
        ':created' => $purge_time,
      ));
      $purged_users = array();
      $uids = array();
      foreach ($accounts as $account) {
        $uids[] = $account->uid;
        $purged_users[] = check_plain($account->name);
      }

      // Delete the users from the system.
      user_delete_multiple($uids);

      // Log the purged users.
      if (!empty($purged_users)) {
        watchdog('logintoboggan', 'Purged the following unvalidated users: !purged_users', array(
          '!purged_users' => theme('item_list', array(
            'items' => $purged_users,
          )),
        ));
      }
    }
  }
}

/**
 * Implement hook_help().
 */
function logintoboggan_help($path, $arg) {
  switch ($path) {
    case 'admin/help#logintoboggan':
      $output = t("<p>The Login Toboggan module improves the Drupal login system by offering the following features:\n      <ol>\n      <li>Allow users to log in using either their username OR their e-mail address.</li>\n      <li>Allow users to log in immediately.</li>\n      <li>Provide a login form on Access Denied pages for non-logged-in (anonymous) users.</li>\n      <li>The module provides two login block options: One uses JavaScript to display the form within the block immediately upon clicking 'log in'. The other brings the user to a separate page, but returns the user to their original page upon login.</li>\n      <li>Customize the registration form with two e-mail fields to ensure accuracy.</li>\n      <li>Optionally redirect the user to a specific page when using the 'Immediate login' feature.</li>\n      <li>Optionally redirect the user to a specific page upon validation of their e-mail address.</li>\n      <li>Optionally display a user message indicating a successful login.</li>\n      <li>Optionally combine both the login and registration form on one page.</li>\n      <li>Optionally display an 'Request new password' link on the user login form.</li>\n      <li>Optionally have unvalidated users purged from the system at a pre-defined interval (please read the CAVEATS section of INSTALL.txt for important information on configuring this feature!).</li>\n      </ol>\n      These features may be turned on or off in the Login Toboggan <a href=\"!url\">settings</a>.</p>\n      <p>Because this module completely reorients the Drupal login process you will probably want to edit the welcome e-mail on the <a href=\"!user_settings\">user settings</a> page. Note when the 'Set password' option is enabled, the [user:validate-url] token becomes a verification url that the user MUST visit in order to enable authenticated status). The following is an example welcome e-mail:</p>\n      ", array(
        '!url' => url('admin/config/system/logintoboggan'),
        '!user_settings' => url('admin/config/people/accounts'),
      ));
      $example_help_form = drupal_get_form('logintoboggan_example_help');
      $output .= drupal_render($example_help_form);
      $output .= t("<p>Note that if you have set the 'Visitors can create accounts but administrator approval is required' option for account approval, and are also using the 'Set password' feature of LoginToboggan, the user will immediately receive the permissions of the pre-authorized user role. LoginToboggan prevents the pre-authorized role from automatically inheriting the authorized role permissions. You may wish to create a pre-authorized role with the exact same permissions as the anonymous user if you wish the newly created user to only have anonymous permissions.</p><p>In order for a site administrator to unblock a user who is awaiting administrator approval, they must either click on the validation link they receive in their notification e-mail, or manually remove the user from the site's pre-authorized role -- afterwards the user will then receive 'authenticated user' permissions. In either case, the user will receive an account activated e-mail if it's enabled on the user settings page -- it's recommended that you edit the default text of the activation e-mail to match LoginToboggan's workflow as described. </p><p>If you are using the 'Visitors can create accounts and no administrator approval is required' option, removal of the pre-authorized role will happen automatically when the user validates their account via e-mail.</p><p>Also be aware that LoginToboggan only affects registrations initiated by users--any user account created by an administrator will not use any LoginToboggan functionality.");
      return $output;
      break;
    case 'admin/config/system/logintoboggan':
      if (module_exists('help')) {
        $help_text = t("More help can be found at <a href=\"!help\">LoginToboggan help</a>.", array(
          '!help' => url('admin/help/logintoboggan'),
        ));
      }
      else {
        $help_text = '';
      }
      $output = "<p>" . t("Customize your login and registration system.") . " {$help_text}</p>";
      return $output;
  }
}

/**
 * Helper function for example user e-mail textfield.
 */
function logintoboggan_example_help() {
  $example = t('
[user:name],

Thank you for registering.

IMPORTANT:
For full site access, you will need to click on this link or copy and paste it in your browser:

[user:validate-url]

This will verify your account and log you into the site. In the future you will be able to log in to [site:login-url] using the username and password that you created during registration.
');
  $form['foo'] = array(
    '#type' => 'textarea',
    '#default_value' => $example,
    '#rows' => 15,
  );
  return $form;
}

/**
 * Implement hook_form_block_admin_configure_alter().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_form_block_admin_configure_alter(&$form, &$form_state) {
  if ($form['module']['#value'] == 'user' && $form['delta']['#value'] == 'login') {
    $form['#submit'][] = 'logintoboggan_user_block_admin_configure_submit';
    $form['settings']['title']['#description'] .= '<div id="logintoboggan-block-title-description">' . t('<strong>Note:</strong> Logintoboggan module is installed. If you are using one of the custom login block types below, it is recommended that you set this to <em>&lt;none&gt;</em>.') . '</div>';
    $form['settings']['logintoboggan_login_block_type'] = array(
      '#type' => 'radios',
      '#title' => t('Block type'),
      '#default_value' => variable_get('logintoboggan_login_block_type', 0),
      '#options' => array(
        t('Standard'),
        t('Link'),
        t('Collapsible form'),
      ),
      '#description' => t("'Standard' is a standard login block, 'Link' is a login link that returns the user to the original page after logging in, 'Collapsible form' is a JavaScript collapsible login form."),
    );
    $form['settings']['logintoboggan_login_block_message'] = array(
      '#type' => 'textarea',
      '#title' => t('Set a custom message to appear at the top of the login block'),
      '#default_value' => variable_get('logintoboggan_login_block_message', ''),
    );
  }
}

/**
 * Implement hook_form_user_profile_form_alter().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_form_user_profile_form_alter(&$form, &$form_state) {
  if ($form['#user_category'] == 'account') {
    $account = $form['#user'];
    $form['#validate'][] = 'logintoboggan_user_edit_validate';
    $id = logintoboggan_validating_id();

    // User is editing their own account settings, or user admin
    // is editing their account.
    if ($GLOBALS['user']->uid == $account->uid || user_access('administer users')) {

      // Display link to re-send validation e-mail.
      // Re-validate link appears if:
      //   1. Users can create their own password.
      //   2. User is still in the validating role.
      //   3. Users can create accounts without admin approval.
      //   4. The validating role is not the authorized user role.
      if (!variable_get('user_email_verification', TRUE) && array_key_exists($id, $account->roles) && variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS && $id > DRUPAL_AUTHENTICATED_RID) {
        $form['revalidate'] = array(
          '#type' => 'fieldset',
          '#title' => t('Account validation'),
          '#weight' => -10,
        );
        $form['revalidate']['revalidate_link'] = array(
          '#markup' => l(t('re-send validation e-mail'), 'toboggan/revalidate/' . $account->uid),
        );
      }
    }
    $pre_auth = !variable_get('user_email_verification', TRUE) && $id != DRUPAL_AUTHENTICATED_RID;
    $in_pre_auth_role = in_array($id, array_keys($account->roles));

    // Messages are only necessary for user admins, and aren't necessary if
    // there's no valid pre-auth role.
    if (user_access('administer users') && isset($form['account']['roles']) && $pre_auth) {

      // User is still in the pre-auth role, so let the admin know.
      if ($in_pre_auth_role) {

        // To reduce UI confusion, remove the disabled checkbox for the
        // authenticated user role.
        unset($form['account']['roles'][DRUPAL_AUTHENTICATED_RID]);

        // This form element is necessary as a placeholder for the user's
        // pre-auth setting on form load. It's used to compare against the
        // submitted form values to see if the pre-auth role has been unchecked.
        $form['logintoboggan_pre_auth_check'] = array(
          '#type' => 'hidden',
          '#value' => '1',
        );
        if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {
          $form['account']['status']['#description'] = t('If this user was created using the "Immediate Login" feature of LoginToboggan, and they are also awaiting administrator approval on their account, you must remove them from the site\'s pre-authorized role in the "Roles" section below, or they will not receive authenticated user permissions!');
        }
        $form['account']['roles']['#description'] = t("The user is assigned LoginToboggan's pre-authorized role, and is not currently receiving authenticated user permissions.");
      }
      else {
        unset($form['account']['roles']['#options'][$id]);
      }
    }
  }
}

/**
 * Implement hook_form_user_register_form_alter().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_form_user_register_form_alter(&$form, &$form_state) {

  // Admin created accounts are only validated by the module.
  if (user_access('administer users')) {
    $form['#validate'][] = 'logintoboggan_user_register_validate';
    return;
  }
  $mail = variable_get('logintoboggan_confirm_email_at_registration', 0);
  $pass = !variable_get('user_email_verification', TRUE);

  // Ensure a valid submit array.
  $form['#submit'] = is_array($form['#submit']) ? $form['#submit'] : array();

  // Replace core's registration function with LT's registration function.
  // Put the LT submit handler first, so other submit handlers have a valid
  // user to work with upon registration.
  $key = array_search('user_register_submit', $form['#submit']);
  if ($key !== FALSE) {
    unset($form['#submit'][$key]);
  }
  array_unshift($form['#submit'], 'logintoboggan_user_register_submit');
  if ($mail || $pass) {
    $form['#validate'][] = 'logintoboggan_user_register_validate';

    //Display a confirm e-mail address box if option is enabled.
    if ($mail) {
      $form['account']['conf_mail'] = array(
        '#type' => 'textfield',
        '#title' => t('Confirm e-mail address'),
        '#weight' => -28,
        '#maxlength' => 64,
        '#description' => t('Please re-type your e-mail address to confirm it is accurate.'),
        '#required' => TRUE,
      );

      // Weight things properly so that the order is name, mail, conf_mail.
      $form['account']['name']['#weight'] = -30;
      $form['account']['mail']['#weight'] = -29;
    }
    $min_pass = variable_get('logintoboggan_minimum_password_length', 0);
    if ($pass && $min_pass > 0) {
      $form['account']['pass']['#description'] = isset($form['account']['pass']['#description']) ? $form['account']['pass']['#description'] . " " : "";
      $form['account']['pass']['#description'] .= t('Password must be at least %length characters.', array(
        '%length' => $min_pass,
      ));
    }
  }
}

/**
 * Implement hook_form_user_admin_account_alter().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_form_user_admin_account_alter(&$form, &$form_state) {

  // Unset the ability to add the pre-auth role in the user admin interface.
  $id = logintoboggan_validating_id();

  // Test here for a valid pre-auth -- we only remove this role if one exists.
  $pre_auth = !variable_get('user_email_verification', TRUE) && $id != DRUPAL_AUTHENTICATED_RID;
  $add = t('Add a role to the selected users');
  if ($pre_auth && isset($form['options']['operation']['#options'][$add]["add_role-{$id}"])) {
    unset($form['options']['operation']['#options'][$add]["add_role-{$id}"]);
  }
}

/**
 * Implement hook_form_user_pass_reset_alter().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_form_user_pass_reset_alter(&$form, &$form_state) {
  $form_args = $form_state['build_info']['args'];

  // The signature for user_pass_reset (after form and form_state) is:
  // $uid, $timestamp, $hashed_pass, $action = NULL
  $uid = $form_args[0];
  $action = isset($form_args[3]) ? $form_args[3] : NULL;

  // Make sure this isn't a rebuild of the password reset form.
  // Drupal invokes form builders during submit, so avoid acting twice.
  $is_first_form_build = empty($action) && empty($form_state['input']);

  // Password resets count as validating an email address, so remove the user
  // from the pre-auth role if they are still in it. We only want to run this
  // code when the user first hits the reset login form.
  if ($is_first_form_build && ($account = user_load($uid))) {
    $id = logintoboggan_validating_id();
    $in_pre_auth_role = $id != DRUPAL_AUTHENTICATED_RID && in_array($id, array_keys($account->roles));
    if ($in_pre_auth_role) {
      _logintoboggan_process_validation($account);
    }

    // Display a success message either on first log-in, or if we just promoted
    // the user out of pre-auth state.
    if ($account->login == 0 || $in_pre_auth_role) {
      drupal_set_message(t('You have successfully validated your e-mail address.'));
    }
  }
}

/**
 * Implement hook_form_alter().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_login':
    case 'user_login_block':

      // Grab the message from settings for display at the top of the login block.
      if ($login_msg = variable_get('logintoboggan_login_block_message', '')) {
        $form['message'] = array(
          '#markup' => filter_xss_admin($login_msg),
          '#weight' => -50,
        );
      }
      if (variable_get('logintoboggan_login_with_email', 0)) {

        // Ensure a valid validate array.
        $form['#validate'] = is_array($form['#validate']) ? $form['#validate'] : array();

        // LT's validation function must run first.
        array_unshift($form['#validate'], 'logintoboggan_user_login_validate');

        // Use theme functions to print the username field's textual labels.
        $form['name']['#title'] = theme('lt_username_title', array(
          'form_id' => $form_id,
        ));
        $form['name']['#description'] = theme('lt_username_description', array(
          'form_id' => $form_id,
        ));

        // Use theme functions to print the password field's textual labels.
        $form['pass']['#title'] = theme('lt_password_title', array(
          'form_id' => $form_id,
        ));
        $form['pass']['#description'] = theme('lt_password_description', array(
          'form_id' => $form_id,
        ));
      }
      if ($form_id == 'user_login_block') {
        $block_type = variable_get('logintoboggan_login_block_type', 0);
        if ($block_type == 1) {

          // What would really be nice here is to start with a clean form, but
          // we can't really do that, because drupal_prepare_form() has already
          // been run, and we can't run it again in the _alter() hook, or we'll
          // get into and endless loop. Since we don't know exactly what's in
          // the form, strip out all regular form elements and the handlers.
          foreach (element_children($form) as $element) {
            unset($form[$element]);

            // OpenID expects this key, so provide it to prevent notices.
            if (module_exists("openid")) {
              $form['name']['#size'] = 0;
            }
          }
          unset($form['#validate'], $form['#submit']);
          $form['logintoboggan_login_link'] = array(
            '#markup' => l(theme('lt_login_link'), 'user/login', array(
              'query' => drupal_get_destination(),
            )),
          );
        }
        elseif ($block_type == 2) {
          $form = _logintoboggan_toggleboggan($form);
        }
      }
      else {
        if (variable_get('logintoboggan_unified_login', 0)) {
          $form['lost_password'] = array(
            '#markup' => '<div class="login-forgot">' . l(t('Request new password'), 'user/password') . '</div>',
          );
        }
      }
      break;
    case 'user_admin_settings':

      // Disable the checkbox at the Account settings page which controls
      // whether e-mail verification is required upon registration or not.
      // The LoginToboggan module implements e-mail verification functionality
      // differently than core, and will control whether e-mail verification is
      // required or not.
      $form['registration_cancellation']['user_email_verification']['#disabled'] = true;
      $form['registration_cancellation']['user_email_verification']['#description'] = t('This setting has been locked by the LoginToboggan module. You can change this setting by modifying the <strong>Set password</strong> checkbox at <a href="!link">LoginToboggan settings page</a>.', array(
        '!link' => url('admin/config/system/logintoboggan'),
      ));

      //Check for the "validate-url" token in the Welcome (No approval requried) email.
      if (!variable_get('user_email_verification', TRUE)) {
        if (strpos($form['email_no_approval_required']['user_mail_register_no_approval_required_body']['#default_value'], '[user:validate-url]') === FALSE) {

          //Detect token presence, warn about issues without it.
          drupal_set_message(t('The token [user:validate-url] was not found in the <strong>Welcome (no approval required)</strong> E-mail.  Since the <strong>Set password</strong> option is set in !settingslink, it is highly recommended you add it and change the text to reflect this functionality.', array(
            '!settingslink' => l(t('Logintoboggan Settings'), 'admin/config/system/logintoboggan'),
          )), 'warning');
        }
        $form['email_no_approval_required']['user_mail_register_no_approval_required_body']['#description'] = t('To ensure Logintoboggan email verification works, replace the [user:one-time-login-url] token with the [user:validate-url] token, and change the language to reflect the fact that they are clicking an "Email Validation" link, not a "Change Password" link');
      }
      break;
  }
}

/**
 * Implement hook_js_alter().
 */
function logintoboggan_js_alter(&$javascript) {

  // Look for the user permissions js.
  if (isset($javascript['modules/user/user.permissions.js'])) {
    $id = logintoboggan_validating_id();

    // If the pre-auth user isn't the auth user, then swap out core's user
    // permissions js with LT's custom implementation. This is necessary to
    // prevent the pre-auth role's checkboxes from being automatically disabled
    // when the auth user's checkboxes are checked.
    if ($id != DRUPAL_AUTHENTICATED_RID) {
      $javascript['settings']['data'][] = array(
        'LoginToboggan' => array(
          'preAuthID' => $id,
        ),
      );
      $file = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.permissions.js';
      $javascript[$file] = drupal_js_defaults($file);
      $javascript[$file]['weight'] = 999;
    }
  }
}

/**
 * Custom submit function for user registration form
 *
 * @ingroup logintoboggan_form
 */
function logintoboggan_user_register_submit($form, &$form_state) {
  $reg_pass_set = !variable_get('user_email_verification', TRUE);

  // Test here for a valid pre-auth -- if the pre-auth is set to the auth user, we
  // handle things a bit differently.
  $pre_auth = logintoboggan_validating_id() != DRUPAL_AUTHENTICATED_RID;

  // If we are allowing user selected passwords then skip the auto-generate function
  // The new user's status will be 1 (visitors can create own accounts) if reg_pass_set == 1
  // Immediate login, we are going to assign a pre-auth role, until email validation completed
  if ($reg_pass_set) {
    $pass = $form_state['values']['pass'];

    // Let's leave the user submitted value.
    $status = $form_state['values']['status'];
  }
  else {
    $pass = user_password();
    $status = variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS;
  }

  // The unset below is needed to prevent these form values from being saved as
  // user data.
  form_state_values_clean($form_state);

  // Set the roles for the new user -- add the pre-auth role if they can pick their own password,
  // and the pre-auth role isn't anon or auth user.
  $validating_id = logintoboggan_validating_id();
  $roles = isset($form_state['values']['roles']) ? array_filter($form_state['values']['roles']) : array();
  if ($reg_pass_set && $validating_id > DRUPAL_AUTHENTICATED_RID) {
    $roles[$validating_id] = 1;
  }
  $form_state['values']['pass'] = $pass;
  $form_state['values']['init'] = $form_state['values']['mail'];
  $form_state['values']['roles'] = $roles;
  $form_state['values']['status'] = $status;
  $account = $form['#user'];
  entity_form_submit_build_entity('user', $account, $form, $form_state);

  // Populate $edit with the properties of $account, which have been edited on
  // this form by taking over all values, which appear in the form values too.
  $edit = array_intersect_key((array) $account, $form_state['values']);
  $account = user_save($account, $edit);

  // Terminate if an error occurred during user_save().
  if (!$account) {
    drupal_set_message(t("Error saving user account."), 'error');
    $form_state['redirect'] = '';
    return;
  }
  $form_state['user'] = $account;
  $form_state['values']['uid'] = $account->uid;
  watchdog('user', 'New user: %name (%email).', array(
    '%name' => $form_state['values']['name'],
    '%email' => $form_state['values']['mail'],
  ), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));

  // Add plain text password into user account to generate mail tokens.
  $account->password = $pass;

  // Compose the appropriate user message. Validation emails are only sent if:
  //   1. Users can set their own password.
  //   2. The pre-auth role isn't the auth user.
  //   3. Visitors can create their own accounts.
  $message = t('Further instructions have been sent to your e-mail address.');
  if ($reg_pass_set && $pre_auth && variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS) {
    $message = t('A validation e-mail has been sent to your e-mail address. You will need to follow the instructions in that message in order to gain full access to the site.');
  }
  if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS) {

    // Create new user account, no administrator approval required.
    $mailkey = 'register_no_approval_required';
  }
  elseif (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) {

    // Create new user account, administrator approval required.
    $mailkey = 'register_pending_approval';
    $message = t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />Once it has been approved, you will receive an e-mail containing further instructions.');
  }

  // Mail the user.
  _user_mail_notify($mailkey, $account);
  drupal_set_message($message);

  // where do we need to redirect after registration?
  $redirect = _logintoboggan_process_redirect(variable_get('logintoboggan_redirect_on_register', ''), $account);

  // Log the user in if they created the account and immediate login is enabled.
  if ($reg_pass_set && variable_get('logintoboggan_immediate_login_on_register', TRUE)) {
    $form_state['redirect'] = logintoboggan_process_login($account, $form_state['values'], $redirect);
  }
  else {

    // Redirect to the appropriate page.
    $form_state['redirect'] = $redirect;
  }
}

/**
 * Custom validation for user login form
 *
 * @ingroup logintoboggan_form
 */
function logintoboggan_user_login_validate($form, &$form_state) {
  if (isset($form_state['values']['name']) && $form_state['values']['name']) {
    if ($name = db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER(:name)", array(
      ':name' => trim($form_state['values']['name']),
    ))
      ->fetchField()) {
      form_set_value($form['name'], $name, $form_state);
    }
  }
}

/**
 * Custom validation function for user registration form
 *
 * @ingroup logintoboggan_form
 */
function logintoboggan_user_register_validate($form, &$form_state) {

  //Check to see whether our username matches any email address currently in the system.
  if ($mail = db_query("SELECT mail FROM {users} WHERE LOWER(:name) = LOWER(mail)", array(
    ':name' => $form_state['values']['name'],
  ))
    ->fetchField()) {
    form_set_error('name', t('This e-mail has already been taken by another user.'));
  }

  //Check to see whether our e-mail address matches the confirm address if enabled.
  if (variable_get('logintoboggan_confirm_email_at_registration', 0) && isset($form_state['values']['conf_mail'])) {
    if (trim($form_state['values']['mail']) != trim($form_state['values']['conf_mail'])) {
      form_set_error('conf_mail', t('Your e-mail address and confirmed e-mail address must match.'));
    }
  }

  //Do some password validation if password selection is enabled.
  if (!variable_get('user_email_verification', TRUE)) {
    $pass_err = logintoboggan_validate_pass($form_state['values']['pass']);
    if ($pass_err) {
      form_set_error('pass', $pass_err);
    }
  }
}

/**
 * Custom validation function for user edit form
 *
 * @ingroup logintoboggan_form
 */
function logintoboggan_user_edit_validate($form, &$form_state) {
  $account = $form['#user'];
  $edit = $form_state['values'];

  // If login with mail is enabled...
  if (variable_get('logintoboggan_login_with_email', 0)) {
    $uid = isset($account->uid) ? $account->uid : 0;

    // Check that no user is using this name for their email address.
    if (isset($edit['name']) && db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER(:mail) AND uid <> :uid", array(
      ':mail' => trim($edit['name']),
      ':uid' => $uid,
    ))
      ->fetchField()) {
      form_set_error('name', t('This name has already been taken by another user.'));
    }

    // Check that no user is using this email address for their name.
    if (isset($edit['mail']) && db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER(:name) AND uid <> :uid", array(
      ':name' => trim($edit['mail']),
      ':uid' => $uid,
    ))
      ->fetchField()) {
      form_set_error('mail', t('This e-mail has already been taken by another user.'));
    }
  }
  if (!empty($edit['pass'])) {

    // if we're changing the password, validate it
    $pass_err = logintoboggan_validate_pass($edit['pass']);
    if ($pass_err) {
      form_set_error('pass', $pass_err);
    }
  }
}

/**
 * Implement hook_menu_get_item_alter()
 *
 * @ingroup logintoboggan_core
 *
 * This is currently the best place to dynamically remove the authenticated role
 * from the user object, hook_boot() allows us to act on the user object before
 * any access checks are performed.
 */
function logintoboggan_boot() {
  global $user;

  // Make sure any user with pre-auth role doesn't have authenticated user role
  _logintoboggan_user_roles_alter($user);
}

/**
 * Alter user roles for loaded user account.
 *
 * If user is not an anonymous user, and the user has the pre-auth role, and the pre-auth role
 * isn't also the auth role, then unset the auth role for this user--they haven't validated yet.
 *
 * This alteration is required because sess_read() and user_load() automatically set the
 * authenticated user role for all non-anonymous users (see http://drupal.org/node/92361).
 *
 * @param &$account
 *    User account to have roles adjusted.
 */
function _logintoboggan_user_roles_alter($account) {
  $id = logintoboggan_validating_id();
  $in_pre_auth_role = in_array($id, array_keys($account->roles));
  if ($account->uid && $in_pre_auth_role) {
    if ($id != DRUPAL_AUTHENTICATED_RID) {
      unset($account->roles[DRUPAL_AUTHENTICATED_RID]);

      // Reset the permissions cache.
      drupal_static_reset('user_access');
    }
  }
}

/**
 * Implement hook_menu()
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_menu() {
  $items = array();

  // Settings page.
  $items['admin/config/system/logintoboggan'] = array(
    'title' => 'LoginToboggan',
    'description' => 'Set up custom login options like instant login, login redirects, pre-authorized validation roles, etc.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'logintoboggan_main_settings',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'logintoboggan.admin.inc',
  );

  // Callback for user validate routine.
  $items['user/validate/%user/%/%'] = array(
    'title' => 'Validate e-mail address',
    'page callback' => 'logintoboggan_validate_email',
    'page arguments' => array(
      2,
      3,
      4,
    ),
    'access callback' => 'logintoboggan_validate_email_access',
    'access arguments' => array(
      2,
      3,
    ),
    'type' => MENU_CALLBACK,
    'file' => 'logintoboggan.validation.inc',
  );

  // Callback for re-sending validation e-mail
  $items['toboggan/revalidate/%user'] = array(
    'title' => 'Re-send validation e-mail',
    'page callback' => 'logintoboggan_resend_validation',
    'page arguments' => array(
      2,
    ),
    'access callback' => 'logintoboggan_revalidate_access',
    'access arguments' => array(
      2,
    ),
    'type' => MENU_CALLBACK,
    'file' => 'logintoboggan.validation.inc',
  );

  // Callback for handling access denied redirection.
  $items['toboggan/denied'] = array(
    'access callback' => TRUE,
    'page callback' => 'logintoboggan_denied',
    'title' => 'Access denied',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implementation of hook_menu_alter().
 */
function logintoboggan_menu_alter(&$callbacks) {
  if (variable_get('logintoboggan_unified_login', 0)) {

    // Kill the tabs on the login pages.
    $callbacks['user/login']['type'] = MENU_NORMAL_ITEM;
    $callbacks['user/login']['page callback'] = 'logintoboggan_unified_login_page';
    $callbacks['user/register']['type'] = MENU_CALLBACK;
    $callbacks['user/register']['page callback'] = 'logintoboggan_unified_login_page';
    $callbacks['user/register']['page arguments'] = array(
      'register',
    );
    $callbacks['user/password']['type'] = MENU_CALLBACK;
    $callbacks['user']['page callback'] = 'logintoboggan_unified_login_page';
  }
}

/**
 * Access check for user e-mail validation.
 */
function logintoboggan_validate_email_access($account, $timestamp) {
  return $account->uid && $timestamp < REQUEST_TIME;
}

/**
 * Access check for user revalidation.
 */
function logintoboggan_revalidate_access($account) {
  if (!($GLOBALS['user']->uid && ($GLOBALS['user']->uid == $account->uid || user_access('administer users')))) {
    return FALSE;
  }

  //limit max number of revalidation requests that a user can trigger
  if (!user_access('administer users')) {
    flood_register_event('logintoboggan_revalidate-ip');
    flood_register_event('logintoboggan_revalidate-uid', 3600, $account->uid);
    $threshold = variable_get('logintoboggan_revalidate_threshold', 4);
    if (!flood_is_allowed('logintoboggan_revalidate-ip', $threshold) || !flood_is_allowed('logintoboggan_revalidate-uid', $threshold, 3600, $account->uid)) {
      drupal_set_message(t('You have already requested a validation email within the last hour.'), 'warning');
      return FALSE;
    }
  }
  return TRUE;
}

/**
 * Menu callback for user/login
 *   creates a unified login/registration form (without tabs)
 *
 * @param $active_form
 *   Which form to display, should be 'login' or 'register'.
 */
function logintoboggan_unified_login_page($active_form = 'login') {

  // Sanitize the $active_form text as it comes direct from the url.
  // It should only ever be 'login' or 'register', so default to 'login'.
  if ($active_form != 'login' && $active_form != 'register') {
    $active_form = 'login';
  }
  global $user;
  if ($user->uid) {
    menu_set_active_item('user/' . $user->uid);
    return menu_execute_active_handler(NULL, FALSE);
  }
  else {
    $output = logintoboggan_get_authentication_form($active_form);
    return $output;
  }
}

/**
 * Implementation of hook_theme().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_theme($existing, $type, $theme, $path) {
  return array(
    'lt_username_title' => array(
      'variables' => array(
        'form_id' => NULL,
      ),
    ),
    'lt_username_description' => array(
      'variables' => array(
        'form_id' => NULL,
      ),
    ),
    'lt_password_title' => array(
      'variables' => array(
        'form_id' => NULL,
      ),
    ),
    'lt_password_description' => array(
      'variables' => array(
        'form_id' => NULL,
      ),
    ),
    'lt_access_denied' => array(
      'variables' => array(),
    ),
    'lt_loggedinblock' => array(
      'variables' => array(
        'account' => NULL,
      ),
    ),
    'lt_login_link' => array(
      'variables' => array(),
    ),
    'lt_login_successful_message' => array(
      'variables' => array(
        'account' => NULL,
      ),
    ),
    'lt_unified_login_page' => array(
      'variables' => array(
        'login_form' => NULL,
        'register_form' => NULL,
        'active_form' => NULL,
      ),
    ),
  );
}

/**
 * @defgroup logintoboggan_block Functions for LoginToboggan blocks.
 */
function logintoboggan_user_block_admin_configure_submit($form, &$form_state) {
  variable_set('logintoboggan_login_block_type', $form_state['values']['logintoboggan_login_block_type']);
  variable_set('logintoboggan_login_block_message', $form_state['values']['logintoboggan_login_block_message']);
}

/**
 * Implement hook_block_view().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_block_view($delta = '') {
  global $user;
  $block = array();
  switch ($delta) {
    case 'logintoboggan_logged_in':
      if ($user->uid) {
        $block['content'] = array(
          '#theme' => 'lt_loggedinblock',
          '#account' => $user,
        );
      }
      break;
  }
  return $block;
}

/**
 * Implement hook_block_info().
 *
 * @ingroup logintoboggan_core
 */
function logintoboggan_block_info() {
  $blocks = array();
  $blocks['logintoboggan_logged_in'] = array(
    'info' => t('LoginToboggan logged in block'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * User login block with JavaScript to expand
 *
 * this should really be themed
 *
 * @return array
 *   the reconstituted user login block
 */
function _logintoboggan_toggleboggan($form) {
  $form['#attached']['js'][] = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.js';
  $pre = '<div id="toboggan-container" class="toboggan-container">';
  $options = array(
    'attributes' => array(
      'id' => 'toboggan-login-link',
      'class' => array(
        'toboggan-login-link',
      ),
    ),
    'query' => drupal_get_destination(),
  );
  $pre .= '<div id="toboggan-login-link-container" class="toboggan-login-link-container">';
  $pre .= l(theme('lt_login_link'), 'user/login', $options);
  $pre .= '</div>';

  //the block that will be toggled
  $pre .= '<div id="toboggan-login" class="user-login-block">';
  $form['pre'] = array(
    '#markup' => $pre,
    '#weight' => -300,
  );
  $form['post'] = array(
    '#markup' => '</div></div>',
    '#weight' => 300,
  );
  return $form;
}

/**
 * Builds a unified login form.
 *
 * @param $active_form
 *   Which form to display, should be 'login' or 'register'.
 */
function logintoboggan_unified_login_form($active_form = 'login') {
  $login_form = drupal_get_form('user_login');
  $register_form = drupal_get_form('user_register_form');

  // Override the default form tab if the user has been sent to the page via a
  // failed log-in or registration attempt.
  if (!empty($register_form['#validated'])) {
    $active_form = 'register';
  }
  else {
    if (!empty($login_form['#validated'])) {
      $active_form = 'login';
    }
  }
  $login_form['#attached']['js'][] = drupal_get_path('module', 'logintoboggan') . '/logintoboggan.unifiedlogin.js';
  $login_form['#attached']['js'][] = array(
    'data' => array(
      'LoginToboggan' => array(
        'unifiedLoginActiveForm' => $active_form,
      ),
    ),
    'type' => 'setting',
  );
  $rendered_login_form = drupal_render($login_form);
  $rendered_register_form = drupal_render($register_form);
  $variables = array(
    'login_form' => $rendered_login_form,
    'register_form' => $rendered_register_form,
    'active_form' => $active_form,
  );
  $output = theme('lt_unified_login_page', $variables);
  return $output;
}

/**
 * Returns an appropriate authentication form based on the configuration.
 *
 * @param $active_form
 *   Which form to display, should be 'login' or 'register'.
 */
function logintoboggan_get_authentication_form($active_form = 'login') {
  $output = '';
  if (variable_get('logintoboggan_unified_login', 0)) {
    $output = logintoboggan_unified_login_form($active_form);
  }
  elseif ($active_form == 'login') {
    $output = drupal_get_form('user_login');
  }
  elseif ($active_form == 'register') {
    $output = drupal_get_form('user_register_form');
  }
  return $output;
}
function logintoboggan_denied() {
  $original_path = $_GET['destination'];
  unset($_GET['destination']);
  if ($GLOBALS['user']->uid == 0 && ($path = drupal_get_normal_path(variable_get('logintoboggan_anon_403', ''))) && $path != $original_path) {
    drupal_goto($path, array(
      'query' => array(
        'destination' => $original_path,
      ),
    ));
  }
  elseif (($path = drupal_get_normal_path(variable_get('logintoboggan_auth_403', ''))) && $path != $original_path) {
    drupal_goto($path, array(
      'query' => array(
        'destination' => $original_path,
      ),
    ));
  }
  else {

    // Standard 403 handler.
    drupal_set_title(t('Access denied'));
    $return = t('You are not authorized to access this page.');
  }
}

/**
 * Modified version of user_validate_name
 * - validates user submitted passwords have a certain length and only contain letters, numbers or punctuation (graph character class in regex)
 */
function logintoboggan_validate_pass($pass) {
  if (!strlen($pass)) {
    return t('You must enter a password.');
  }
  if (preg_match('/[\\x{80}-\\x{A0}' . '\\x{A1}-\\x{F7}' . '\\x{AD}' . '\\x{2000}-\\x{200F}' . '\\x{2028}-\\x{202F}' . '\\x{205F}-\\x{206F}' . '\\x{FEFF}' . '\\x{FF01}-\\x{FF60}' . '\\x{FFF9}-\\x{FFFD}]/u', $pass)) {
    return t('The password contains an illegal character.');
  }
  $min_pass_length = variable_get('logintoboggan_minimum_password_length', 0);
  if ($min_pass_length && strlen($pass) < $min_pass_length) {
    return t("The password is too short: it must be at least %min_length characters.", array(
      '%min_length' => $min_pass_length,
    ));
  }
}

/**
 * Modified version of $DRUPAL_AUTHENTICATED_RID
 * - gets the role id for the "validating" user role.
 */
function logintoboggan_validating_id() {
  return variable_get('logintoboggan_pre_auth_role', DRUPAL_AUTHENTICATED_RID);
}
function _logintoboggan_process_validation($account) {

  // Test here for a valid pre-auth -- if the pre-auth is set to the auth user, we
  // handle things a bit differently.
  $validating_id = logintoboggan_validating_id();
  $pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID;

  // Remove the pre-auth role from the user, unless they haven't been approved yet.
  if ($account->status) {
    if ($pre_auth) {
      db_delete('users_roles')
        ->condition('uid', $account->uid)
        ->condition('rid', $validating_id)
        ->execute();
    }
  }

  // Reload the user object freshly, since the cached value may have stale
  // roles, and to prepare for the possible user_save() below.
  $account = user_load($account->uid, TRUE);

  // Allow other modules to react to email validation by invoking the user update hook.
  // This should only be triggered if LT's custom validation is active.
  if (!variable_get('user_email_verification', TRUE)) {
    $edit = array();
    $account->logintoboggan_email_validated = TRUE;
    user_module_invoke('update', $edit, $account);
  }
}

/**
 * Actually log the user on
 *
 * @param object $account
 *   The user object.
 * @param array $edit
 *   An array of form values if a form has been submitted.
 * @param array $redirect
 *   An array of key/value pairs describing a redirect location, in the form
 *   that drupal_goto() will understand. Defaults to:
 *     'path' => 'user/'. $user->uid
 *     'query' => NULL
 *     'fragment' => NULL
 */
function logintoboggan_process_login($account, &$edit, $redirect = array()) {
  global $user;
  $user = user_load($account->uid);
  user_login_finalize($edit);

  // In the special case where a user is validating but they did not create their
  // own password, show a user message letting them know to change their password.
  if (variable_get('user_email_verification', TRUE)) {
    watchdog('user', 'User %name used one-time login link at time %timestamp.', array(
      '%name' => $user->name,
      '%timestamp' => REQUEST_TIME,
    ));
    drupal_set_message(t('You have just used your one-time login link. It is no longer possible to use this link to login. Please change your password.'));
  }
  if (isset($redirect[0]) && $redirect[0] != '') {
    return $redirect;
  }
  return array(
    'user/' . $user->uid,
    array(
      'query' => array(),
      'fragment' => '',
    ),
  );
}
function logintoboggan_eml_validate_url($account, $url_options) {
  $timestamp = REQUEST_TIME;
  return url("user/validate/{$account->uid}/{$timestamp}/" . logintoboggan_eml_rehash($account->pass, $timestamp, $account->mail, $account->uid), $url_options);
}
function logintoboggan_eml_rehash($password, $timestamp, $mail, $uid) {
  return user_pass_rehash($password, $timestamp, $mail, $uid);
}

/**
 * Implement hook_user_login().
 */
function logintoboggan_user_login(&$edit, $account) {
  if (variable_get('logintoboggan_login_successful_message', 0)) {
    drupal_set_message(theme('lt_login_successful_message', array(
      'account' => $account,
    )));
  }
}

/**
 * Implement hook_user_load().
 */
function logintoboggan_user_load($users) {
  foreach ($users as $account) {

    // If the user has the pre-auth role, unset the authenticated role
    _logintoboggan_user_roles_alter($account);
  }
}

/**
 * Implement hook_user_update().
 */
function logintoboggan_user_update(&$edit, $account, $category) {

  // Only perform this check if an admin is editing the account.
  if (user_access('administer users') && isset($edit['roles'])) {

    // Check to see if roles present, and the pre-auth role was present when
    // the form was initially displayed.
    if (isset($edit['logintoboggan_pre_auth_check'])) {

      // If the pre-auth is set to the auth user, then no further checking is
      // necessary.
      $validating_id = logintoboggan_validating_id();
      $pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID;
      if ($pre_auth) {

        // Check to see if an admin has manually removed the pre-auth role from
        // the user. If so, send the account activation email.
        if (!isset($edit['roles'][$validating_id]) || !$edit['roles'][$validating_id]) {

          // Mail the user, letting them know their account now has auth user perms.
          _user_mail_notify('status_activated', $account);
        }
      }
    }
  }
}
function _logintoboggan_protocol() {
  return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
}

/**
 * Transforms a URL fragment into a redirect array understood by drupal_goto().
 *
 * @param $redirect
 *   The redirect string.
 * @param $account
 *   The user account object associated with the redirect.
 */
function _logintoboggan_process_redirect($redirect, $account) {
  $variables = array(
    '%uid' => $account->uid,
  );
  $redirect = drupal_parse_url(urldecode(strtr($redirect, $variables)));

  // If there's a path set, override the destination parameter if necessary.
  if ($redirect['path'] && variable_get('logintoboggan_override_destination_parameter', 1)) {
    unset($_GET['destination']);
  }
  return array(
    $redirect['path'],
    array(
      'query' => $redirect['query'],
      'fragment' => $redirect['fragment'],
    ),
  );
}

/**
 * Implement hook_mail_alter().
 */
function logintoboggan_mail_alter(&$message) {
  if ($message['id'] == 'user_register_pending_approval_admin') {
    $reg_pass_set = !variable_get('user_email_verification', TRUE);
    if ($reg_pass_set) {
      $account = $message['params']['account'];
      $url_options = array(
        'absolute' => TRUE,
      );
      $language = $message['language'];
      $langcode = isset($language) ? $language->language : NULL;
      $message['body'][] = t("\n\nThe user has automatically received the permissions of the LoginToboggan validating role. To give the user full site permissions, click the link below:\n\n!validation_url/admin\n\nAlternatively, you may visit their user account listed above and remove them from the validating role.", array(
        '!validation_url' => logintoboggan_eml_validate_url($account, $url_options),
      ), array(
        'langcode' => $langcode,
      ));
    }
  }

  // Pre-authorized users are logged in to the site without having validated
  // their e-mail address. This allows users to register using other people's
  // e-mail addresses. To prevent potential abuse we block all e-mails to
  // pre-authorized users, except the ones that are needed to recover a lost
  // account or to create a new one.
  $validating_id = logintoboggan_validating_id();
  $pre_auth = !variable_get('user_email_verification', TRUE) && $validating_id != DRUPAL_AUTHENTICATED_RID;
  $account = user_load_by_mail($message['to']);
  if ($pre_auth && !empty($account->roles) && array_key_exists($validating_id, $account->roles)) {
    $whitelist = array(
      'user_cancel_confirm',
      'user_password_reset',
      'user_register_admin_created',
      'user_register_no_approval_required',
      'user_register_pending_approval',
      'user_status_blocked',
      'user_status_canceled',
    );

    // Allow other modules to alter the e-mail whitelist.
    drupal_alter('logintoboggan_pre_auth_whitelist', $whitelist);
    $message['send'] = in_array($message['id'], $whitelist);
    watchdog('logintoboggan', 'Message to non-authenticated user email %sendto blocked.', array(
      '%sendto' => $message['to'],
    ));
  }
}

/**
 * Implement hook_element_info_alter().
 */
function logintoboggan_element_info_alter(&$type) {

  // Allow logintoboggan to alter the password_confirm minimum password length
  $type['password_confirm']['#process'] = array_merge($type['password_confirm']['#process'], array(
    'logintoboggan_form_process_password_confirm',
  ));
}
function logintoboggan_form_process_password_confirm($element) {
  foreach ($element['#attached']['js'] as $key => &$js) {
    if (!empty($js['data']['password'])) {
      $js['data']['password']['tooShort'] = t('Make it at least !length characters', array(
        '!length' => variable_get('logintoboggan_minimum_password_length', 0),
      ));
    }
  }
  return $element;
}

/**
 *
 * THEME FUNCTIONS!
 *
 * You may override and change any of these custom HTML output functions
 * by copy/pasting them into your template.php file, at which point you can
 * customize anything, provided you are using the default phptemplate engine.
 *
 * For more info on overriding theme functions, see http://drupal.org/node/55126
 */

/**
 * Theme the username title of the user login form
 * and the user login block.
 */
function theme_lt_username_title($variables) {
  switch ($variables['form_id']) {
    case 'user_login':

      // Label text for the username field on the /user/login page.
      return t('Username or e-mail address');
      break;
    case 'user_login_block':

      // Label text for the username field when shown in a block.
      return t('Username or e-mail');
      break;
  }
}

/**
 * Theme the username description of the user login form
 * and the user login block.
 */
function theme_lt_username_description($variables) {
  switch ($variables['form_id']) {
    case 'user_login':

      // The username field's description when shown on the /user/login page.
      return t('You may log in with either your assigned username or your e-mail address.');
      break;
    case 'user_login_block':
      return '';
      break;
  }
}

/**
 * Theme the password title of the user login form
 * and the user login block.
 */
function theme_lt_password_title($variables) {

  // Label text for the password field.
  return t('Password');
}

/**
 * Theme the password description of the user login form
 * and the user login block.
 */
function theme_lt_password_description($variables) {
  switch ($variables['form_id']) {
    case 'user_login':

      // The password field's description on the /user/login page.
      return t('The password field is case sensitive.');
      break;
    case 'user_login_block':

      // If showing the login form in a block, don't print any descriptive text.
      return '';
      break;
  }
}

/**
 * Theme the Access Denied message.
 */
function theme_lt_access_denied($variables) {
  return t('You are not authorized to access this page.');
}

/**
 * Theme the loggedinblock that shows for logged-in users.
 */
function theme_lt_loggedinblock($variables) {
  return l(check_plain(format_username($variables['account'])), 'user') . ' | ' . l(t('Log out'), 'user/logout');
}

/**
 * Custom theme function for the login/register link.
 */
function theme_lt_login_link($variables) {

  // Only display register text if registration is allowed.
  if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
    return t('Log in/Register');
  }
  else {
    return t('Log in');
  }
}

/**
 * Theme the login successful message.
 *
 * @param $account
 *   A user object representing the user being logged in.
 */
function theme_lt_login_successful_message($variables) {
  return t('Log in successful for %name.', array(
    '%name' => format_username($variables['account']),
  ));
}

/**
 * Theme function for unified login page.
 *
 * @ingroup themable
 */
function theme_lt_unified_login_page($variables) {
  $login_form = $variables['login_form'];
  $register_form = $variables['register_form'];
  $active_form = $variables['active_form'];
  $output = '';
  $output .= '<div class="toboggan-unified ' . $active_form . '">';

  // Create the initial message and links that people can click on.
  $output .= '<div id="login-message">' . t('You are not logged in.') . '</div>';
  $output .= '<div id="login-links">';
  $output .= l(t('I have an account'), 'user/login', array(
    'attributes' => array(
      'class' => array(
        'login-link',
      ),
      'id' => 'login-link',
    ),
  ));
  $output .= ' ';
  $output .= l(t('I want to create an account'), 'user/register', array(
    'attributes' => array(
      'class' => array(
        'login-link',
      ),
      'id' => 'register-link',
    ),
  ));
  $output .= '</div>';

  // Add the login and registration forms in.
  $output .= '<div id="login-form">' . $login_form . '</div>';
  $output .= '<div id="register-form">' . $register_form . '</div>';
  $output .= '</div>';
  return $output;
}

Functions

Namesort descending Description
logintoboggan_block_info Implement hook_block_info().
logintoboggan_block_view Implement hook_block_view().
logintoboggan_boot Implement hook_menu_get_item_alter()
logintoboggan_cron Implement hook_cron().
logintoboggan_denied
logintoboggan_element_info_alter Implement hook_element_info_alter().
logintoboggan_eml_rehash
logintoboggan_eml_validate_url
logintoboggan_example_help Helper function for example user e-mail textfield.
logintoboggan_form_alter Implement hook_form_alter().
logintoboggan_form_block_admin_configure_alter Implement hook_form_block_admin_configure_alter().
logintoboggan_form_process_password_confirm
logintoboggan_form_user_admin_account_alter Implement hook_form_user_admin_account_alter().
logintoboggan_form_user_pass_reset_alter Implement hook_form_user_pass_reset_alter().
logintoboggan_form_user_profile_form_alter Implement hook_form_user_profile_form_alter().
logintoboggan_form_user_register_form_alter Implement hook_form_user_register_form_alter().
logintoboggan_get_authentication_form Returns an appropriate authentication form based on the configuration.
logintoboggan_help Implement hook_help().
logintoboggan_js_alter Implement hook_js_alter().
logintoboggan_mail_alter Implement hook_mail_alter().
logintoboggan_menu Implement hook_menu()
logintoboggan_menu_alter Implementation of hook_menu_alter().
logintoboggan_process_login Actually log the user on
logintoboggan_revalidate_access Access check for user revalidation.
logintoboggan_theme Implementation of hook_theme().
logintoboggan_unified_login_form Builds a unified login form.
logintoboggan_unified_login_page Menu callback for user/login creates a unified login/registration form (without tabs)
logintoboggan_user_block_admin_configure_submit
logintoboggan_user_edit_validate Custom validation function for user edit form
logintoboggan_user_load Implement hook_user_load().
logintoboggan_user_login Implement hook_user_login().
logintoboggan_user_login_validate Custom validation for user login form
logintoboggan_user_register_submit Custom submit function for user registration form
logintoboggan_user_register_validate Custom validation function for user registration form
logintoboggan_user_update Implement hook_user_update().
logintoboggan_validate_email_access Access check for user e-mail validation.
logintoboggan_validate_pass Modified version of user_validate_name
logintoboggan_validating_id Modified version of $DRUPAL_AUTHENTICATED_RID
theme_lt_access_denied Theme the Access Denied message.
theme_lt_loggedinblock Theme the loggedinblock that shows for logged-in users.
theme_lt_login_link Custom theme function for the login/register link.
theme_lt_login_successful_message Theme the login successful message.
theme_lt_password_description Theme the password description of the user login form and the user login block.
theme_lt_password_title Theme the password title of the user login form and the user login block.
theme_lt_unified_login_page Theme function for unified login page.
theme_lt_username_description Theme the username description of the user login form and the user login block.
theme_lt_username_title Theme the username title of the user login form and the user login block.
_logintoboggan_process_redirect Transforms a URL fragment into a redirect array understood by drupal_goto().
_logintoboggan_process_validation
_logintoboggan_protocol
_logintoboggan_toggleboggan User login block with JavaScript to expand
_logintoboggan_user_roles_alter Alter user roles for loaded user account.