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
63 * Load attributes based on database arguments
65 * Loads all the DB stuff
67 * @param array $args $_REQUEST array
69 * @return success flag
72 function prepare($args)
74 parent::prepare($args);
76 $id = (int)$this->arg('id');
78 $this->application = Oauth_application::staticGet($id);
79 $this->owner = User::staticGet($this->application->owner);
81 if (!common_logged_in()) {
82 $this->clientError(_('You must be logged in to view an application.'));
86 if (empty($this->application)) {
87 $this->clientError(_('No such application.'), 404);
91 $cur = common_current_user();
93 if ($cur->id != $this->owner->id) {
94 $this->clientError(_('You are not the owner of this application.'), 401);
103 * Shows info about the app
108 function handle($args)
110 parent::handle($args);
112 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
115 $token = $this->trimmed('token');
116 if (!$token || $token != common_session_token()) {
117 $this->clientError(_('There was a problem with your session token.'));
121 if ($this->arg('reset')) {
132 * @return string title of the page
137 if (!empty($this->application->name)) {
138 return 'Application: ' . $this->application->name;
142 function showPageNotice()
144 if (!empty($this->msg)) {
145 $this->element('div', ($this->success) ? 'success' : 'error', $this->msg);
149 function showContent()
152 $cur = common_current_user();
154 $this->elementStart('div', 'entity_actions');
161 'nickname' => $this->owner->nickname,
162 'id' => $this->application->id
165 ), 'Edit application');
167 $this->elementStart('form', array(
168 'id' => 'forma_reset_key',
169 'class' => 'form_reset_key',
171 'action' => common_local_url('showapplication',
172 array('nickname' => $cur->nickname,
173 'id' => $this->application->id))));
175 $this->elementStart('fieldset');
176 $this->hidden('token', common_session_token());
177 $this->submit('reset', _('Reset Consumer key/secret'));
178 $this->elementEnd('fieldset');
179 $this->elementEnd('form');
181 $this->elementEnd('div');
183 $consumer = $this->application->getConsumer();
185 $this->elementStart('div', 'entity-application');
187 $this->elementStart('ul', 'entity_application_details');
189 $this->elementStart('li', 'entity_application-icon');
191 if (!empty($this->application->icon)) {
192 $this->element('img', array('src' => $this->application->icon));
195 $this->elementEnd('li');
197 $this->elementStart('li', 'entity_application_name');
198 $this->element('span', array('class' => 'big'), $this->application->name);
199 $this->raw(sprintf(_(' by %1$s'), $this->application->organization));
200 $this->elementEnd('li');
202 $this->element('li', 'entity_application_description', $this->application->description);
204 $this->elementStart('li', 'entity_application_statistics');
206 $defaultAccess = ($this->application->access_type & Oauth_application::$writeAccess)
207 ? 'read-write' : 'read-only';
208 $profile = Profile::staticGet($this->application->owner);
209 $userCnt = 0; // XXX: count how many users use the app
212 _('Created by %1$s - %2$s access by default - %3$d users.'),
213 $profile->getBestName(),
218 $this->elementEnd('li');
220 $this->elementEnd('ul');
222 $this->elementStart('dl', 'entity_consumer_key');
223 $this->element('dt', null, _('Consumer key'));
224 $this->element('dd', 'label', $consumer->consumer_key);
225 $this->elementEnd('dl');
227 $this->elementStart('dl', 'entity_consumer_secret');
228 $this->element('dt', null, _('Consumer secret'));
229 $this->element('dd', 'label', $consumer->consumer_secret);
230 $this->elementEnd('dl');
232 $this->elementStart('dl', 'entity_request_token_url');
233 $this->element('dt', null, _('Request token URL'));
234 $this->element('dd', 'label', common_local_url('oauthrequesttoken'));
235 $this->elementEnd('dl');
237 $this->elementStart('dl', 'entity_access_token_url');
238 $this->element('dt', null, _('Access token URL'));
239 $this->element('dd', 'label', common_local_url('oauthaccesstoken'));
240 $this->elementEnd('dl');
242 $this->elementStart('dl', 'entity_authorize_url');
243 $this->element('dt', null, _('Authorize URL'));
244 $this->element('dd', 'label', common_local_url('oauthauthorize'));
245 $this->elementEnd('dl');
247 $this->element('p', 'oauth-signature-note',
248 '*We support hmac-sha1 signatures. We do not support the plaintext signature method.');
250 $this->elementEnd('div');
252 $this->elementStart('div', 'entity-list-apps');
255 'href' => common_local_url(
257 array('nickname' => $this->owner->nickname)
260 'View your applications');
261 $this->elementEnd('div');
266 $this->application->query('BEGIN');
268 $consumer = $this->application->getConsumer();
269 $result = $consumer->delete();
272 common_log_db_error($consumer, 'DELETE', __FILE__);
273 $this->success = false;
274 $this->msg = ('Unable to reset consumer key and secret.');
279 $consumer = Consumer::generateNew();
281 $result = $consumer->insert();
284 common_log_db_error($consumer, 'INSERT', __FILE__);
285 $this->application->query('ROLLBACK');
286 $this->success = false;
287 $this->msg = ('Unable to reset consumer key and secret.');
292 $orig = clone($this->application);
293 $this->application->consumer_key = $consumer->consumer_key;
294 $result = $this->application->update($orig);
297 common_log_db_error($application, 'UPDATE', __FILE__);
298 $this->application->query('ROLLBACK');
299 $this->success = false;
300 $this->msg = ('Unable to reset consumer key and secret.');
305 $this->application->query('COMMIT');
307 $this->success = true;
308 $this->msg = ('Consumer key and secret reset.');