Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/provider/PhabricatorAuthProvider.php
| Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | abstract class PhabricatorAuthProvider extends Phobject { | ||||
| public function createProviders() { | public function createProviders() { | ||||
| return array($this); | return array($this); | ||||
| } | } | ||||
| protected function willSaveAccount(PhabricatorExternalAccount $account) { | protected function willSaveAccount(PhabricatorExternalAccount $account) { | ||||
| return; | return; | ||||
| } | } | ||||
| public function willRegisterAccount(PhabricatorExternalAccount $account) { | final protected function newExternalAccountForIdentifiers( | ||||
| return; | array $identifiers) { | ||||
| } | |||||
| protected function loadOrCreateAccount(array $identifiers) { | |||||
| assert_instances_of($identifiers, 'PhabricatorExternalAccountIdentifier'); | assert_instances_of($identifiers, 'PhabricatorExternalAccountIdentifier'); | ||||
| if (!$identifiers) { | if (!$identifiers) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Authentication provider (of class "%s") is attempting to '. | 'Authentication provider (of class "%s") is attempting to '. | ||||
| 'load or create an external account, but provided no account '. | 'load or create an external account, but provided no account '. | ||||
| 'identifiers.', | 'identifiers.', | ||||
| Show All 27 Lines | if (!$accounts) { | ||||
| pht( | pht( | ||||
| 'Authentication provider (of class "%s") is attempting to load '. | 'Authentication provider (of class "%s") is attempting to load '. | ||||
| 'or create an external account, but provided a list of '. | 'or create an external account, but provided a list of '. | ||||
| 'account identifiers which map to more than one account: %s.', | 'account identifiers which map to more than one account: %s.', | ||||
| get_class($this), | get_class($this), | ||||
| implode(', ', $raw_identifiers))); | implode(', ', $raw_identifiers))); | ||||
| } | } | ||||
| return $this->didUpdateAccount($account); | |||||
| } | |||||
| final protected function newExternalAccountForUser(PhabricatorUser $user) { | |||||
| $config = $this->getProviderConfig(); | |||||
| // When a user logs in with a provider like username/password, they | |||||
| // always already have a Phabricator account (since there's no way they | |||||
| // could have a username otherwise). | |||||
| // These users should never go to registration, so we're building a | |||||
| // dummy "external account" which just links directly back to their | |||||
| // internal account. | |||||
| $account = id(new PhabricatorExternalAccountQuery()) | |||||
| ->setViewer($user) | |||||
| ->withProviderConfigPHIDs(array($config->getPHID())) | |||||
| ->withUserPHIDs(array($user->getPHID())) | |||||
| ->executeOne(); | |||||
| if (!$account) { | |||||
| $account = $this->newExternalAccount() | |||||
| ->setUserPHID($user->getPHID()); | |||||
| // TODO: Remove this when "accountID" is removed; the column is not | |||||
| // nullable. | |||||
| $account->setAccountID(''); | |||||
| } | |||||
| return $this->didUpdateAccount($account); | |||||
| } | |||||
| private function didUpdateAccount(PhabricatorExternalAccount $account) { | |||||
| $adapter = $this->getAdapter(); | $adapter = $this->getAdapter(); | ||||
| $account->setUsername($adapter->getAccountName()); | $account->setUsername($adapter->getAccountName()); | ||||
| $account->setRealName($adapter->getAccountRealName()); | $account->setRealName($adapter->getAccountRealName()); | ||||
| $account->setEmail($adapter->getAccountEmail()); | $account->setEmail($adapter->getAccountEmail()); | ||||
| $account->setAccountURI($adapter->getAccountURI()); | $account->setAccountURI($adapter->getAccountURI()); | ||||
| $account->setProfileImagePHID(null); | $account->setProfileImagePHID(null); | ||||
| ▲ Show 20 Lines • Show All 303 Lines • Show Last 20 Lines | |||||