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 $consumer = $this->application->getConsumer();
156 $this->elementStart('div', 'entity_profile vcard');
157 $this->element('h2', null, _('Application profile'));
158 $this->elementStart('dl', 'entity_depiction');
159 $this->element('dt', null, _('Icon'));
160 $this->elementStart('dd');
161 if (!empty($this->application->icon)) {
162 $this->element('img', array('src' => $this->application->icon,
163 'class' => 'photo logo'));
165 $this->elementEnd('dd');
166 $this->elementEnd('dl');
168 $this->elementStart('dl', 'entity_fn');
169 $this->element('dt', null, _('Name'));
170 $this->elementStart('dd');
171 $this->element('a', array('href' => $this->application->source_url,
172 'class' => 'url fn'),
173 $this->application->name);
174 $this->elementEnd('dd');
175 $this->elementEnd('dl');
177 $this->elementStart('dl', 'entity_org');
178 $this->element('dt', null, _('Organization'));
179 $this->elementStart('dd');
180 $this->element('a', array('href' => $this->application->homepage,
182 $this->application->organization);
183 $this->elementEnd('dd');
184 $this->elementEnd('dl');
186 $this->elementStart('dl', 'entity_note');
187 $this->element('dt', null, _('Description'));
188 $this->element('dd', 'note', $this->application->description);
189 $this->elementEnd('dl');
191 $this->elementStart('dl', 'entity_statistics');
192 $this->element('dt', null, _('Statistics'));
193 $this->elementStart('dd');
194 $defaultAccess = ($this->application->access_type & Oauth_application::$writeAccess)
195 ? 'read-write' : 'read-only';
196 $profile = Profile::staticGet($this->application->owner);
197 $userCnt = 0; // XXX: count how many users use the app
200 _('Created by %1$s - %2$s access by default - %3$d users.'),
201 $profile->getBestName(),
205 $this->elementEnd('dd');
206 $this->elementEnd('dl');
207 $this->elementEnd('div');
209 $this->elementStart('div', 'entity_actions');
210 $this->element('h2', null, _('Application actions'));
211 $this->elementStart('ul');
212 $this->elementStart('li', 'entity_edit');
218 'nickname' => $this->owner->nickname,
219 'id' => $this->application->id
223 $this->elementEnd('li');
225 $this->elementStart('li', 'entity_reset_keysecret');
226 $this->elementStart('form', array(
227 'id' => 'forma_reset_key',
228 'class' => 'form_reset_key',
230 'action' => common_local_url('showapplication',
231 array('nickname' => $cur->nickname,
232 'id' => $this->application->id))));
234 $this->elementStart('fieldset');
235 $this->hidden('token', common_session_token());
236 $this->submit('reset', _('Reset key & secret'));
237 $this->elementEnd('fieldset');
238 $this->elementEnd('form');
239 $this->elementEnd('li');
240 $this->elementEnd('ul');
241 $this->elementEnd('div');
243 $this->elementStart('div', 'entity_data');
244 $this->element('h2', null, _('Application info'));
245 $this->elementStart('dl', 'entity_consumer_key');
246 $this->element('dt', null, _('Consumer key'));
247 $this->element('dd', null, $consumer->consumer_key);
248 $this->elementEnd('dl');
250 $this->elementStart('dl', 'entity_consumer_secret');
251 $this->element('dt', null, _('Consumer secret'));
252 $this->element('dd', null, $consumer->consumer_secret);
253 $this->elementEnd('dl');
255 $this->elementStart('dl', 'entity_request_token_url');
256 $this->element('dt', null, _('Request token URL'));
257 $this->element('dd', null, common_local_url('apioauthrequesttoken'));
258 $this->elementEnd('dl');
260 $this->elementStart('dl', 'entity_access_token_url');
261 $this->element('dt', null, _('Access token URL'));
262 $this->element('dd', null, common_local_url('apioauthaccesstoken'));
263 $this->elementEnd('dl');
265 $this->elementStart('dl', 'entity_authorize_url');
266 $this->element('dt', null, _('Authorize URL'));
267 $this->element('dd', null, common_local_url('apioauthauthorize'));
268 $this->elementEnd('dl');
270 $this->element('p', 'note',
271 _('Note: We support hmac-sha1 signatures. We do not support the plaintext signature method.'));
272 $this->elementEnd('div');
274 $this->elementStart('p', array('id' => 'application_action'));
277 'href' => common_local_url(
279 array('nickname' => $this->owner->nickname)),
282 'View your applications');
283 $this->elementEnd('p');
288 $this->application->query('BEGIN');
290 $consumer = $this->application->getConsumer();
291 $result = $consumer->delete();
294 common_log_db_error($consumer, 'DELETE', __FILE__);
295 $this->success = false;
296 $this->msg = ('Unable to reset consumer key and secret.');
301 $consumer = Consumer::generateNew();
303 $result = $consumer->insert();
306 common_log_db_error($consumer, 'INSERT', __FILE__);
307 $this->application->query('ROLLBACK');
308 $this->success = false;
309 $this->msg = ('Unable to reset consumer key and secret.');
314 $orig = clone($this->application);
315 $this->application->consumer_key = $consumer->consumer_key;
316 $result = $this->application->update($orig);
319 common_log_db_error($application, 'UPDATE', __FILE__);
320 $this->application->query('ROLLBACK');
321 $this->success = false;
322 $this->msg = ('Unable to reset consumer key and secret.');
327 $this->application->query('COMMIT');
329 $this->success = true;
330 $this->msg = ('Consumer key and secret reset.');