Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/provider/PhabricatorAuthProvider.php
| Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | final protected function newExternalAccountForIdentifiers( | ||||
| $config = $this->getProviderConfig(); | $config = $this->getProviderConfig(); | ||||
| $viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
| $raw_identifiers = mpull($identifiers, 'getIdentifierRaw'); | $raw_identifiers = mpull($identifiers, 'getIdentifierRaw'); | ||||
| $accounts = id(new PhabricatorExternalAccountQuery()) | $accounts = id(new PhabricatorExternalAccountQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withProviderConfigPHIDs(array($config->getPHID())) | ->withProviderConfigPHIDs(array($config->getPHID())) | ||||
| ->withAccountIDs($raw_identifiers) | ->withRawAccountIdentifiers($raw_identifiers) | ||||
| ->needAccountIdentifiers(true) | ->needAccountIdentifiers(true) | ||||
| ->execute(); | ->execute(); | ||||
| if (!$accounts) { | if (!$accounts) { | ||||
| $account = $this->newExternalAccount() | $account = $this->newExternalAccount(); | ||||
| ->setAccountID(head($raw_identifiers)); | |||||
| } else if (count($accounts) === 1) { | } else if (count($accounts) === 1) { | ||||
| $account = head($accounts); | $account = head($accounts); | ||||
| } else { | } else { | ||||
| throw new Exception( | throw new Exception( | ||||
| 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.', | ||||
| Show All 29 Lines | final protected function newExternalAccountForUser(PhabricatorUser $user) { | ||||
| $account = id(new PhabricatorExternalAccountQuery()) | $account = id(new PhabricatorExternalAccountQuery()) | ||||
| ->setViewer($user) | ->setViewer($user) | ||||
| ->withProviderConfigPHIDs(array($config->getPHID())) | ->withProviderConfigPHIDs(array($config->getPHID())) | ||||
| ->withUserPHIDs(array($user->getPHID())) | ->withUserPHIDs(array($user->getPHID())) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$account) { | if (!$account) { | ||||
| $account = $this->newExternalAccount() | $account = $this->newExternalAccount() | ||||
| ->setUserPHID($user->getPHID()); | ->setUserPHID($user->getPHID()); | ||||
| // TODO: Remove this when "accountID" is removed; the column is not | |||||
| // nullable. | |||||
| $account->setAccountID(''); | |||||
| } | } | ||||
| return $this->didUpdateAccount($account); | return $this->didUpdateAccount($account); | ||||
| } | } | ||||
| private function didUpdateAccount(PhabricatorExternalAccount $account) { | private function didUpdateAccount(PhabricatorExternalAccount $account) { | ||||
| $adapter = $this->getAdapter(); | $adapter = $this->getAdapter(); | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | protected function newExternalAccount() { | ||||
| // TODO: Remove this when these columns are removed. They no longer have | // TODO: Remove this when these columns are removed. They no longer have | ||||
| // readers or writers (other than this callsite). | // readers or writers (other than this callsite). | ||||
| $account | $account | ||||
| ->setAccountType($adapter->getAdapterType()) | ->setAccountType($adapter->getAdapterType()) | ||||
| ->setAccountDomain($adapter->getAdapterDomain()); | ->setAccountDomain($adapter->getAdapterDomain()); | ||||
| // TODO: Remove this when "accountID" is removed; the column is not | |||||
| // nullable. | |||||
| $account->setAccountID(''); | |||||
| return $account; | return $account; | ||||
| } | } | ||||
| public function getLoginOrder() { | public function getLoginOrder() { | ||||
| return '500-'.$this->getProviderName(); | return '500-'.$this->getProviderName(); | ||||
| } | } | ||||
| protected function getLoginIcon() { | protected function getLoginIcon() { | ||||
| ▲ Show 20 Lines • Show All 216 Lines • Show Last 20 Lines | |||||