function prlp_form_user_pass_reset_alter in Password Reset Landing Page (PRLP) 7
Same name and namespace in other branches
- 8 prlp.module \prlp_form_user_pass_reset_alter()
- 6 prlp.module \prlp_form_user_pass_reset_alter()
- 7.x prlp.module \prlp_form_user_pass_reset_alter()
Alters the user password reset landing page.
Lets the user enter a new password directly on the landing page and adds a submit handler to save it.
File
- ./
prlp.module, line 45 - Password Reset Landing Page module.
Code
function prlp_form_user_pass_reset_alter(&$form, &$form_state) {
@(list($uid, $timestamp, $hashed_pass, $action) = $form_state['build_info']['args']);
if ($uid) {
$form['#user'] = user_load($uid);
// Do this only if the URI didn't have an 'action' component.
if (empty($action)) {
// Inject the username/password change form into the current form.
user_account_form($form, $form_state);
$user_account_form_id = 'user_account_form';
drupal_alter(array(
'form',
'form_user_account_form',
), $form, $form_state, $user_account_form_id);
// ???
$form['#user_category'] = 'account';
// Hide certain fields in $form.
foreach ($form as $key => &$element) {
if (in_array($key, prlp_get_hidden_fields())) {
$element['#access'] = FALSE;
}
}
// Hide certain fields in $form['account']
foreach ($form['account'] as $key => &$element) {
if (in_array($key, prlp_get_hidden_account_fields())) {
$element['#access'] = FALSE;
}
}
// The form does not properly rebuild itself if #action is set (which
// makes it redirect in the middle of form rebuild), or on D7.79+ if the
// session value isn't set (which makes it error out).
unset($form['#action']);
if (isset($_SESSION['prlp_reset_hash']) && empty($form_state['input'])) {
$_SESSION['pass_reset_hash'] = $_SESSION['prlp_reset_hash'];
}
// Remove the part of the message that talks about changing password
// later, since they are changing it right here.
if (!empty($form['message']['#markup'])) {
$form['message']['#markup'] = str_replace('<p>Click on this button to log in to the site and change your password.</p>', '', $form['message']['#markup']);
}
if (is_array($form['account']['pass']) && variable_get('prlp_password_required', 1)) {
$form['account']['pass']['#required'] = TRUE;
}
// Before sending the user to user profile edit form.
$form['#submit'][] = 'prlp_user_pass_reset_submit';
}
}
}