View source
<?php
function noreqnewpass_menu() {
$items = array();
$items['admin/config/people/noreqnewpass'] = array(
'title' => t('No Request New Password'),
'description' => t('Manage password preferences'),
'access arguments' => array(
'administer noreqnewpass',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'noreqnewpass_admin_form',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function noreqnewpass_menu_alter(&$items) {
$items['user/password']['access callback'] = 'noreqnewpass_access_check';
}
function noreqnewpass_access_check() {
if (variable_get('noreqnewpass_disabled', TRUE)) {
return FALSE;
}
return TRUE;
}
function noreqnewpass_permission() {
return array(
'administer noreqnewpass' => array(
'title' => t('Administer No Request New Password'),
'description' => t('Administer No Request New Password module'),
),
'can change your own password' => array(
'title' => t('Can change your own password'),
'description' => t('Disable this module for a certain role.'),
),
);
}
function noreqnewpass_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login_block' && variable_get('noreqnewpass_disabled', true)) {
$items = array();
if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
$items[] = l(t('Create new account'), 'user/register', array(
'attributes' => array(
'title' => t('Create a new user account.'),
),
));
}
$form['links'] = array(
'#markup' => theme('item_list', array(
'items' => $items,
)),
);
}
if (($form_id == 'user_login_block' || $form_id == 'user_login') && variable_get('noreqnewpass_disabled', true)) {
$key = array_search('user_login_final_validate', $form['#validate']);
$form['#validate'][$key] = 'noreqnewpass_user_login_final_validate';
}
if ($form_id == 'user_profile_form' && !user_access("can change your own password")) {
$form['account']['current_pass']['#access'] = false;
$form['account']['pass']['#access'] = false;
}
}
function noreqnewpass_admin_form() {
$form = array();
$form['noreqnewpass_disabled'] = array(
'#title' => t('Disable Request new password link'),
'#type' => 'checkbox',
'#default_value' => variable_get('noreqnewpass_disabled', true),
'#description' => t('If checked, Request new password link will be disabled.'),
);
return system_settings_form($form);
}
function noreqnewpass_user_login_final_validate($form_id, &$form_state) {
if (empty($form_state['uid'])) {
flood_register_event('failed_login_attempt_ip', variable_get('user_failed_login_ip_window', 3600));
if (isset($form_state['flood_control_user_identifier'])) {
flood_register_event('failed_login_attempt_user', variable_get('user_failed_login_user_window', 21600), $form_state['flood_control_user_identifier']);
}
if (isset($form_state['flood_control_triggered'])) {
if ($form_state['flood_control_triggered'] == 'user') {
form_set_error('name', format_plural(variable_get('user_failed_login_user_limit', 5), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later.'));
}
else {
form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later.'));
}
}
else {
form_set_error('name', t('Sorry, unrecognized username or password.'));
watchdog('user', 'Login attempt failed for %user.', array(
'%user' => $form_state['values']['name'],
));
}
}
elseif (isset($form_state['flood_control_user_identifier'])) {
flood_clear_event('failed_login_attempt_user', $form_state['flood_control_user_identifier']);
}
}