Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthController.php
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | abstract class PhabricatorAuthController extends PhabricatorController { | ||||
*/ | */ | ||||
protected function loginUser( | protected function loginUser( | ||||
PhabricatorUser $user, | PhabricatorUser $user, | ||||
$force_full_session = false) { | $force_full_session = false) { | ||||
$response = $this->buildLoginValidateResponse($user); | $response = $this->buildLoginValidateResponse($user); | ||||
$session_type = PhabricatorAuthSession::TYPE_WEB; | $session_type = PhabricatorAuthSession::TYPE_WEB; | ||||
$event_type = PhabricatorEventType::TYPE_AUTH_WILLLOGINUSER; | |||||
$event_data = array( | |||||
'user' => $user, | |||||
'type' => $session_type, | |||||
'response' => $response, | |||||
'shouldLogin' => true, | |||||
); | |||||
$event = id(new PhabricatorEvent($event_type, $event_data)) | |||||
->setUser($user); | |||||
PhutilEventEngine::dispatchEvent($event); | |||||
$should_login = $event->getValue('shouldLogin'); | |||||
if ($should_login) { | |||||
if ($force_full_session) { | if ($force_full_session) { | ||||
$partial_session = false; | $partial_session = false; | ||||
} else { | } else { | ||||
$partial_session = true; | $partial_session = true; | ||||
} | } | ||||
$session_key = id(new PhabricatorAuthSessionEngine()) | $session_key = id(new PhabricatorAuthSessionEngine()) | ||||
->establishSession($session_type, $user->getPHID(), $partial_session); | ->establishSession($session_type, $user->getPHID(), $partial_session); | ||||
// NOTE: We allow disabled users to login and roadblock them later, so | // NOTE: We allow disabled users to login and roadblock them later, so | ||||
// there's no check for users being disabled here. | // there's no check for users being disabled here. | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$request->setCookie( | $request->setCookie( | ||||
PhabricatorCookies::COOKIE_USERNAME, | PhabricatorCookies::COOKIE_USERNAME, | ||||
$user->getUsername()); | $user->getUsername()); | ||||
$request->setCookie( | $request->setCookie( | ||||
PhabricatorCookies::COOKIE_SESSION, | PhabricatorCookies::COOKIE_SESSION, | ||||
$session_key); | $session_key); | ||||
$this->clearRegistrationCookies(); | $this->clearRegistrationCookies(); | ||||
} | |||||
return $event->getValue('response'); | return $response; | ||||
} | } | ||||
protected function clearRegistrationCookies() { | protected function clearRegistrationCookies() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
// Clear the registration key. | // Clear the registration key. | ||||
$request->clearCookie(PhabricatorCookies::COOKIE_REGISTRATION); | $request->clearCookie(PhabricatorCookies::COOKIE_REGISTRATION); | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |