Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthStartController.php
Show All 23 Lines | public function handleRequest(AphrontRequest $request) { | ||||
} | } | ||||
// If the user gets this far, they aren't logged in, so if they have a | // If the user gets this far, they aren't logged in, so if they have a | ||||
// user session token we can conclude that it's invalid: if it was valid, | // user session token we can conclude that it's invalid: if it was valid, | ||||
// they'd have been logged in above and never made it here. Try to clear | // they'd have been logged in above and never made it here. Try to clear | ||||
// it and warn the user they may need to nuke their cookies. | // it and warn the user they may need to nuke their cookies. | ||||
$session_token = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); | $session_token = $request->getCookie(PhabricatorCookies::COOKIE_SESSION); | ||||
$did_clear = $request->getStr('cleared'); | |||||
if (strlen($session_token)) { | if (strlen($session_token)) { | ||||
$kind = PhabricatorAuthSessionEngine::getSessionKindFromToken( | $kind = PhabricatorAuthSessionEngine::getSessionKindFromToken( | ||||
$session_token); | $session_token); | ||||
switch ($kind) { | switch ($kind) { | ||||
case PhabricatorAuthSessionEngine::KIND_ANONYMOUS: | case PhabricatorAuthSessionEngine::KIND_ANONYMOUS: | ||||
// If this is an anonymous session. It's expected that they won't | // If this is an anonymous session. It's expected that they won't | ||||
// be logged in, so we can just continue. | // be logged in, so we can just continue. | ||||
break; | break; | ||||
default: | default: | ||||
// The session cookie is invalid, so clear it. | // The session cookie is invalid, so try to clear it. | ||||
$request->clearCookie(PhabricatorCookies::COOKIE_USERNAME); | $request->clearCookie(PhabricatorCookies::COOKIE_USERNAME); | ||||
$request->clearCookie(PhabricatorCookies::COOKIE_SESSION); | $request->clearCookie(PhabricatorCookies::COOKIE_SESSION); | ||||
// We've previously tried to clear the cookie but we ended up back | |||||
// here, so it didn't work. Hard fatal instead of trying again. | |||||
if ($did_clear) { | |||||
return $this->renderError( | return $this->renderError( | ||||
pht( | pht( | ||||
'Your login session is invalid. Try reloading the page and '. | 'Your login session is invalid, and clearing the session '. | ||||
'logging in again. If that does not work, clear your browser '. | 'cookie was unsuccessful. Try clearing your browser cookies.')); | ||||
'cookies.')); | |||||
} | } | ||||
$redirect_uri = $request->getRequestURI(); | |||||
$redirect_uri->setQueryParam('cleared', 1); | |||||
return id(new AphrontRedirectResponse())->setURI($redirect_uri); | |||||
} | |||||
} | |||||
// If we just cleared the session cookie and it worked, clean up after | |||||
// ourselves by redirecting to get rid of the "cleared" parameter. The | |||||
// the workflow will continue normally. | |||||
if ($did_clear) { | |||||
$redirect_uri = $request->getRequestURI(); | |||||
$redirect_uri->setQueryParam('cleared', null); | |||||
return id(new AphrontRedirectResponse())->setURI($redirect_uri); | |||||
} | } | ||||
$providers = PhabricatorAuthProvider::getAllEnabledProviders(); | $providers = PhabricatorAuthProvider::getAllEnabledProviders(); | ||||
foreach ($providers as $key => $provider) { | foreach ($providers as $key => $provider) { | ||||
if (!$provider->shouldAllowLogin()) { | if (!$provider->shouldAllowLogin()) { | ||||
unset($providers[$key]); | unset($providers[$key]); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 209 Lines • Show Last 20 Lines |