Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/controller/PhabricatorAuthController.php
Show All 39 Lines | abstract class PhabricatorAuthController extends PhabricatorController { | ||||
* Log a user into a web session and return an @{class:AphrontResponse} which | * Log a user into a web session and return an @{class:AphrontResponse} which | ||||
* corresponds to continuing the login process. | * corresponds to continuing the login process. | ||||
* | * | ||||
* Normally, this is a redirect to the validation controller which makes sure | * Normally, this is a redirect to the validation controller which makes sure | ||||
* the user's cookies are set. However, event listeners can intercept this | * the user's cookies are set. However, event listeners can intercept this | ||||
* event and do something else if they prefer. | * event and do something else if they prefer. | ||||
* | * | ||||
* @param PhabricatorUser User to log the viewer in as. | * @param PhabricatorUser User to log the viewer in as. | ||||
* @param bool True to issue a full session immediately, bypassing MFA. | |||||
* @return AphrontResponse Response which continues the login process. | * @return AphrontResponse Response which continues the login process. | ||||
*/ | */ | ||||
protected function loginUser(PhabricatorUser $user) { | protected function loginUser( | ||||
PhabricatorUser $user, | |||||
$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_type = PhabricatorEventType::TYPE_AUTH_WILLLOGINUSER; | ||||
$event_data = array( | $event_data = array( | ||||
'user' => $user, | 'user' => $user, | ||||
'type' => $session_type, | 'type' => $session_type, | ||||
'response' => $response, | 'response' => $response, | ||||
'shouldLogin' => true, | 'shouldLogin' => true, | ||||
); | ); | ||||
$event = id(new PhabricatorEvent($event_type, $event_data)) | $event = id(new PhabricatorEvent($event_type, $event_data)) | ||||
->setUser($user); | ->setUser($user); | ||||
PhutilEventEngine::dispatchEvent($event); | PhutilEventEngine::dispatchEvent($event); | ||||
$should_login = $event->getValue('shouldLogin'); | $should_login = $event->getValue('shouldLogin'); | ||||
if ($should_login) { | if ($should_login) { | ||||
if ($force_full_session) { | |||||
$partial_session = false; | |||||
} else { | |||||
$partial_session = true; | |||||
} | |||||
$session_key = id(new PhabricatorAuthSessionEngine()) | $session_key = id(new PhabricatorAuthSessionEngine()) | ||||
->establishSession($session_type, $user->getPHID(), $partial = true); | ->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()); | ||||
▲ Show 20 Lines • Show All 217 Lines • Show Last 20 Lines |