Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/engine/PhabricatorAuthSessionEngine.php
| Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | public function loadUserForSession($session_type, $session_token) { | ||||
| } | } | ||||
| $session_table = new PhabricatorAuthSession(); | $session_table = new PhabricatorAuthSession(); | ||||
| $user_table = new PhabricatorUser(); | $user_table = new PhabricatorUser(); | ||||
| $conn_r = $session_table->establishConnection('r'); | $conn_r = $session_table->establishConnection('r'); | ||||
| $session_key = PhabricatorHash::digest($session_token); | $session_key = PhabricatorHash::digest($session_token); | ||||
| $cache_parts = $this->getUserCacheQueryParts($conn_r); | $cache_parts = $this->getUserCacheQueryParts($conn_r); | ||||
| list($cache_selects, $cache_joins, $cache_map) = $cache_parts; | list($cache_selects, $cache_joins, $cache_map, $types_map) = $cache_parts; | ||||
| $info = queryfx_one( | $info = queryfx_one( | ||||
| $conn_r, | $conn_r, | ||||
| 'SELECT | 'SELECT | ||||
| s.id AS s_id, | s.id AS s_id, | ||||
| s.sessionExpires AS s_sessionExpires, | s.sessionExpires AS s_sessionExpires, | ||||
| s.sessionStart AS s_sessionStart, | s.sessionStart AS s_sessionStart, | ||||
| s.highSecurityUntil AS s_highSecurityUntil, | s.highSecurityUntil AS s_highSecurityUntil, | ||||
| Show All 32 Lines | foreach ($info as $key => $value) { | ||||
| unset($info[$key]); | unset($info[$key]); | ||||
| $cache_raw[$cache_map[$key]] = $value; | $cache_raw[$cache_map[$key]] = $value; | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| $user = $user_table->loadFromArray($info); | $user = $user_table->loadFromArray($info); | ||||
| $cache_raw = $this->filterRawCacheData($user, $types_map, $cache_raw); | |||||
| $user->attachRawCacheData($cache_raw); | $user->attachRawCacheData($cache_raw); | ||||
| $user->setAllowInlineCacheGeneration(true); | $user->setAllowInlineCacheGeneration(true); | ||||
| switch ($session_type) { | switch ($session_type) { | ||||
| case PhabricatorAuthSession::TYPE_WEB: | case PhabricatorAuthSession::TYPE_WEB: | ||||
| // Explicitly prevent bots and mailing lists from establishing web | // Explicitly prevent bots and mailing lists from establishing web | ||||
| // sessions. It's normally impossible to attach authentication to these | // sessions. It's normally impossible to attach authentication to these | ||||
| // accounts, and likewise impossible to generate sessions, but it's | // accounts, and likewise impossible to generate sessions, but it's | ||||
| ▲ Show 20 Lines • Show All 583 Lines • ▼ Show 20 Lines | /* -( User Cache )--------------------------------------------------------- */ | ||||
| * @task cache | * @task cache | ||||
| */ | */ | ||||
| private function getUserCacheQueryParts(AphrontDatabaseConnection $conn) { | private function getUserCacheQueryParts(AphrontDatabaseConnection $conn) { | ||||
| $cache_selects = array(); | $cache_selects = array(); | ||||
| $cache_joins = array(); | $cache_joins = array(); | ||||
| $cache_map = array(); | $cache_map = array(); | ||||
| $keys = array(); | $keys = array(); | ||||
| $types_map = array(); | |||||
| $cache_types = PhabricatorUserCacheType::getAllCacheTypes(); | $cache_types = PhabricatorUserCacheType::getAllCacheTypes(); | ||||
| foreach ($cache_types as $cache_type) { | foreach ($cache_types as $cache_type) { | ||||
| foreach ($cache_type->getAutoloadKeys() as $autoload_key) { | foreach ($cache_type->getAutoloadKeys() as $autoload_key) { | ||||
| $keys[] = $autoload_key; | $keys[] = $autoload_key; | ||||
| $types_map[$autoload_key] = $cache_type; | |||||
| } | } | ||||
| } | } | ||||
| $cache_table = id(new PhabricatorUserCache())->getTableName(); | $cache_table = id(new PhabricatorUserCache())->getTableName(); | ||||
| $cache_idx = 1; | $cache_idx = 1; | ||||
| foreach ($keys as $key) { | foreach ($keys as $key) { | ||||
| $join_as = 'ucache_'.$cache_idx; | $join_as = 'ucache_'.$cache_idx; | ||||
| Show All 27 Lines | private function getUserCacheQueryParts(AphrontDatabaseConnection $conn) { | ||||
| } | } | ||||
| if ($cache_joins) { | if ($cache_joins) { | ||||
| $cache_joins = implode(' ', $cache_joins); | $cache_joins = implode(' ', $cache_joins); | ||||
| } else { | } else { | ||||
| $cache_joins = ''; | $cache_joins = ''; | ||||
| } | } | ||||
| return array($cache_selects, $cache_joins, $cache_map); | return array($cache_selects, $cache_joins, $cache_map, $types_map); | ||||
| } | |||||
| private function filterRawCacheData( | |||||
| PhabricatorUser $user, | |||||
| array $types_map, | |||||
| array $cache_raw) { | |||||
| foreach ($cache_raw as $cache_key => $cache_data) { | |||||
| $type = $types_map[$cache_key]; | |||||
| if ($type->shouldValidateRawCacheData()) { | |||||
| if (!$type->isRawCacheDataValid($user, $cache_key, $cache_data)) { | |||||
| unset($cache_raw[$cache_key]); | |||||
| } | |||||
| } | |||||
| } | |||||
| return $cache_raw; | |||||
| } | } | ||||
| } | } | ||||