3 final class PhabricatorAuthInvite
4 extends PhabricatorUserDAO
5 implements PhabricatorPolicyInterface
{
8 protected $emailAddress;
9 protected $verificationHash;
10 protected $acceptedByPHID;
12 private $verificationCode;
13 private $viewerHasVerificationCode;
15 protected function getConfiguration() {
17 self
::CONFIG_AUX_PHID
=> true,
18 self
::CONFIG_COLUMN_SCHEMA
=> array(
19 'emailAddress' => 'sort128',
20 'verificationHash' => 'bytes12',
21 'acceptedByPHID' => 'phid?',
23 self
::CONFIG_KEY_SCHEMA
=> array(
24 'key_address' => array(
25 'columns' => array('emailAddress'),
29 'columns' => array('verificationHash'),
33 ) + parent
::getConfiguration();
36 public function generatePHID() {
37 return PhabricatorPHID
::generateNewPHID(
38 PhabricatorAuthInvitePHIDType
::TYPECONST
);
41 public function regenerateVerificationCode() {
42 $this->verificationCode
= Filesystem
::readRandomCharacters(16);
43 $this->verificationHash
= null;
47 public function getVerificationCode() {
48 if (!$this->verificationCode
) {
49 if ($this->verificationHash
) {
52 'Verification code can not be regenerated after an invite is '.
55 $this->regenerateVerificationCode();
57 return $this->verificationCode
;
60 public function save() {
61 if (!$this->getVerificationHash()) {
62 $hash = PhabricatorHash
::digestForIndex($this->getVerificationCode());
63 $this->setVerificationHash($hash);
66 return parent
::save();
69 public function setViewerHasVerificationCode($loaded) {
70 $this->viewerHasVerificationCode
= $loaded;
75 /* -( PhabricatorPolicyInterface )----------------------------------------- */
78 public function getCapabilities() {
80 PhabricatorPolicyCapability
::CAN_VIEW
,
84 public function getPolicy($capability) {
85 switch ($capability) {
86 case PhabricatorPolicyCapability
::CAN_VIEW
:
87 return PhabricatorPolicies
::POLICY_ADMIN
;
91 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
92 if ($this->viewerHasVerificationCode
) {
96 if ($viewer->getPHID()) {
97 if ($viewer->getPHID() == $this->getAuthorPHID()) {
98 // You can see invites you sent.
102 if ($viewer->getPHID() == $this->getAcceptedByPHID()) {
103 // You can see invites you have accepted.
111 public function describeAutomaticCapability($capability) {
113 'Invites are visible to administrators, the inviting user, users with '.
114 'an invite code, and the user who accepts the invite.');