3 * StatusNet, the distributed open-source microblogging tool
5 * List a user's OAuth connected applications
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2008-2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR . '/lib/connectsettingsaction.php';
35 require_once INSTALLDIR . '/lib/applicationlist.php';
36 require_once INSTALLDIR . '/lib/apioauthstore.php';
39 * Show connected OAuth applications
43 * @author Zach Copley <zach@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
50 class OauthconnectionssettingsAction extends ConnectSettingsAction
56 function prepare($args)
58 parent::prepare($args);
59 $this->id = (int)$this->arg('id');
60 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
67 * @return string Title of the page
72 return _('Connected applications');
76 * Instructions for use
78 * @return instructions for use
81 function getInstructions()
83 return _('You have allowed the following applications to access you account.');
87 * Content area of the page
92 function showContent()
94 $user = common_current_user();
95 $profile = $user->getProfile();
97 $offset = ($this->page - 1) * APPS_PER_PAGE;
98 $limit = APPS_PER_PAGE + 1;
100 $application = $profile->getApplications($offset, $limit);
104 if (!empty($application)) {
105 $al = new ApplicationList($application, $user, $this, true);
110 $this->showEmptyListMessage();
113 $this->pagination($this->page > 1, $cnt > APPS_PER_PAGE,
114 $this->page, 'connectionssettings',
115 array('nickname' => $user->nickname));
119 * Handle posts to this form
121 * Based on the button that was pressed, muxes out to other functions
122 * to do the actual task requested.
124 * All sub-functions reload the form with a message -- success or failure.
129 function handlePost()
133 $token = $this->trimmed('token');
134 if (!$token || $token != common_session_token()) {
135 $this->showForm(_('There was a problem with your session token. '.
136 'Try again, please.'));
140 if ($this->arg('revoke')) {
141 $this->revokeAccess($this->id);
143 // XXX: Show some indicator to the user of what's been done.
147 $this->clientError(_('Unexpected form submission.'), 401);
153 * Revoke access to an authorized OAuth application
155 * @param int $appId the ID of the application
159 function revokeAccess($appId)
161 $cur = common_current_user();
163 $app = Oauth_application::staticGet('id', $appId);
166 $this->clientError(_('No such application.'), 404);
170 // XXX: Transaction here?
172 $appUser = Oauth_application_user::getByKeys($cur, $app);
174 if (empty($appUser)) {
175 $this->clientError(_('You are not a user of that application.'), 401);
179 $datastore = new ApiStatusNetOAuthDataStore();
180 $datastore->revoke_token($appUser->token, 1);
182 $result = $appUser->delete();
185 common_log_db_error($orig, 'DELETE', __FILE__);
186 $this->clientError(sprintf(_('Unable to revoke access for app: %s.'), $app->id));
190 $msg = 'User %s (id: %d) revoked access to app %s (id: %d)';
191 common_log(LOG_INFO, sprintf($msg, $cur->nickname,
192 $cur->id, $app->name, $app->id));
196 function showEmptyListMessage()
198 $message = _('You have not authorized any applications to use your account.');
200 $this->elementStart('div', 'guide');
201 $this->raw(common_markup_to_html($message));
202 $this->elementEnd('div');
205 function showSections()
207 $cur = common_current_user();
209 $this->element('h2', null, 'Developers');
210 $this->elementStart('p');
211 $this->raw(_('Developers can edit the registration settings for their applications '));
213 array('href' => common_local_url('oauthappssettings')),
215 $this->elementEnd('p');