X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Foauthconnectionssettings.php;h=0c5a14344370e609df043fb67262683df6501a96;hb=8d4cdbb430c46e34cc01cdedbbf44ff160541f2b;hp=cdb73203f0c4263e53054bca3a90d0401108350f;hpb=bb55784e902388f12ae9a0beddf283b48f19531e;p=quix0rs-gnu-social.git diff --git a/actions/oauthconnectionssettings.php b/actions/oauthconnectionssettings.php index cdb73203f0..0c5a143443 100644 --- a/actions/oauthconnectionssettings.php +++ b/actions/oauthconnectionssettings.php @@ -27,13 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR . '/lib/connectsettingsaction.php'; -require_once INSTALLDIR . '/lib/applicationlist.php'; -require_once INSTALLDIR . '/lib/apioauthstore.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Show connected OAuth applications @@ -46,17 +40,16 @@ require_once INSTALLDIR . '/lib/apioauthstore.php'; * * @see SettingsAction */ -class OauthconnectionssettingsAction extends ConnectSettingsAction +class OauthconnectionssettingsAction extends SettingsAction { - var $page = null; - var $oauth_token = null; + var $page = null; + + protected $oauth_token = null; - function prepare($args) + protected function doPreparation() { - parent::prepare($args); $this->oauth_token = $this->arg('oauth_token'); - $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1; - return true; + $this->page = $this->int('page') ?: 1; } /** @@ -64,7 +57,6 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction * * @return string Title of the page */ - function title() { // TRANS: Title for OAuth connection settings. @@ -76,7 +68,6 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction * * @return instructions for use */ - function getInstructions() { // TRANS: Instructions for OAuth connection settings. @@ -91,18 +82,15 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction function showContent() { - $user = common_current_user(); - $profile = $user->getProfile(); - $offset = ($this->page - 1) * APPS_PER_PAGE; $limit = APPS_PER_PAGE + 1; - $connection = $user->getConnectedApps($offset, $limit); + $connection = $this->scoped->getConnectedApps($offset, $limit); $cnt = 0; if (!empty($connection)) { - $cal = new ConnectedAppsList($connection, $user, $this); + $cal = new ConnectedAppsList($connection, $this->scoped, $this); $cnt = $cal->show(); } @@ -115,7 +103,7 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction $cnt > APPS_PER_PAGE, $this->page, 'connectionssettings', - array('nickname' => $user->nickname) + array('nickname' => $this->scoped->getNickname()) ); } @@ -129,24 +117,14 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction * * @return void */ - function handlePost() + protected function doPost() { - // CSRF protection - - $token = $this->trimmed('token'); - if (!$token || $token != common_session_token()) { - $this->showForm(_('There was a problem with your session token. '. - 'Try again, please.')); - return; - } - if ($this->arg('revoke')) { - $this->revokeAccess($this->oauth_token); - } else { - // TRANS: Client error when submitting a form with unexpected information. - $this->clientError(_('Unexpected form submission.'), 401); - return false; + return $this->revokeAccess($this->oauth_token); } + + // TRANS: Client error when submitting a form with unexpected information. + throw new ClientException(_('Unexpected form submission.'), 401); } /** @@ -166,12 +144,11 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction if (empty($appUser)) { // TRANS: Client error when trying to revoke access for an application while not being a user of it. $this->clientError(_('You are not a user of that application.'), 401); - return false; } - $app = Oauth_application::staticGet('id', $appUser->application_id); + $app = Oauth_application::getKV('id', $appUser->application_id); - $datastore = new ApiStatusNetOAuthDataStore(); + $datastore = new ApiGNUsocialOAuthDataStore(); $datastore->revoke_token($appUser->token, 1); $result = $appUser->delete(); @@ -181,7 +158,6 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction // TRANS: Client error when revoking access has failed for some reason. // TRANS: %s is the application ID revoking access failed for. $this->clientError(sprintf(_('Unable to revoke access for application: %s.'), $app->id)); - return false; } $msg = 'API OAuth - user %s (id: %d) revoked access token %s for app id %d';