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';
38 * Show connected OAuth applications
42 * @author Zach Copley <zach@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
49 class OauthconnectionssettingsAction extends ConnectSettingsAction
55 function prepare($args)
57 parent::prepare($args);
58 $this->id = (int)$this->arg('id');
59 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
66 * @return string Title of the page
71 return _('Connected applications');
74 function isReadOnly($args)
80 * Instructions for use
82 * @return instructions for use
85 function getInstructions()
87 return _('You have allowed the following applications to access you account.');
91 * Content area of the page
96 function showContent()
98 $user = common_current_user();
99 $profile = $user->getProfile();
101 $offset = ($this->page - 1) * APPS_PER_PAGE;
102 $limit = APPS_PER_PAGE + 1;
104 $application = $profile->getApplications($offset, $limit);
108 if (!empty($application)) {
109 $al = new ApplicationList($application, $user, $this, true);
114 $this->showEmptyListMessage();
117 $this->pagination($this->page > 1, $cnt > APPS_PER_PAGE,
118 $this->page, 'connectionssettings',
119 array('nickname' => $this->user->nickname));
123 * Handle posts to this form
125 * Based on the button that was pressed, muxes out to other functions
126 * to do the actual task requested.
128 * All sub-functions reload the form with a message -- success or failure.
133 function handlePost()
137 $token = $this->trimmed('token');
138 if (!$token || $token != common_session_token()) {
139 $this->showForm(_('There was a problem with your session token. '.
140 'Try again, please.'));
144 if ($this->arg('revoke')) {
145 $this->revokeAccess($this->id);
147 // XXX: Show some indicator to the user of what's been done.
151 $this->clientError(_('Unexpected form submission.'), 401);
156 function revokeAccess($appId)
158 $cur = common_current_user();
160 $app = Oauth_application::staticGet('id', $appId);
163 $this->clientError(_('No such application.'), 404);
167 $appUser = Oauth_application_user::getByKeys($cur, $app);
169 if (empty($appUser)) {
170 $this->clientError(_('You are not a user of that application.'), 401);
174 $orig = clone($appUser);
175 $appUser->access_type = 0; // No access
176 $result = $appUser->update();
179 common_log_db_error($orig, 'UPDATE', __FILE__);
180 $this->clientError(_('Unable to revoke access for app: ' . $app->id));
184 $msg = 'User %s (id: %d) revoked access to app %s (id: %d)';
185 common_log(LOG_INFO, sprintf($msg, $cur->nickname,
186 $cur->id, $app->name, $app->id));
190 function showEmptyListMessage()
192 $message = sprintf(_('You have not authorized any applications to use your account.'));
194 $this->elementStart('div', 'guide');
195 $this->raw(common_markup_to_html($message));
196 $this->elementEnd('div');
199 function showSections()
201 $cur = common_current_user();
203 $this->element('h2', null, 'Developers');
204 $this->elementStart('p');
205 $this->raw(_('Developers can edit the registration settings for their applications '));
207 array('href' => common_local_url('oauthappssettings')),
209 $this->elementEnd('p');