I don't like the one time login process; sending the users directly to their user edit page is not what I want. I want to force the users to insert a new password.
I have created a module that doesn't work; obviously I'm not affecting the submit action and is not taking the newly inserted username to the user object.
// Let's try to add a form in the user pass reset form for password requests.
function xxx_login_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_pass_reset') {
$form['#account'] = $GLOBALS['user'];
$form['loginsetup'] = array(
'#title' => t('Login setup'),
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE
);
$form['loginsetup']['account']['name'] = array(
'#type' => 'textfield',
'#size' => 25,
'#title' => t('Username'),
'#required' => TRUE
);
$form['loginsetup']['account']['pass'] = array(
'#type' => 'password_confirm',
'#size' => 25,
'#title' => 'Please enter your new password',
'#required' => TRUE,
);
$form['message']['#markup'] = FALSE;
$form['help']['#markup'] = FALSE;
$form['actions']['submit']['#value'] = 'Enter';
// $form['#validate'][] = 'xxx_login_user_pass_validate';
$form['#submit'][] = 'xxx_login_user_pass_submit';
}
return $form;
}
// We'll check if the user did not leave a username.
// function xxx_login_user_pass_validate($form, &$form_state) {
// if (empty($form_state['values']['name'])) {
// form_set_error('name', t('You must select a username.'));
// }
// }
// We should send the new values to the user object.
function xxx_login_user_pass_submit($form, &$form_state) {
// Set up the edit array to pass to user_save().
$edit = array(
'pass' => $form_state['values']['pass'],
'name' => $form_state['values']['name']
);
// Save the account with the new password and name
user_save($form['#account'], $edit);
// Inform the user.
drupal_set_message(t('Your login details have been stored. Welcome to example.com!'));
}
The validate function is now commented, but it does not affect the module; with or without it, it still does not work.