You are here

function restrict_by_ip_login_add_edit_user in Restrict Login or Role Access by IP Address 7.3

Same name and namespace in other branches
  1. 6.3 restrict_by_ip.module \restrict_by_ip_login_add_edit_user()

Form callback to add/edit user IP restriction.

1 string reference to 'restrict_by_ip_login_add_edit_user'
restrict_by_ip_menu in ./restrict_by_ip.module
Implementation of hook_menu().

File

./restrict_by_ip.module, line 251
Allows the admin to select which ip addresses role or a user can login from for this site Some of the code below is taken from the cck_ipaddress_module

Code

function restrict_by_ip_login_add_edit_user($form, &$form_state, $account = NULL) {
  $form = array();
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#maxlength' => 60,
    '#autocomplete_path' => $account ? NULL : 'user/autocomplete',
  );
  $form['restriction'] = array(
    '#type' => 'textfield',
    '#title' => t('Allowed IP range'),
    '#description' => t('Enter IP Address Ranges in CIDR Notation separated with semi-colons, with no trailing semi-colon. E.G. 10.20.30.0/24;192.168.199.1/32;1.0.0.0/8<br />For more information on CIDR notation click <a href="http://www.brassy.net/2007/mar/cidr_basic_subnetting">here</a>.'),
    '#maxlength' => NULL,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save restriction'),
    '#suffix' => l('[Cancel]', 'admin/config/people/restrict_by_ip/login'),
  );

  // Set up defaults if editing an existing restriction
  if ($account) {
    $restriction = db_query("SELECT restrict_by_ip_address FROM {restrict_by_ip} WHERE uid = :uid", array(
      ':uid' => $account->uid,
    ))
      ->fetchField();
    $form['name']['#value'] = $account->name;
    $form['name']['#disabled'] = TRUE;
    $form['name']['autocomplete_path'] = NULL;
    $form['restriction']['#default_value'] = $restriction;
    $form['restriction']['#description'] .= t('<br />Leave field blank to remove restriction.');
  }
  return $form;
}