3 * StatusNet, the distributed open-source microblogging tool
5 * Show an OAuth application
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/>.
22 * @category Application
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')) {
35 * Show an OAuth application
37 * @category Application
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
44 class ShowApplicationAction extends OwnerDesignAction
50 var $application = null;
53 * User who owns the app
64 * Load attributes based on database arguments
66 * Loads all the DB stuff
68 * @param array $args $_REQUEST array
70 * @return success flag
73 function prepare($args)
75 parent::prepare($args);
77 $id = (int)$this->arg('id');
79 $this->application = Oauth_application::staticGet($id);
80 $this->owner = User::staticGet($this->application->owner);
82 if (!common_logged_in()) {
83 $this->clientError(_('You must be logged in to view an application.'));
87 if (empty($this->application)) {
88 $this->clientError(_('No such application.'), 404);
92 $cur = common_current_user();
94 if ($cur->id != $this->owner->id) {
95 $this->clientError(_('You are not the owner of this application.'), 401);
104 * Shows info about the app
109 function handle($args)
111 parent::handle($args);
113 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
116 $token = $this->trimmed('token');
117 if (!$token || $token != common_session_token()) {
118 $this->clientError(_('There was a problem with your session token.'));
122 if ($this->arg('reset')) {
133 * @return string title of the page
138 if (!empty($this->application->name)) {
139 return 'Application: ' . $this->application->name;
143 function showPageNotice()
145 if (!empty($this->msg)) {
146 $this->element('div', ($this->success) ? 'success' : 'error', $this->msg);
150 function showContent()
153 $cur = common_current_user();
155 $this->elementStart('div', 'entity_actions');
162 'nickname' => $this->owner->nickname,
163 'id' => $this->application->id
166 ), 'Edit application');
168 $this->elementStart('form', array(
169 'id' => 'forma_reset_key',
170 'class' => 'form_reset_key',
172 'action' => common_local_url('showapplication',
173 array('nickname' => $cur->nickname,
174 'id' => $this->application->id))));
176 $this->elementStart('fieldset');
177 $this->hidden('token', common_session_token());
178 $this->submit('reset', _('Reset Consumer key/secret'));
179 $this->elementEnd('fieldset');
180 $this->elementEnd('form');
182 $this->elementEnd('div');
184 $consumer = $this->application->getConsumer();
186 $this->elementStart('div', 'entity-application');
188 $this->elementStart('ul', 'entity_application_details');
190 $this->elementStart('li', 'entity_application_name');
191 $this->element('span', array('class' => 'big'), $this->application->name);
192 $this->raw(sprintf(_(' by %1$s'), $this->application->organization));
193 $this->elementEnd('li');
195 $this->element('li', 'entity_application_description', $this->application->description);
197 $this->elementStart('li', 'entity_application_statistics');
199 $defaultAccess = ($this->application->access_type & Oauth_application::$writeAccess)
200 ? 'read-write' : 'read-only';
201 $profile = Profile::staticGet($this->application->owner);
202 $userCnt = 0; // XXX: count how many users use the app
205 _('Created by %1$s - %2$s access by default - %3$d users.'),
206 $profile->getBestName(),
211 $this->elementEnd('li');
213 $this->elementEnd('ul');
215 $this->elementStart('dl', 'entity_consumer_key');
216 $this->element('dt', null, _('Consumer key'));
217 $this->element('dd', 'label', $consumer->consumer_key);
218 $this->elementEnd('dl');
220 $this->elementStart('dl', 'entity_consumer_secret');
221 $this->element('dt', null, _('Consumer secret'));
222 $this->element('dd', 'label', $consumer->consumer_secret);
223 $this->elementEnd('dl');
225 $this->elementStart('dl', 'entity_request_token_url');
226 $this->element('dt', null, _('Request token URL'));
227 $this->element('dd', 'label', common_local_url('oauthrequesttoken'));
228 $this->elementEnd('dl');
230 $this->elementStart('dl', 'entity_access_token_url');
231 $this->element('dt', null, _('Access token URL'));
232 $this->element('dd', 'label', common_local_url('oauthaccesstoken'));
233 $this->elementEnd('dl');
235 $this->elementStart('dl', 'entity_authorize_url');
236 $this->element('dt', null, _('Authorize URL'));
237 $this->element('dd', 'label', common_local_url('oauthauthorize'));
238 $this->elementEnd('dl');
240 $this->element('p', 'oauth-signature-note',
241 '*We support hmac-sha1 signatures. We do not support the plaintext signature method.');
243 $this->elementEnd('div');
245 $this->elementStart('div', 'entity-list-apps');
248 'href' => common_local_url(
250 array('nickname' => $this->owner->nickname)
253 'View your applications');
254 $this->elementEnd('div');
259 $this->application->query('BEGIN');
261 $consumer = $this->application->getConsumer();
262 $result = $consumer->delete();
265 common_log_db_error($consumer, 'DELETE', __FILE__);
266 $this->success = false;
267 $this->msg = ('Unable to reset consumer key and secret.');
272 $consumer = Consumer::generateNew();
274 $result = $consumer->insert();
277 common_log_db_error($consumer, 'INSERT', __FILE__);
278 $this->application->query('ROLLBACK');
279 $this->success = false;
280 $this->msg = ('Unable to reset consumer key and secret.');
285 $orig = clone($this->application);
286 $this->application->consumer_key = $consumer->consumer_key;
287 $result = $this->application->update($orig);
290 common_log_db_error($application, 'UPDATE', __FILE__);
291 $this->application->query('ROLLBACK');
292 $this->success = false;
293 $this->msg = ('Unable to reset consumer key and secret.');
298 $this->application->query('COMMIT');
300 $this->success = true;
301 $this->msg = ('Consumer key and secret reset.');