Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/storage/PhabricatorUser.php
| <?php | <?php | ||||
| /** | /** | ||||
| * @task availability Availability | * @task availability Availability | ||||
| * @task image-cache Profile Image Cache | * @task image-cache Profile Image Cache | ||||
| * @task factors Multi-Factor Authentication | * @task factors Multi-Factor Authentication | ||||
| * @task handles Managing Handles | * @task handles Managing Handles | ||||
| * @task settings Settings | |||||
| * @task cache User Cache | * @task cache User Cache | ||||
| */ | */ | ||||
| final class PhabricatorUser | final class PhabricatorUser | ||||
| extends PhabricatorUserDAO | extends PhabricatorUserDAO | ||||
| implements | implements | ||||
| PhutilPerson, | PhutilPerson, | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorCustomFieldInterface, | PhabricatorCustomFieldInterface, | ||||
| PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
| PhabricatorSSHPublicKeyInterface, | PhabricatorSSHPublicKeyInterface, | ||||
| PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
| PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
| PhabricatorFulltextInterface, | PhabricatorFulltextInterface, | ||||
| PhabricatorConduitResultInterface { | PhabricatorConduitResultInterface { | ||||
| const SESSION_TABLE = 'phabricator_session'; | const SESSION_TABLE = 'phabricator_session'; | ||||
| const NAMETOKEN_TABLE = 'user_nametoken'; | const NAMETOKEN_TABLE = 'user_nametoken'; | ||||
| const MAXIMUM_USERNAME_LENGTH = 64; | const MAXIMUM_USERNAME_LENGTH = 64; | ||||
| protected $userName; | protected $userName; | ||||
| protected $realName; | protected $realName; | ||||
| protected $sex; | |||||
| protected $translation; | |||||
| protected $passwordSalt; | protected $passwordSalt; | ||||
| protected $passwordHash; | protected $passwordHash; | ||||
| protected $profileImagePHID; | protected $profileImagePHID; | ||||
| protected $profileImageCache; | protected $profileImageCache; | ||||
| protected $availabilityCache; | protected $availabilityCache; | ||||
| protected $availabilityCacheTTL; | protected $availabilityCacheTTL; | ||||
| protected $timezoneIdentifier = ''; | |||||
| protected $consoleEnabled = 0; | protected $consoleEnabled = 0; | ||||
| protected $consoleVisible = 0; | protected $consoleVisible = 0; | ||||
| protected $consoleTab = ''; | protected $consoleTab = ''; | ||||
| protected $conduitCertificate; | protected $conduitCertificate; | ||||
| protected $isSystemAgent = 0; | protected $isSystemAgent = 0; | ||||
| Show All 17 Lines | final class PhabricatorUser | ||||
| private $alternateCSRFString = self::ATTACHABLE; | private $alternateCSRFString = self::ATTACHABLE; | ||||
| private $session = self::ATTACHABLE; | private $session = self::ATTACHABLE; | ||||
| private $rawCacheData = array(); | private $rawCacheData = array(); | ||||
| private $usableCacheData = array(); | private $usableCacheData = array(); | ||||
| private $authorities = array(); | private $authorities = array(); | ||||
| private $handlePool; | private $handlePool; | ||||
| private $csrfSalt; | private $csrfSalt; | ||||
| private $timezoneOverride; | |||||
| protected function readField($field) { | protected function readField($field) { | ||||
| switch ($field) { | switch ($field) { | ||||
| case 'timezoneIdentifier': | |||||
| // If the user hasn't set one, guess the server's time. | |||||
| return nonempty( | |||||
| $this->timezoneIdentifier, | |||||
| date_default_timezone_get()); | |||||
| // Make sure these return booleans. | // Make sure these return booleans. | ||||
| case 'isAdmin': | case 'isAdmin': | ||||
| return (bool)$this->isAdmin; | return (bool)$this->isAdmin; | ||||
| case 'isDisabled': | case 'isDisabled': | ||||
| return (bool)$this->isDisabled; | return (bool)$this->isDisabled; | ||||
| case 'isSystemAgent': | case 'isSystemAgent': | ||||
| return (bool)$this->isSystemAgent; | return (bool)$this->isSystemAgent; | ||||
| case 'isMailingList': | case 'isMailingList': | ||||
| ▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | final class PhabricatorUser | ||||
| } | } | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
| self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
| 'userName' => 'sort64', | 'userName' => 'sort64', | ||||
| 'realName' => 'text128', | 'realName' => 'text128', | ||||
| 'sex' => 'text4?', | |||||
| 'translation' => 'text64?', | |||||
| 'passwordSalt' => 'text32?', | 'passwordSalt' => 'text32?', | ||||
| 'passwordHash' => 'text128?', | 'passwordHash' => 'text128?', | ||||
| 'profileImagePHID' => 'phid?', | 'profileImagePHID' => 'phid?', | ||||
| 'consoleEnabled' => 'bool', | 'consoleEnabled' => 'bool', | ||||
| 'consoleVisible' => 'bool', | 'consoleVisible' => 'bool', | ||||
| 'consoleTab' => 'text64', | 'consoleTab' => 'text64', | ||||
| 'conduitCertificate' => 'text255', | 'conduitCertificate' => 'text255', | ||||
| 'isSystemAgent' => 'bool', | 'isSystemAgent' => 'bool', | ||||
| 'isMailingList' => 'bool', | 'isMailingList' => 'bool', | ||||
| 'isDisabled' => 'bool', | 'isDisabled' => 'bool', | ||||
| 'isAdmin' => 'bool', | 'isAdmin' => 'bool', | ||||
| 'timezoneIdentifier' => 'text255', | |||||
| 'isEmailVerified' => 'uint32', | 'isEmailVerified' => 'uint32', | ||||
| 'isApproved' => 'uint32', | 'isApproved' => 'uint32', | ||||
| 'accountSecret' => 'bytes64', | 'accountSecret' => 'bytes64', | ||||
| 'isEnrolledInMultiFactor' => 'bool', | 'isEnrolledInMultiFactor' => 'bool', | ||||
| 'profileImageCache' => 'text255?', | 'profileImageCache' => 'text255?', | ||||
| 'availabilityCache' => 'text255?', | 'availabilityCache' => 'text255?', | ||||
| 'availabilityCacheTTL' => 'uint32?', | 'availabilityCacheTTL' => 'uint32?', | ||||
| ), | ), | ||||
| Show All 40 Lines | public function setPassword(PhutilOpaqueEnvelope $envelope) { | ||||
| } else { | } else { | ||||
| $this->setPasswordSalt(md5(Filesystem::readRandomBytes(32))); | $this->setPasswordSalt(md5(Filesystem::readRandomBytes(32))); | ||||
| $hash = $this->hashPassword($envelope); | $hash = $this->hashPassword($envelope); | ||||
| $this->setPasswordHash($hash->openEnvelope()); | $this->setPasswordHash($hash->openEnvelope()); | ||||
| } | } | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| // To satisfy PhutilPerson. | |||||
| public function getSex() { | |||||
| return $this->sex; | |||||
| } | |||||
| public function getMonogram() { | public function getMonogram() { | ||||
| return '@'.$this->getUsername(); | return '@'.$this->getUsername(); | ||||
| } | } | ||||
| public function isLoggedIn() { | public function isLoggedIn() { | ||||
| return !($this->getPHID() === null); | return !($this->getPHID() === null); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | final class PhabricatorUser | ||||
| public function loadPrimaryEmail() { | public function loadPrimaryEmail() { | ||||
| return $this->loadOneRelative( | return $this->loadOneRelative( | ||||
| new PhabricatorUserEmail(), | new PhabricatorUserEmail(), | ||||
| 'userPHID', | 'userPHID', | ||||
| 'getPHID', | 'getPHID', | ||||
| '(isPrimary = 1)'); | '(isPrimary = 1)'); | ||||
| } | } | ||||
| /* -( Settings )----------------------------------------------------------- */ | |||||
| public function getUserSetting($key) { | public function getUserSetting($key) { | ||||
| $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; | $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; | ||||
| $settings = $this->requireCacheData($settings_key); | $settings = $this->requireCacheData($settings_key); | ||||
| if (array_key_exists($key, $settings)) { | if (array_key_exists($key, $settings)) { | ||||
| return $settings[$key]; | return $settings[$key]; | ||||
| } | } | ||||
| $defaults = PhabricatorSetting::getAllEnabledSettings($this); | $defaults = PhabricatorSetting::getAllEnabledSettings($this); | ||||
| if (isset($defaults[$key])) { | if (isset($defaults[$key])) { | ||||
| return $defaults[$key]->getSettingDefaultValue(); | return $defaults[$key]->getSettingDefaultValue(); | ||||
| } | } | ||||
| return null; | return null; | ||||
| } | } | ||||
| /** | |||||
| * Test if a given setting is set to a particular value. | |||||
| * | |||||
| * @param const Setting key. | |||||
| * @param wild Value to compare. | |||||
| * @return bool True if the setting has the specified value. | |||||
| * @task settings | |||||
| */ | |||||
| public function compareUserSetting($key, $value) { | public function compareUserSetting($key, $value) { | ||||
| $actual = $this->getUserSetting($key); | $actual = $this->getUserSetting($key); | ||||
| return ($actual == $value); | return ($actual == $value); | ||||
| } | } | ||||
| public function getTranslation() { | |||||
| return $this->getUserSetting(PhabricatorTranslationSetting::SETTINGKEY); | |||||
| } | |||||
| public function getTimezoneIdentifier() { | |||||
| if ($this->timezoneOverride) { | |||||
| return $this->timezoneOverride; | |||||
| } | |||||
| return $this->getUserSetting(PhabricatorTimezoneSetting::SETTINGKEY); | |||||
| } | |||||
| /** | |||||
| * Override the user's timezone identifier. | |||||
| * | |||||
| * This is primarily useful for unit tests. | |||||
| * | |||||
| * @param string New timezone identifier. | |||||
| * @return this | |||||
| * @task settings | |||||
| */ | |||||
| public function overrideTimezoneIdentifier($identifier) { | |||||
| $this->timezoneOverride = $identifier; | |||||
| return $this; | |||||
| } | |||||
| public function getSex() { | |||||
| return $this->getUserSetting(PhabricatorPronounSetting::SETTINGKEY); | |||||
| } | |||||
| public function loadPreferences() { | public function loadPreferences() { | ||||
| if ($this->preferences) { | if ($this->preferences) { | ||||
| return $this->preferences; | return $this->preferences; | ||||
| } | } | ||||
| $preferences = null; | $preferences = null; | ||||
| if ($this->getPHID()) { | if ($this->getPHID()) { | ||||
| $preferences = id(new PhabricatorUserPreferencesQuery()) | $preferences = id(new PhabricatorUserPreferencesQuery()) | ||||
| ▲ Show 20 Lines • Show All 1,012 Lines • ▼ Show 20 Lines | if ($user_phid) { | ||||
| } | } | ||||
| } | } | ||||
| $this->usableCacheData[$key] = $usable_value; | $this->usableCacheData[$key] = $usable_value; | ||||
| return $usable_value; | return $usable_value; | ||||
| } | } | ||||
| /** | |||||
| * @task cache | |||||
| */ | |||||
| public function clearCacheData($key) { | |||||
| unset($this->rawCacheData[$key]); | |||||
| unset($this->usableCacheData[$key]); | |||||
| return $this; | |||||
| } | |||||
| } | } | ||||