View source
<?php
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);
if (empty($action)) {
user_account_form($form, $form_state);
$form['#user_category'] = 'account';
$form['account']['mail']['#access'] = FALSE;
$form['picture']['#access'] = FALSE;
unset($form['#action']);
$form['#submit'][] = 'prlp_user_pass_reset_submit';
}
}
}
function prlp_user_pass_reset_submit($form, &$form_state) {
global $user;
@(list($uid, $timestamp, $hashed_pass, $action) = $form_state['build_info']['args']);
if ($user->uid) {
if ($user->uid == $uid) {
drupal_set_message(t('You are logged in as %user. <a href="!user_edit">Change your password.</a>', array(
'%user' => $user->name,
'!user_edit' => url("user/{$user->uid}/edit"),
)));
}
else {
$reset_link_account = user_load($uid);
if (!empty($reset_link_account)) {
drupal_set_message(t('Another user (%other_user) is already logged into the site on this computer, but you tried to use a one-time link for user %resetting_user. Please <a href="!logout">logout</a> and try using the link again.', array(
'%other_user' => $user->name,
'%resetting_user' => $reset_link_account->name,
'!logout' => url('user/logout'),
)));
}
else {
drupal_set_message(t('The one-time login link you clicked is invalid.'));
}
}
drupal_goto();
}
else {
$timeout = variable_get('user_password_reset_timeout', 86400);
$current = REQUEST_TIME;
$users = user_load_multiple(array(
$uid,
), array(
'status' => '1',
));
if ($timestamp <= $current && ($account = reset($users))) {
if ($account->login && $current - $timestamp > $timeout) {
drupal_set_message(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'));
drupal_goto('user/password');
}
elseif ($account->uid && $timestamp >= $account->login && $timestamp <= $current && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login)) {
$form_state['user'] = $account;
if (!isset($_SESSION)) {
$_SESSION = array();
}
user_profile_form_submit($form, $form_state);
watchdog('user', 'User %name used one-time login link at time %timestamp.', array(
'%name' => $account->name,
'%timestamp' => $timestamp,
));
$user = $account;
user_login_finalize();
drupal_set_message(t('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.'));
$token = drupal_hash_base64(drupal_random_bytes(55));
$_SESSION['pass_reset_' . $user->uid] = $token;
drupal_goto('user/' . $user->uid . '/edit', array(
'query' => array(
'pass-reset-token' => $token,
),
));
}
else {
drupal_set_message(t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'));
drupal_goto('user/password');
}
}
else {
drupal_access_denied();
}
}
}