disable_login.module in Disable Login Page 7
Same filename and directory in other branches
Disable Login module, for protecting login page from anonymous users.
File
disable_login.moduleView source
<?php
/**
* @file
* Disable Login module, for protecting login page from anonymous users.
*/
/**
* Implements hook_help().
*/
function disable_login_help($path, $arg) {
switch ($path) {
case 'admin/help#disable_login':
$output = '';
$output .= '<h3>' . t('About') . '</h3> ';
$output .= t('Gives a site owner options to disable access to the
/user/login page from anonymous users.');
$output .= '<h4>' . t('Features') . '</h4>';
$output .= '<ol>';
$output .= '<li>' . t('Disable Login Page is a simple module that prevents
access to the default Drupal Login Page to
anonymous users without the use of a secret key.') . '</li>';
$output .= '</ol>';
$output .= '<h4>' . t('Configuration') . '</h4>';
$output .= '<ol>';
$output .= '<li>' . t('Visit the configuration page at:') . '<strong>"' . t('Administration >> Configuration >>
Development >> Disable Login') . '"</strong></li>';
$output .= '<li>' . t('You can enable or disable the protection in the
configuration page.') . '</li>';
$output .= '<li>' . t(' You can also define the name of the secret key
and the corresponding secret value for the key
that will allow access to your login page.') . '</li>';
$output .= '<li>' . t('Hit "Save Configuration" to save the settings.') . '</li>';
return $output;
}
}
/**
* Implements hook_menu().
*/
function disable_login_menu() {
$items = array();
$items['admin/config/development/disable-login'] = array(
'title' => 'Disable Login Page Settings',
'description' => 'Configure Disable Login Page Settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'disable_login_settings_form',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Disable login admin settings form.
*/
function disable_login_settings_form($form, &$form_state) {
$form = array();
$form['disable_login'] = [
'#type' => 'checkbox',
'#title' => 'Disable public access to login page without secret key',
'#description' => t('Use this to turn on/off protection on the login page'),
'#default_value' => variable_get('disable_login', '1'),
];
$form['disable_login_querystring'] = [
'#type' => 'textfield',
'#title' => 'Querystring name',
'#maxlength' => 255,
'#size' => 128,
'#description' => t('The name of the querystring to look for the secret key'),
'#default_value' => variable_get('disable_login_querystring', 'key'),
];
$form['disable_login_secret'] = [
'#type' => 'textfield',
'#title' => 'Secret key',
'#maxlength' => 255,
'#size' => 128,
'#description' => t('The value of the secret key to access the login page'),
'#default_value' => variable_get('disable_login_secret', ''),
];
$form['#submit'][] = 'disable_login_settings_form_submit';
return system_settings_form($form);
}
/**
* Validation function for disable_login_settings_form.
*/
function disable_login_settings_form_validate($form, &$form_state) {
}
/**
* Submit function for the admin settings form.
*/
function disable_login_settings_form_submit($form, &$form_state) {
}
/**
* Implements hook_menu_alter().
*/
function disable_login_menu_alter(&$items) {
// Restrict 'user/login' page.
$items['user/login']['access callback'] = 'disable_login_check_access';
}
/**
* Access callback function to restrict user login.
*/
function disable_login_check_access() {
$params = drupal_get_query_parameters();
if (variable_get('disable_login')) {
$key_name = variable_get('disable_login_querystring');
$secret_key = variable_get('disable_login_secret');
$key_value = isset($params[$key_name]) ? $params[$key_name] : '';
if ($key_value == $secret_key) {
return TRUE;
}
else {
return FALSE;
}
}
return TRUE;
}
Functions
Name | Description |
---|---|
disable_login_check_access | Access callback function to restrict user login. |
disable_login_help | Implements hook_help(). |
disable_login_menu | Implements hook_menu(). |
disable_login_menu_alter | Implements hook_menu_alter(). |
disable_login_settings_form | Disable login admin settings form. |
disable_login_settings_form_submit | Submit function for the admin settings form. |
disable_login_settings_form_validate | Validation function for disable_login_settings_form. |