Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / auth / storage / PhabricatorAuthFactorConfig.php
blobed5a27f543884cc342cef331de74278fdfececef
1 <?php
4 final class PhabricatorAuthFactorConfig
5 extends PhabricatorAuthDAO
6 implements
7 PhabricatorPolicyInterface,
8 PhabricatorDestructibleInterface {
10 protected $userPHID;
11 protected $factorProviderPHID;
12 protected $factorName;
13 protected $factorSecret;
14 protected $properties = array();
16 private $sessionEngine;
17 private $factorProvider = self::ATTACHABLE;
18 private $mfaSyncToken;
20 protected function getConfiguration() {
21 return array(
22 self::CONFIG_SERIALIZATION => array(
23 'properties' => self::SERIALIZATION_JSON,
25 self::CONFIG_AUX_PHID => true,
26 self::CONFIG_COLUMN_SCHEMA => array(
27 'factorName' => 'text',
28 'factorSecret' => 'text',
30 self::CONFIG_KEY_SCHEMA => array(
31 'key_user' => array(
32 'columns' => array('userPHID'),
35 ) + parent::getConfiguration();
38 public function getPHIDType() {
39 return PhabricatorAuthAuthFactorPHIDType::TYPECONST;
42 public function attachFactorProvider(
43 PhabricatorAuthFactorProvider $provider) {
44 $this->factorProvider = $provider;
45 return $this;
48 public function getFactorProvider() {
49 return $this->assertAttached($this->factorProvider);
52 public function setSessionEngine(PhabricatorAuthSessionEngine $engine) {
53 $this->sessionEngine = $engine;
54 return $this;
57 public function getSessionEngine() {
58 if (!$this->sessionEngine) {
59 throw new PhutilInvalidStateException('setSessionEngine');
62 return $this->sessionEngine;
65 public function setMFASyncToken(PhabricatorAuthTemporaryToken $token) {
66 $this->mfaSyncToken = $token;
67 return $this;
70 public function getMFASyncToken() {
71 return $this->mfaSyncToken;
74 public function getAuthFactorConfigProperty($key, $default = null) {
75 return idx($this->properties, $key, $default);
78 public function setAuthFactorConfigProperty($key, $value) {
79 $this->properties[$key] = $value;
80 return $this;
83 public function newSortVector() {
84 return id(new PhutilSortVector())
85 ->addInt($this->getFactorProvider()->newStatus()->getOrder())
86 ->addInt($this->getID());
90 /* -( PhabricatorPolicyInterface )----------------------------------------- */
93 public function getCapabilities() {
94 return array(
95 PhabricatorPolicyCapability::CAN_VIEW,
96 PhabricatorPolicyCapability::CAN_EDIT,
100 public function getPolicy($capability) {
101 return $this->getUserPHID();
104 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
105 return false;
109 /* -( PhabricatorDestructibleInterface )----------------------------------- */
112 public function destroyObjectPermanently(
113 PhabricatorDestructionEngine $engine) {
115 $user = id(new PhabricatorPeopleQuery())
116 ->setViewer($engine->getViewer())
117 ->withPHIDs(array($this->getUserPHID()))
118 ->executeOne();
120 $this->delete();
122 if ($user) {
123 $user->updateMultiFactorEnrollment();