1
0
Fork 0
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:
epriestley 2013-06-14 07:00:29 -07:00
parent 3005811b9e
commit bce4b7addf
5 changed files with 38 additions and 34 deletions

View file

@ -89,9 +89,8 @@ final class PhabricatorOAuthLoginController
}
}
$existing_oauth = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
'userID = %d AND oauthProvider = %s',
$current_user->getID(),
$existing_oauth = PhabricatorUserOAuthInfo::loadOneByUserAndProviderKey(
$current_user,
$provider_key);
if ($existing_oauth) {
@ -182,25 +181,6 @@ final class PhabricatorOAuthLoginController
'Settings.',
$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/');
return id(new AphrontDialogResponse())->setDialog($dialog);
@ -300,8 +280,7 @@ final class PhabricatorOAuthLoginController
private function retrieveOAuthInfo(PhabricatorOAuthProvider $provider) {
$oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
'oauthProvider = %s and oauthUID = %s',
$oauth_info = PhabricatorUserOAuthInfo::loadOneByProviderKeyAndAccountID(
$provider->getProviderKey(),
$provider->retrieveUserID());

View file

@ -21,9 +21,8 @@ final class PhabricatorOAuthUnlinkController extends PhabricatorAuthController {
$provider_key = $provider->getProviderKey();
$oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
'userID = %d AND oauthProvider = %s',
$user->getID(),
$oauth_info = PhabricatorUserOAuthInfo::loadOneByUserAndProviderKey(
$user,
$provider_key);
if (!$oauth_info) {

View file

@ -64,9 +64,7 @@ final class PhabricatorPeopleProfileController
// NOTE: applications install the various links through PhabricatorEvent
// listeners
$oauths = id(new PhabricatorUserOAuthInfo())->loadAllWhere(
'userID = %d',
$user->getID());
$oauths = PhabricatorUserOAuthInfo::loadAllOAuthProvidersByUser($user);
$oauths = mpull($oauths, null, 'getOAuthProvider');
$providers = PhabricatorOAuthProvider::getAllProviders();

View file

@ -14,4 +14,33 @@ final class PhabricatorUserOAuthInfo extends PhabricatorUserDAO {
protected $tokenScope = '';
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);
}
}

View file

@ -68,10 +68,9 @@ final class PhabricatorSettingsPanelOAuth
$provider_name = $provider->getProviderName();
$provider_key = $provider->getProviderKey();
$oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere(
'userID = %d AND oauthProvider = %s',
$user->getID(),
$provider->getProviderKey());
$oauth_info = PhabricatorUserOAuthInfo::loadOneByUserAndProviderKey(
$user,
$provider_key);
$form = new AphrontFormView();
$form->setUser($user);