1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-28 20:18:13 +01:00

Replace "web" and "conduit" magic session strings with constants

Summary: Ref T4310. Ref T3720. We use bare strings to refer to session types in several places right now; use constants instead.

Test Plan: grep; logged out; logged in; ran Conduit commands.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4310, T3720

Differential Revision: https://secure.phabricator.com/D7963
This commit is contained in:
epriestley 2014-01-14 13:22:34 -08:00
parent eef314b701
commit d392a8f157
7 changed files with 14 additions and 8 deletions

View file

@ -65,7 +65,7 @@ abstract class PhabricatorAuthController extends PhabricatorController {
protected function loginUser(PhabricatorUser $user) { protected function loginUser(PhabricatorUser $user) {
$response = $this->buildLoginValidateResponse($user); $response = $this->buildLoginValidateResponse($user);
$session_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(

View file

@ -36,7 +36,8 @@ final class PhabricatorAuthSessionEngine extends Phobject {
* You can configure the maximum number of concurrent sessions for various * You can configure the maximum number of concurrent sessions for various
* session types in the Phabricator configuration. * session types in the Phabricator configuration.
* *
* @param string Session type, like "web". * @param const Session type constant (see
* @{class:PhabricatorAuthSession}).
* @param phid Identity to establish a session for, usually a user PHID. * @param phid Identity to establish a session for, usually a user PHID.
* @return string Newly generated session key. * @return string Newly generated session key.
*/ */
@ -56,10 +57,10 @@ final class PhabricatorAuthSessionEngine extends Phobject {
$session_limit = 1; $session_limit = 1;
switch ($session_type) { switch ($session_type) {
case 'web': case PhabricatorAuthSession::TYPE_WEB:
$session_limit = PhabricatorEnv::getEnvConfig('auth.sessions.web'); $session_limit = PhabricatorEnv::getEnvConfig('auth.sessions.web');
break; break;
case 'conduit': case PhabricatorAuthSession::TYPE_CONDUIT:
$session_limit = PhabricatorEnv::getEnvConfig('auth.sessions.conduit'); $session_limit = PhabricatorEnv::getEnvConfig('auth.sessions.conduit');
break; break;
default: default:

View file

@ -3,6 +3,9 @@
final class PhabricatorAuthSession extends PhabricatorAuthDAO final class PhabricatorAuthSession extends PhabricatorAuthDAO
implements PhabricatorPolicyInterface { implements PhabricatorPolicyInterface {
const TYPE_WEB = 'web';
const TYPE_CONDUIT = 'conduit';
protected $userPHID; protected $userPHID;
protected $type; protected $type;
protected $sessionKey; protected $sessionKey;

View file

@ -38,7 +38,7 @@ abstract class PhabricatorController extends AphrontController {
$phsid = $request->getCookie('phsid'); $phsid = $request->getCookie('phsid');
if ($phsid) { if ($phsid) {
$session_user = id(new PhabricatorAuthSessionEngine()) $session_user = id(new PhabricatorAuthSessionEngine())
->loadUserForSession('web', $phsid); ->loadUserForSession(PhabricatorAuthSession::TYPE_WEB, $phsid);
if ($session_user) { if ($session_user) {
$user = $session_user; $user = $session_user;
} }

View file

@ -280,7 +280,7 @@ final class PhabricatorConduitAPIController
} }
$user = id(new PhabricatorAuthSessionEngine()) $user = id(new PhabricatorAuthSessionEngine())
->loadUserForSession('conduit', $session_key); ->loadUserForSession(PhabricatorAuthSession::TYPE_CONDUIT, $session_key);
if (!$user) { if (!$user) {
return array( return array(

View file

@ -143,7 +143,9 @@ final class ConduitAPI_conduit_connect_Method extends ConduitAPIMethod {
throw new ConduitException('ERR-INVALID-CERTIFICATE'); throw new ConduitException('ERR-INVALID-CERTIFICATE');
} }
$session_key = id(new PhabricatorAuthSessionEngine()) $session_key = id(new PhabricatorAuthSessionEngine())
->establishSession('conduit', $user->getPHID()); ->establishSession(
PhabricatorAuthSession::TYPE_CONDUIT,
$user->getPHID());
} else { } else {
throw new ConduitException('ERR-NO-CERTIFICATE'); throw new ConduitException('ERR-NO-CERTIFICATE');
} }

View file

@ -37,7 +37,7 @@ final class PhabricatorSettingsPanelConduit
$sessions = id(new PhabricatorAuthSessionQuery()) $sessions = id(new PhabricatorAuthSessionQuery())
->setViewer($user) ->setViewer($user)
->withIdentityPHIDs(array($user->getPHID())) ->withIdentityPHIDs(array($user->getPHID()))
->withSessionTypes(array('conduit')) ->withSessionTypes(array(PhabricatorAuthSession::TYPE_CONDUIT))
->execute(); ->execute();
foreach ($sessions as $session) { foreach ($sessions as $session) {
$session->delete(); $session->delete();