2013-04-19 20:40:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorExternalAccount extends PhabricatorUserDAO {
|
|
|
|
|
2013-04-28 22:22:05 +02:00
|
|
|
protected $userPHID;
|
|
|
|
protected $accountType;
|
|
|
|
protected $accountDomain;
|
|
|
|
protected $accountSecret;
|
|
|
|
protected $accountID;
|
|
|
|
protected $displayName;
|
2013-06-14 15:55:18 +02:00
|
|
|
protected $username;
|
|
|
|
protected $realName;
|
|
|
|
protected $email;
|
|
|
|
protected $emailVerified = 0;
|
|
|
|
protected $accountURI;
|
|
|
|
protected $profileImagePHID;
|
|
|
|
protected $properties = array();
|
2013-04-19 20:40:13 +02:00
|
|
|
|
2013-04-20 04:50:21 +02:00
|
|
|
public function generatePHID() {
|
2013-04-19 20:40:13 +02:00
|
|
|
return PhabricatorPHID::generateNewPHID(
|
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_XUSR);
|
2013-04-20 04:50:21 +02:00
|
|
|
}
|
2013-04-28 22:22:05 +02:00
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2013-06-14 15:55:18 +02:00
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'properties' => self::SERIALIZATION_JSON,
|
|
|
|
),
|
2013-04-28 22:22:05 +02:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2013-05-06 20:34:48 +02:00
|
|
|
public function getPhabricatorUser() {
|
|
|
|
$tmp_usr = id(new PhabricatorUser())
|
|
|
|
->makeEphemeral()
|
|
|
|
->setPHID($this->getPHID());
|
|
|
|
return $tmp_usr;
|
|
|
|
}
|
|
|
|
|
2013-06-16 19:14:07 +02:00
|
|
|
public function getProviderKey() {
|
2013-06-16 19:15:16 +02:00
|
|
|
return $this->getAccountType().':'.$this->getAccountDomain();
|
2013-06-16 19:14:07 +02:00
|
|
|
}
|
|
|
|
|
2013-06-14 15:55:18 +02:00
|
|
|
public function save() {
|
|
|
|
if (!$this->getAccountSecret()) {
|
|
|
|
$this->setAccountSecret(Filesystem::readRandomCharacters(32));
|
|
|
|
}
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
2013-06-16 19:14:07 +02:00
|
|
|
public function setProperty($key, $value) {
|
|
|
|
$this->properties[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProperty($key, $default = null) {
|
|
|
|
return idx($this->properties, $key, $default);
|
|
|
|
}
|
|
|
|
|
2013-06-17 15:12:45 +02:00
|
|
|
public function isUsableForLogin() {
|
|
|
|
$key = $this->getProviderKey();
|
|
|
|
$provider = PhabricatorAuthProvider::getEnabledProviderByKey($key);
|
|
|
|
|
|
|
|
if (!$provider) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$provider->shouldAllowLogin()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-19 20:40:13 +02:00
|
|
|
}
|