mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Internalize storage access for PhabricatorUserOAuthInfo
Summary: Ref T1536. Move all access to the underlying storage to inside the class. My plan is: - Migrate the table to ExternalAccount. - Nuke the table. - Make this class read from and write to ExternalAccount instead. We can't get rid of OAuthInfo completely because Facebook still depends on it for now, via registration hooks. Test Plan: Logged in and registered with OAuth. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1536 Differential Revision: https://secure.phabricator.com/D6171
This commit is contained in:
parent
3005811b9e
commit
bce4b7addf
5 changed files with 38 additions and 34 deletions
|
@ -89,9 +89,8 @@ final class PhabricatorOAuthLoginController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$existing_oauth = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
|
$existing_oauth = PhabricatorUserOAuthInfo::loadOneByUserAndProviderKey(
|
||||||
'userID = %d AND oauthProvider = %s',
|
$current_user,
|
||||||
$current_user->getID(),
|
|
||||||
$provider_key);
|
$provider_key);
|
||||||
|
|
||||||
if ($existing_oauth) {
|
if ($existing_oauth) {
|
||||||
|
@ -182,25 +181,6 @@ final class PhabricatorOAuthLoginController
|
||||||
'Settings.',
|
'Settings.',
|
||||||
$provider_name)));
|
$provider_name)));
|
||||||
|
|
||||||
$user = id(new PhabricatorUser())
|
|
||||||
->loadOneWhere('phid = %s', $known_email->getUserPHID());
|
|
||||||
$oauth_infos = id(new PhabricatorUserOAuthInfo())
|
|
||||||
->loadAllWhere('userID = %d', $user->getID());
|
|
||||||
if ($oauth_infos) {
|
|
||||||
$providers = array();
|
|
||||||
foreach ($oauth_infos as $info) {
|
|
||||||
$provider = $info->getOAuthProvider();
|
|
||||||
$providers[] = PhabricatorOAuthProvider::newProvider($provider)
|
|
||||||
->getProviderName();
|
|
||||||
}
|
|
||||||
$dialog->appendChild(phutil_tag(
|
|
||||||
'p',
|
|
||||||
array(),
|
|
||||||
pht(
|
|
||||||
'The account is associated with: %s.',
|
|
||||||
implode(', ', $providers))));
|
|
||||||
}
|
|
||||||
|
|
||||||
$dialog->addCancelButton('/login/');
|
$dialog->addCancelButton('/login/');
|
||||||
|
|
||||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||||
|
@ -300,8 +280,7 @@ final class PhabricatorOAuthLoginController
|
||||||
|
|
||||||
private function retrieveOAuthInfo(PhabricatorOAuthProvider $provider) {
|
private function retrieveOAuthInfo(PhabricatorOAuthProvider $provider) {
|
||||||
|
|
||||||
$oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
|
$oauth_info = PhabricatorUserOAuthInfo::loadOneByProviderKeyAndAccountID(
|
||||||
'oauthProvider = %s and oauthUID = %s',
|
|
||||||
$provider->getProviderKey(),
|
$provider->getProviderKey(),
|
||||||
$provider->retrieveUserID());
|
$provider->retrieveUserID());
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,8 @@ final class PhabricatorOAuthUnlinkController extends PhabricatorAuthController {
|
||||||
|
|
||||||
$provider_key = $provider->getProviderKey();
|
$provider_key = $provider->getProviderKey();
|
||||||
|
|
||||||
$oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
|
$oauth_info = PhabricatorUserOAuthInfo::loadOneByUserAndProviderKey(
|
||||||
'userID = %d AND oauthProvider = %s',
|
$user,
|
||||||
$user->getID(),
|
|
||||||
$provider_key);
|
$provider_key);
|
||||||
|
|
||||||
if (!$oauth_info) {
|
if (!$oauth_info) {
|
||||||
|
|
|
@ -64,9 +64,7 @@ final class PhabricatorPeopleProfileController
|
||||||
// NOTE: applications install the various links through PhabricatorEvent
|
// NOTE: applications install the various links through PhabricatorEvent
|
||||||
// listeners
|
// listeners
|
||||||
|
|
||||||
$oauths = id(new PhabricatorUserOAuthInfo())->loadAllWhere(
|
$oauths = PhabricatorUserOAuthInfo::loadAllOAuthProvidersByUser($user);
|
||||||
'userID = %d',
|
|
||||||
$user->getID());
|
|
||||||
$oauths = mpull($oauths, null, 'getOAuthProvider');
|
$oauths = mpull($oauths, null, 'getOAuthProvider');
|
||||||
|
|
||||||
$providers = PhabricatorOAuthProvider::getAllProviders();
|
$providers = PhabricatorOAuthProvider::getAllProviders();
|
||||||
|
|
|
@ -14,4 +14,33 @@ final class PhabricatorUserOAuthInfo extends PhabricatorUserDAO {
|
||||||
protected $tokenScope = '';
|
protected $tokenScope = '';
|
||||||
protected $tokenStatus = 'unused';
|
protected $tokenStatus = 'unused';
|
||||||
|
|
||||||
|
public static function loadOneByUserAndProviderKey(
|
||||||
|
PhabricatorUser $user,
|
||||||
|
$provider_key) {
|
||||||
|
|
||||||
|
return id(new PhabricatorUserOAuthInfo())->loadOneWhere(
|
||||||
|
'userID = %d AND oauthProvider = %s',
|
||||||
|
$user->getID(),
|
||||||
|
$provider_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loadAllOAuthProvidersByUser(
|
||||||
|
PhabricatorUser $user) {
|
||||||
|
|
||||||
|
return id(new PhabricatorUserOAuthInfo())->loadAllWhere(
|
||||||
|
'userID = %d',
|
||||||
|
$user->getID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loadOneByProviderKeyAndAccountID(
|
||||||
|
$provider_key,
|
||||||
|
$account_id) {
|
||||||
|
|
||||||
|
return id(new PhabricatorUserOAuthInfo())->loadOneWhere(
|
||||||
|
'oauthProvider = %s and oauthUID = %s',
|
||||||
|
$provider_key,
|
||||||
|
$account_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,9 @@ final class PhabricatorSettingsPanelOAuth
|
||||||
$provider_name = $provider->getProviderName();
|
$provider_name = $provider->getProviderName();
|
||||||
$provider_key = $provider->getProviderKey();
|
$provider_key = $provider->getProviderKey();
|
||||||
|
|
||||||
$oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
|
$oauth_info = PhabricatorUserOAuthInfo::loadOneByUserAndProviderKey(
|
||||||
'userID = %d AND oauthProvider = %s',
|
$user,
|
||||||
$user->getID(),
|
$provider_key);
|
||||||
$provider->getProviderKey());
|
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form->setUser($user);
|
$form->setUser($user);
|
||||||
|
|
Loading…
Reference in a new issue