View source
<?php
function noreqnewpass_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/noreqnewpass',
'title' => t('No Request New Password'),
'description' => t('Manage password preferences'),
'access' => user_access('administer noreqnewpass'),
'callback' => 'drupal_get_form',
'callback arguments' => 'noreqnewpass_admin_form',
);
}
if (variable_get('noreqnewpass_disabled', true)) {
$items[] = array(
'path' => 'user/password',
'access' => FALSE,
);
}
return $items;
}
function noreqnewpass_perm() {
return array(
'administer noreqnewpass',
'can change your own password',
);
}
function noreqnewpass_form_alter($form_id, &$form) {
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)) {
$form['#validate'] = array(
'noreqnewpass_user_login_validate' => array(),
);
}
if ($form_id == 'user_edit' && !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_validate($form_id, $form_values) {
if ($form_values['name']) {
if (user_is_blocked($form_values['name'])) {
form_set_error('name', t('The username %name has not been activated or is blocked.', array(
'%name' => $form_values['name'],
)));
}
else {
if (drupal_is_denied('user', $form_values['name'])) {
form_set_error('name', t('The name %name is a reserved username.', array(
'%name' => $form_values['name'],
)));
}
else {
if ($form_values['pass']) {
$user = user_authenticate($form_values['name'], trim($form_values['pass']));
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'],
)));
}
}
}
}
}
}