Customize a 'Password Reset' form
Here is a method of customizing a 'password reset' page and hiding the account settings until the password is reset.
Problem:
I wanted the user to just see a 'Password Reset' form, and not the full account edit form, when they reset their password or login via the url in the welcome email. I also want this form to stay there until they do reset their password.
Solution:
1) When a user resets their password (Or clicks on the URL in their registration email), the form values for their user/#/edit page are empty. When they login normally, this is not the case. Therefore, an empty $edit variable on user login is our flag:
<?php
function mymodule_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'login') {
if (empty($edit)) {
// Add a temporary variable to the user object called 'reset'
user_save($account, array('reset' => TRUE));
}
break;
}
}
?>2) Now you can customize the 'Password Reset' form:
<?php
function mymodule_form_alter($form_id, &$form) {
if ('user_edit' == $form_id) {
if (isset($form['_account']['#value']->reset) ) {
$form['account']['#title'] = t('Password Reset');
// Include mail for the user.module validation code
$form['account']['mail'] = array('#type' => 'value', '#value' => $form['_account']['#value']->mail);
$form['picture'] = NULL;
$form['theme_select'] = NULL;
$form['comment_settings'] = NULL;
$form['timezone'] = NULL;
}
}
}
?>3) Lastly, be sure to remove the special 'reset' variable we added to the user. I do this in user 'submit', but you can even do it in hook_form_alter(), depending on your needs.
<?php
function mymodule_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'submit') {
if ($account->reset) {
user_save($account, array('reset' => NULL));
return;
}
}
}
?>