diff options
author | Lukas Reschke <lukas@owncloud.com> | 2016-04-18 12:14:07 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2016-04-18 21:21:52 +0200 |
commit | 8222ad515706d62cceb14428c959b83a69ccbc8b (patch) | |
tree | 1fb2a2a86d2eaebca7e48366a7b3e50d3f3dbe7f /core | |
parent | 51975d360a93daba3b2681136a77b8d7078719e9 (diff) | |
download | nextcloud-server-8222ad515706d62cceb14428c959b83a69ccbc8b.tar.gz nextcloud-server-8222ad515706d62cceb14428c959b83a69ccbc8b.zip |
Move logout to controller
Testable code. Yay.
Diffstat (limited to 'core')
-rw-r--r-- | core/Application.php | 3 | ||||
-rw-r--r-- | core/Controller/LoginController.php | 24 | ||||
-rw-r--r-- | core/routes.php | 1 |
3 files changed, 26 insertions, 2 deletions
diff --git a/core/Application.php b/core/Application.php index 805208d4696..0a54386a2ce 100644 --- a/core/Application.php +++ b/core/Application.php @@ -97,7 +97,8 @@ class Application extends App { $c->query('UserManager'), $c->query('Config'), $c->query('Session'), - $c->query('UserSession') + $c->query('UserSession'), + $c->query('URLGenerator') ); }); diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index faed7e291ea..796706d364a 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -28,6 +28,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IRequest; use OCP\ISession; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -41,6 +42,8 @@ class LoginController extends Controller { private $session; /** @var IUserSession */ private $userSession; + /** @var IURLGenerator */ + private $urlGenerator; /** * @param string $appName @@ -49,18 +52,37 @@ class LoginController extends Controller { * @param IConfig $config * @param ISession $session * @param IUserSession $userSession + * @param IURLGenerator $urlGenerator */ function __construct($appName, IRequest $request, IUserManager $userManager, IConfig $config, ISession $session, - IUserSession $userSession) { + IUserSession $userSession, + IURLGenerator $urlGenerator) { parent::__construct($appName, $request); $this->userManager = $userManager; $this->config = $config; $this->session = $session; $this->userSession = $userSession; + $this->urlGenerator = $urlGenerator; + } + + /** + * @NoAdminRequired + * @UseSession + * + * @return RedirectResponse + */ + public function logout() { + $loginToken = $this->request->getCookie('oc_token'); + if (!is_null($loginToken)) { + $this->config->deleteUserValue($this->userSession->getUser()->getUID(), 'login_token', $loginToken); + } + $this->userSession->logout(); + + return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); } /** diff --git a/core/routes.php b/core/routes.php index bcad9d0dad3..2b7a19f7d86 100644 --- a/core/routes.php +++ b/core/routes.php @@ -43,6 +43,7 @@ $application->registerRoutes($this, [ ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], + ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], ] ]); |