mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-27 23:18:20 +01:00
db3a0c90bb
Summary: Ref T2715. XUSR -> apps Test Plan: `phid.query` Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6558
108 lines
2.5 KiB
PHP
108 lines
2.5 KiB
PHP
<?php
|
|
|
|
final class PhabricatorExternalAccount extends PhabricatorUserDAO
|
|
implements PhabricatorPolicyInterface {
|
|
|
|
protected $userPHID;
|
|
protected $accountType;
|
|
protected $accountDomain;
|
|
protected $accountSecret;
|
|
protected $accountID;
|
|
protected $displayName;
|
|
protected $username;
|
|
protected $realName;
|
|
protected $email;
|
|
protected $emailVerified = 0;
|
|
protected $accountURI;
|
|
protected $profileImagePHID;
|
|
protected $properties = array();
|
|
|
|
private $profileImageFile;
|
|
|
|
public function getProfileImageFile() {
|
|
if ($this->profileImageFile === null) {
|
|
throw new Exception("Call attachProfileImageFile() first!");
|
|
}
|
|
return $this->profileImageFile;
|
|
}
|
|
|
|
public function attachProfileImageFile(PhabricatorFile $file) {
|
|
$this->profileImageFile = $file;
|
|
return $this;
|
|
}
|
|
|
|
public function generatePHID() {
|
|
return PhabricatorPHID::generateNewPHID(
|
|
PhabricatorPeoplePHIDTypeExternal::TYPECONST);
|
|
}
|
|
|
|
public function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_AUX_PHID => true,
|
|
self::CONFIG_SERIALIZATION => array(
|
|
'properties' => self::SERIALIZATION_JSON,
|
|
),
|
|
) + parent::getConfiguration();
|
|
}
|
|
|
|
public function getPhabricatorUser() {
|
|
$tmp_usr = id(new PhabricatorUser())
|
|
->makeEphemeral()
|
|
->setPHID($this->getPHID());
|
|
return $tmp_usr;
|
|
}
|
|
|
|
public function getProviderKey() {
|
|
return $this->getAccountType().':'.$this->getAccountDomain();
|
|
}
|
|
|
|
public function save() {
|
|
if (!$this->getAccountSecret()) {
|
|
$this->setAccountSecret(Filesystem::readRandomCharacters(32));
|
|
}
|
|
return parent::save();
|
|
}
|
|
|
|
public function setProperty($key, $value) {
|
|
$this->properties[$key] = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getProperty($key, $default = null) {
|
|
return idx($this->properties, $key, $default);
|
|
}
|
|
|
|
public function isUsableForLogin() {
|
|
$key = $this->getProviderKey();
|
|
$provider = PhabricatorAuthProvider::getEnabledProviderByKey($key);
|
|
|
|
if (!$provider) {
|
|
return false;
|
|
}
|
|
|
|
if (!$provider->shouldAllowLogin()) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
public function getCapabilities() {
|
|
return array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
);
|
|
}
|
|
|
|
public function getPolicy($capability) {
|
|
return PhabricatorPolicies::POLICY_NOONE;
|
|
}
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
return ($viewer->getPHID() == $this->getUserPHID());
|
|
}
|
|
|
|
}
|