View source
<?php
function noreqnewpass_menu() {
$items = array();
$items['admin/settings/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',
),
);
return $items;
}
function noreqnewpass_menu_alter(&$callback) {
if (variable_get('noreqnewpass_disabled', true)) {
$callback['user/password'] = array(
'access arguments' => array(
FALSE,
),
);
}
}
function noreqnewpass_perm() {
return array(
'administer noreqnewpass',
'can change your own password',
);
}
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', 1)) {
$items[] = l(t('Create new account'), 'user/register', array(
'title' => t('Create a new user account.'),
));
}
$form['links'] = array(
'#value' => theme('item_list', $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")) {
unset($form['account']['pass']);
}
}
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_states) {
global $user;
if (!$user->uid) {
form_set_error('name', t('Sorry, unrecognized username or password.'));
watchdog('user', t('Login attempt failed for %user.', array(
'%user' => $form_values['name'],
)));
}
}