Commit e21c1a13 authored by alexpott's avatar alexpott

Issue #1987894 by ParisLiakos, vijaycs85: Convert user_logout() to a new style controller.

parent f94711cd
<?php
/**
* @file
* Contains \Drupal\user\Access\LoginStatusCheck.
*/
namespace Drupal\user\Access;
use Drupal\Core\Access\AccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Determines access to routes based on login status of current user.
*/
class LoginStatusCheck implements AccessCheckInterface {
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return array_key_exists('_user_is_logged_in', $route->getRequirements());
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
return (bool) $GLOBALS['user']->uid;
}
}
......@@ -2,15 +2,16 @@
/**
* @file
* Contains \Drupal\user\UserAutocompleteController.
* Contains \Drupal\user\Controller\UserAutocompleteController.
*/
namespace Drupal\user;
namespace Drupal\user\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\ControllerInterface;
use Drupal\user\UserAutocomplete;
/**
* Controller routines for taxonomy user routes.
......@@ -79,4 +80,3 @@ public function autocompleteUserAnonymous(Request $request) {
}
}
<?php
/**
* @file
* Contains \Drupal\user\Controller\UserController.
*/
namespace Drupal\user\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Controller routines for user routes.
*/
class UserController implements ControllerInterface {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs an UserController object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('module_handler')
);
}
/**
* Logs the current user out.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirection to home page.
*/
public function logout(Request $request) {
global $user;
watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
$this->moduleHandler->invokeAll('user_logout', array($user));
// Destroy the current session, and reset $user to the anonymous user.
session_destroy();
// @todo Remove the destination check once drupal.org/node/1668866 is in.
$url = $request->query->get('destination') ?: '<front>';
return new RedirectResponse(url($url, array('absolute' => TRUE)));
}
}
......@@ -906,11 +906,9 @@ function user_menu() {
$items['user/logout'] = array(
'title' => 'Log out',
'access callback' => 'user_is_logged_in',
'page callback' => 'user_logout',
'route_name' => 'user_logout',
'weight' => 10,
'menu_name' => 'account',
'file' => 'user.pages.inc',
);
// User listing pages.
......
......@@ -164,7 +164,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
}
/**
* Menu callback; logs the current user out, and redirects to the home page.
* Logs the current user out, and redirects to the home page.
*/
function user_logout() {
global $user;
......
......@@ -5,17 +5,24 @@ user_register:
requirements:
_access_user_register: 'TRUE'
user_logout:
pattern: '/user/logout'
defaults:
_controller: '\Drupal\user\Controller\UserController::logout'
requirements:
_user_is_logged_in: 'TRUE'
user_autocomplete:
pattern: '/user/autocomplete'
defaults:
_controller: '\Drupal\user\UserAutocompleteController::autocompleteUser'
_controller: '\Drupal\user\Controller\UserAutocompleteController::autocompleteUser'
requirements:
_permission: 'access user profiles'
user_autocomplete_anonymous:
pattern: '/user/autocomplete/anonymous'
defaults:
_controller: '\Drupal\user\UserAutocompleteController::autocompleteUserAnonymous'
_controller: '\Drupal\user\Controller\UserAutocompleteController::autocompleteUserAnonymous'
requirements:
_permission: 'access user profiles'
......
......@@ -11,6 +11,10 @@ services:
class: Drupal\user\Access\RoleAccessCheck
tags:
- { name: access_check }
access_check.user.login_status:
class: Drupal\user\Access\LoginStatusCheck
tags:
- { name: access_check }
user.data:
class: Drupal\user\UserData
arguments: ['@database']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment