Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/controller/PhabricatorLogoutController.php
12256 views
1
<?php
2
3
final class PhabricatorLogoutController
4
extends PhabricatorAuthController {
5
6
public function shouldRequireLogin() {
7
// See T13310. We allow access to the "Logout" controller even if you are
8
// not logged in: otherwise, users who do not have access to any Spaces can
9
// not log out.
10
11
// When you try to access a controller which requires you be logged in,
12
// and you do not have access to any Spaces, an access check fires first
13
// and prevents access with a "No Access to Spaces" error. If this
14
// controller requires users be logged in, users who are trying to log out
15
// and also have no access to Spaces get the error instead of a logout
16
// workflow and are trapped.
17
18
// By permitting access to this controller even if you are not logged in,
19
// we bypass the Spaces check and allow users who have no access to Spaces
20
// to log out.
21
22
// This incidentally allows users who are already logged out to access the
23
// controller, but this is harmless: we just no-op these requests.
24
25
return false;
26
}
27
28
public function shouldRequireEmailVerification() {
29
// Allow unverified users to logout.
30
return false;
31
}
32
33
public function shouldRequireEnabledUser() {
34
// Allow disabled users to logout.
35
return false;
36
}
37
38
public function shouldAllowPartialSessions() {
39
return true;
40
}
41
42
public function shouldAllowLegallyNonCompliantUsers() {
43
return true;
44
}
45
46
public function handleRequest(AphrontRequest $request) {
47
$viewer = $this->getViewer();
48
49
if ($request->isFormPost()) {
50
// Destroy the user's session in the database so logout works even if
51
// their cookies have some issues. We'll detect cookie issues when they
52
// try to login again and tell them to clear any junk.
53
$phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
54
if (strlen($phsid)) {
55
$session = id(new PhabricatorAuthSessionQuery())
56
->setViewer($viewer)
57
->withSessionKeys(array($phsid))
58
->executeOne();
59
60
if ($session) {
61
$engine = new PhabricatorAuthSessionEngine();
62
$engine->logoutSession($viewer, $session);
63
}
64
}
65
$request->clearCookie(PhabricatorCookies::COOKIE_SESSION);
66
67
return id(new AphrontRedirectResponse())
68
->setURI('/auth/loggedout/');
69
}
70
71
72
if ($viewer->getPHID()) {
73
$dialog = $this->newDialog()
74
->setTitle(pht('Log Out?'))
75
->appendParagraph(pht('Are you sure you want to log out?'))
76
->addCancelButton('/');
77
78
$configs = id(new PhabricatorAuthProviderConfigQuery())
79
->setViewer(PhabricatorUser::getOmnipotentUser())
80
->execute();
81
if (!$configs) {
82
$dialog
83
->appendRemarkup(
84
pht(
85
'WARNING: You have not configured any authentication providers '.
86
'yet, so your account has no login credentials. If you log out '.
87
'now, you will not be able to log back in normally.'))
88
->appendParagraph(
89
pht(
90
'To enable the login flow, follow setup guidance and configure '.
91
'at least one authentication provider, then associate '.
92
'credentials with your account. After completing these steps, '.
93
'you will be able to log out and log back in normally.'))
94
->appendParagraph(
95
pht(
96
'If you log out now, you can still regain access to your '.
97
'account later by using the account recovery workflow. The '.
98
'login screen will prompt you with recovery instructions.'));
99
100
$button = pht('Log Out Anyway');
101
} else {
102
$button = pht('Log Out');
103
}
104
105
$dialog->addSubmitButton($button);
106
return $dialog;
107
}
108
109
return id(new AphrontRedirectResponse())->setURI('/');
110
}
111
112
}
113
114