You are here

function ip_login_form_alter in IP Login 7.3

Same name and namespace in other branches
  1. 6.2 ip_login.module \ip_login_form_alter()
  2. 7.2 ip_login.module \ip_login_form_alter()

Implementation of hook_form_alter().

File

./ip_login.module, line 240
Allow user login by IP addresses, ranges or wildcards.

Code

function ip_login_form_alter(&$form, &$form_state, $form_id) {

  // @todo should call hook_theme ideally
  switch ($form_id) {
    case 'user_login':
      $matched_uid = ip_login_check(ip_login_ip_address());
      if ($matched_uid > 0) {
        $link_text = t(variable_get('ip_login_link_login_page', 'Log in automatically'));
        if (strlen($link_text)) {

          // hide if no link text
          $link_help = t(variable_get('ip_login_link_login_page_help', "Your computer's IP address has been matched and validated."));
          $markup = '<ul class="item-list">';
          $markup .= '<li><strong>' . l($link_text, ATTEMPT_IP_LOGIN, array(
            'query' => array(
              'ip_login_override_pages' => 'yes',
            ),
          )) . '</strong>';
          if (strlen($link_help)) {
            $markup .= '<br/><small>' . filter_xss_admin($link_help) . '</small>';
          }
          $markup .= '</li></ul>';
          $form['ip_login'] = array(
            '#markup' => $markup,
            '#weight' => variable_get('ip_login_link_login_page_weight', -10),
          );
        }
      }
      break;
    case 'user_login_block':
      $matched_uid = ip_login_check(ip_login_ip_address());
      if ($matched_uid > 0) {
        $link_text = t(variable_get('ip_login_link_login_block', 'Log in automatically'));
        if (strlen($link_text)) {

          // hide if no link text
          $markup = '<ul class="item-list">';
          $markup .= '<li><strong>' . l($link_text, ATTEMPT_IP_LOGIN, array(
            'query' => array(
              'ip_login_override_pages' => 'yes',
            ),
          )) . '</strong>';
          $markup .= '</li></ul>';
          $form['ip_login'] = array(
            '#markup' => $markup,
            '#weight' => variable_get('ip_login_link_login_page_weight', -10),
          );
        }
      }
      break;
  }
}