2011-01-31 03:52:29 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorLogoutController
|
|
|
|
extends PhabricatorAuthController {
|
2011-01-31 03:52:29 +01:00
|
|
|
|
|
|
|
public function shouldRequireLogin() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Allow installs to require email verification
Summary:
Allow installs to require users to verify email addresses before they can use Phabricator. If a user logs in without a verified email address, they're given instructions to verify their address.
This isn't too useful on its own since we don't actually have arbitrary email registration, but the next step is to allow installs to restrict email to only some domains (e.g., @mycompany.com).
Test Plan:
- Verification
- Set verification requirement to `true`.
- Tried to use Phabricator with an unverified account, was told to verify.
- Tried to use Conduit, was given a verification error.
- Verified account, used Phabricator.
- Unverified account, reset password, verified implicit verification, used Phabricator.
- People Admin Interface
- Viewed as admin. Clicked "Administrate User".
- Viewed as non-admin
- Sanity Checks
- Used Conduit normally from web/CLI with a verified account.
- Logged in/out.
- Sent password reset email.
- Created a new user.
- Logged in with an unverified user but with the configuration set to off.
Reviewers: btrahan, vrana, jungejason
Reviewed By: btrahan
CC: aran, csilvers
Maniphest Tasks: T1184
Differential Revision: https://secure.phabricator.com/D2520
2012-05-21 21:47:38 +02:00
|
|
|
public function shouldRequireEmailVerification() {
|
|
|
|
// Allow unverified users to logout.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-12 19:06:54 +02:00
|
|
|
public function shouldRequireEnabledUser() {
|
|
|
|
// Allow disabled users to logout.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-01 19:23:02 +02:00
|
|
|
public function shouldAllowPartialSessions() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-13 00:22:56 +01:00
|
|
|
public function shouldAllowLegallyNonCompliantUsers() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-06 19:50:36 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2015-08-02 01:49:27 +02:00
|
|
|
$viewer = $this->getViewer();
|
2011-01-31 03:52:29 +01:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2011-09-08 23:16:59 +02:00
|
|
|
// 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.
|
2014-01-23 23:01:35 +01:00
|
|
|
$phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
|
|
|
|
if (strlen($phsid)) {
|
2014-01-14 22:22:27 +01:00
|
|
|
$session = id(new PhabricatorAuthSessionQuery())
|
2015-08-02 01:49:27 +02:00
|
|
|
->setViewer($viewer)
|
2014-01-14 22:22:27 +01:00
|
|
|
->withSessionKeys(array($phsid))
|
|
|
|
->executeOne();
|
2016-04-03 19:04:10 +02:00
|
|
|
|
2014-01-14 22:22:27 +01:00
|
|
|
if ($session) {
|
2016-04-03 19:04:10 +02:00
|
|
|
$engine = new PhabricatorAuthSessionEngine();
|
|
|
|
$engine->logoutSession($viewer, $session);
|
2014-01-14 22:22:27 +01:00
|
|
|
}
|
2011-09-08 23:16:59 +02:00
|
|
|
}
|
2014-01-23 23:01:35 +01:00
|
|
|
$request->clearCookie(PhabricatorCookies::COOKIE_SESSION);
|
2011-09-08 23:16:59 +02:00
|
|
|
|
2011-01-31 03:52:29 +01:00
|
|
|
return id(new AphrontRedirectResponse())
|
2015-02-06 19:50:36 +01:00
|
|
|
->setURI('/auth/loggedout/');
|
2011-01-31 03:52:29 +01:00
|
|
|
}
|
|
|
|
|
2015-08-02 01:49:27 +02:00
|
|
|
if ($viewer->getPHID()) {
|
2016-03-31 22:45:02 +02:00
|
|
|
return $this->newDialog()
|
2013-01-27 01:17:44 +01:00
|
|
|
->setTitle(pht('Log out of Phabricator?'))
|
2014-01-23 23:01:35 +01:00
|
|
|
->appendChild(pht('Are you sure you want to log out?'))
|
2013-01-27 01:17:44 +01:00
|
|
|
->addSubmitButton(pht('Logout'))
|
2012-07-25 22:58:49 +02:00
|
|
|
->addCancelButton('/');
|
|
|
|
}
|
|
|
|
|
2011-01-31 03:52:29 +01:00
|
|
|
return id(new AphrontRedirectResponse())->setURI('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|