Path: blob/master/src/applications/auth/storage/PhabricatorAuthInvite.php
12256 views
<?php12final class PhabricatorAuthInvite3extends PhabricatorUserDAO4implements PhabricatorPolicyInterface {56protected $authorPHID;7protected $emailAddress;8protected $verificationHash;9protected $acceptedByPHID;1011private $verificationCode;12private $viewerHasVerificationCode;1314protected function getConfiguration() {15return array(16self::CONFIG_AUX_PHID => true,17self::CONFIG_COLUMN_SCHEMA => array(18'emailAddress' => 'sort128',19'verificationHash' => 'bytes12',20'acceptedByPHID' => 'phid?',21),22self::CONFIG_KEY_SCHEMA => array(23'key_address' => array(24'columns' => array('emailAddress'),25'unique' => true,26),27'key_code' => array(28'columns' => array('verificationHash'),29'unique' => true,30),31),32) + parent::getConfiguration();33}3435public function generatePHID() {36return PhabricatorPHID::generateNewPHID(37PhabricatorAuthInvitePHIDType::TYPECONST);38}3940public function regenerateVerificationCode() {41$this->verificationCode = Filesystem::readRandomCharacters(16);42$this->verificationHash = null;43return $this;44}4546public function getVerificationCode() {47if (!$this->verificationCode) {48if ($this->verificationHash) {49throw new Exception(50pht(51'Verification code can not be regenerated after an invite is '.52'created.'));53}54$this->regenerateVerificationCode();55}56return $this->verificationCode;57}5859public function save() {60if (!$this->getVerificationHash()) {61$hash = PhabricatorHash::digestForIndex($this->getVerificationCode());62$this->setVerificationHash($hash);63}6465return parent::save();66}6768public function setViewerHasVerificationCode($loaded) {69$this->viewerHasVerificationCode = $loaded;70return $this;71}727374/* -( PhabricatorPolicyInterface )----------------------------------------- */757677public function getCapabilities() {78return array(79PhabricatorPolicyCapability::CAN_VIEW,80);81}8283public function getPolicy($capability) {84switch ($capability) {85case PhabricatorPolicyCapability::CAN_VIEW:86return PhabricatorPolicies::POLICY_ADMIN;87}88}8990public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {91if ($this->viewerHasVerificationCode) {92return true;93}9495if ($viewer->getPHID()) {96if ($viewer->getPHID() == $this->getAuthorPHID()) {97// You can see invites you sent.98return true;99}100101if ($viewer->getPHID() == $this->getAcceptedByPHID()) {102// You can see invites you have accepted.103return true;104}105}106107return false;108}109110public function describeAutomaticCapability($capability) {111return pht(112'Invites are visible to administrators, the inviting user, users with '.113'an invite code, and the user who accepts the invite.');114}115116}117118119