mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 10:52:41 +01:00
0727418023
Summary: Ref T4339. We have more magical cookie names than we should, move them all to a central location. Test Plan: Registered, logged in, linked account, logged out. See inlines. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4339 Differential Revision: https://secure.phabricator.com/D8041
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
final class PhabricatorLogoutController
|
|
extends PhabricatorAuthController {
|
|
|
|
public function shouldRequireLogin() {
|
|
return true;
|
|
}
|
|
|
|
public function shouldRequireEmailVerification() {
|
|
// Allow unverified users to logout.
|
|
return false;
|
|
}
|
|
|
|
public function shouldRequireEnabledUser() {
|
|
// Allow disabled users to logout.
|
|
return false;
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$log = PhabricatorUserLog::initializeNewLog(
|
|
$user,
|
|
$user->getPHID(),
|
|
PhabricatorUserLog::ACTION_LOGOUT);
|
|
$log->save();
|
|
|
|
// Destroy the user's session in the database so logout works even if
|
|
// their cookies have some issues. We'll detect cookie issues when they
|
|
// try to login again and tell them to clear any junk.
|
|
$phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
|
|
if (strlen($phsid)) {
|
|
$session = id(new PhabricatorAuthSessionQuery())
|
|
->setViewer($user)
|
|
->withSessionKeys(array($phsid))
|
|
->executeOne();
|
|
if ($session) {
|
|
$session->delete();
|
|
}
|
|
}
|
|
$request->clearCookie(PhabricatorCookies::COOKIE_SESSION);
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI('/login/');
|
|
}
|
|
|
|
if ($user->getPHID()) {
|
|
$dialog = id(new AphrontDialogView())
|
|
->setUser($user)
|
|
->setTitle(pht('Log out of Phabricator?'))
|
|
->appendChild(pht('Are you sure you want to log out?'))
|
|
->addSubmitButton(pht('Logout'))
|
|
->addCancelButton('/');
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
}
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/');
|
|
}
|
|
|
|
}
|