2007-09-10 13:14:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* User page callback file for the user module.
|
|
|
|
*/
|
|
|
|
|
2014-03-31 17:37:55 +00:00
|
|
|
use Drupal\Core\Render\Element;
|
2012-09-20 03:34:47 +00:00
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2012-06-04 12:06:09 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
2007-09-10 13:14:38 +00:00
|
|
|
|
|
|
|
/**
|
2013-05-24 16:55:47 +00:00
|
|
|
* Prepares variables for user templates.
|
2007-09-10 13:14:38 +00:00
|
|
|
*
|
2013-05-24 16:55:47 +00:00
|
|
|
* Default template: user.html.twig.
|
2007-09-10 13:14:38 +00:00
|
|
|
*
|
2013-05-24 16:55:47 +00:00
|
|
|
* @param array $variables
|
|
|
|
* An associative array containing:
|
2014-06-20 15:18:33 +00:00
|
|
|
* - elements: An associative array containing the user information and any
|
|
|
|
* fields attached to the user. Properties used:
|
|
|
|
* - #user: A \Drupal\user\Entity\User object. The user account of the
|
|
|
|
* profile being viewed.
|
|
|
|
* - attributes: HTML attributes for the containing element.
|
2007-09-10 13:14:38 +00:00
|
|
|
*/
|
2012-12-13 12:11:18 +00:00
|
|
|
function template_preprocess_user(&$variables) {
|
|
|
|
$account = $variables['elements']['#user'];
|
2010-01-10 00:41:28 +00:00
|
|
|
|
2012-12-13 12:11:18 +00:00
|
|
|
// Helpful $content variable for templates.
|
2014-03-31 17:37:55 +00:00
|
|
|
foreach (Element::children($variables['elements']) as $key) {
|
2012-12-13 12:11:18 +00:00
|
|
|
$variables['content'][$key] = $variables['elements'][$key];
|
2009-09-10 12:33:46 +00:00
|
|
|
}
|
2007-09-10 13:14:38 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 08:42:13 +00:00
|
|
|
/**
|
2014-06-09 21:47:53 +00:00
|
|
|
* Menu callback; Cancel a user account via email confirmation link.
|
2009-01-08 08:42:13 +00:00
|
|
|
*
|
2014-07-08 18:29:13 +00:00
|
|
|
* @see \Drupal\user\Form\UserCancelForm
|
2009-01-08 08:42:13 +00:00
|
|
|
* @see user_cancel_url()
|
2013-09-18 18:30:30 +00:00
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal\user\Controller\UserController::confirmCancel().
|
2009-01-08 08:42:13 +00:00
|
|
|
*/
|
|
|
|
function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') {
|
|
|
|
// Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
|
|
|
|
$timeout = 86400;
|
|
|
|
$current = REQUEST_TIME;
|
|
|
|
|
|
|
|
// Basic validation of arguments.
|
2013-09-16 03:58:06 +00:00
|
|
|
$account_data = \Drupal::service('user.data')->get('user', $account->id());
|
2012-11-27 22:26:22 +00:00
|
|
|
if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
|
2009-01-08 08:42:13 +00:00
|
|
|
// Validate expiration and hashed password/login.
|
2013-07-24 19:40:03 +00:00
|
|
|
if ($timestamp <= $current && $current - $timestamp < $timeout && $account->id() && $timestamp >= $account->getLastLoginTime() && $hashed_pass == user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime())) {
|
2009-01-08 08:42:13 +00:00
|
|
|
$edit = array(
|
2013-09-16 03:58:06 +00:00
|
|
|
'user_cancel_notify' => isset($account_data['cancel_notify']) ? $account_data['cancel_notify'] : \Drupal::config('user.settings')->get('notify.status_canceled'),
|
2009-01-08 08:42:13 +00:00
|
|
|
);
|
2012-11-27 22:26:22 +00:00
|
|
|
user_cancel($edit, $account->id(), $account_data['cancel_method']);
|
2009-01-08 08:42:13 +00:00
|
|
|
// Since user_cancel() is not invoked via Form API, batch processing needs
|
|
|
|
// to be invoked manually and should redirect to the front page after
|
|
|
|
// completion.
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
return batch_process('');
|
2009-01-08 08:42:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'));
|
2013-07-11 17:29:02 +00:00
|
|
|
return new RedirectResponse(url("user/" . $account->id() . "/cancel", array('absolute' => TRUE)));
|
2009-01-08 08:42:13 +00:00
|
|
|
}
|
2007-09-10 13:14:38 +00:00
|
|
|
}
|
2012-06-04 12:06:09 +00:00
|
|
|
throw new AccessDeniedHttpException();
|
2007-09-10 13:14:38 +00:00
|
|
|
}
|