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);
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 $consumer = $this->application->getConsumer();
157 $this->elementStart('div', 'entity_profile vcard');
158 $this->element('h2', null, _('Application profile'));
159 $this->elementStart('dl', 'entity_depiction');
160 $this->element('dt', null, _('Icon'));
161 $this->elementStart('dd');
162 if (!empty($this->application->icon)) {
163 $this->element('img', array('src' => $this->application->icon,
164 'class' => 'photo logo'));
166 $this->elementEnd('dd');
167 $this->elementEnd('dl');
169 $this->elementStart('dl', 'entity_fn');
170 $this->element('dt', null, _('Name'));
171 $this->elementStart('dd');
172 $this->element('a', array('href' => $this->application->source_url,
173 'class' => 'url fn'),
174 $this->application->name);
175 $this->elementEnd('dd');
176 $this->elementEnd('dl');
178 $this->elementStart('dl', 'entity_org');
179 $this->element('dt', null, _('Organization'));
180 $this->elementStart('dd');
181 $this->element('a', array('href' => $this->application->homepage,
183 $this->application->organization);
184 $this->elementEnd('dd');
185 $this->elementEnd('dl');
187 $this->elementStart('dl', 'entity_note');
188 $this->element('dt', null, _('Description'));
189 $this->element('dd', 'note', $this->application->description);
190 $this->elementEnd('dl');
192 $this->elementStart('dl', 'entity_statistics');
193 $this->element('dt', null, _('Statistics'));
194 $this->elementStart('dd');
195 $defaultAccess = ($this->application->access_type & Oauth_application::$writeAccess)
196 ? 'read-write' : 'read-only';
197 $profile = Profile::staticGet($this->application->owner);
199 $appUsers = new Oauth_application_user();
200 $appUsers->application_id = $this->application->id;
201 $userCnt = $appUsers->count();
204 _('created by %1$s - %2$s access by default - %3$d users'),
205 $profile->getBestName(),
209 $this->elementEnd('dd');
210 $this->elementEnd('dl');
211 $this->elementEnd('div');
213 $this->elementStart('div', 'entity_actions');
214 $this->element('h2', null, _('Application actions'));
215 $this->elementStart('ul');
216 $this->elementStart('li', 'entity_edit');
218 array('href' => common_local_url('editapplication',
219 array('id' => $this->application->id))),
221 $this->elementEnd('li');
223 $this->elementStart('li', 'entity_reset_keysecret');
224 $this->elementStart('form', array(
225 'id' => 'form_reset_key',
226 'class' => 'form_reset_key',
228 'action' => common_local_url('showapplication',
229 array('id' => $this->application->id))));
230 $this->elementStart('fieldset');
231 $this->hidden('token', common_session_token());
232 $this->submit('reset', _('Reset key & secret'));
233 $this->elementEnd('fieldset');
234 $this->elementEnd('form');
235 $this->elementEnd('li');
237 $this->elementStart('li', 'entity_delete');
238 $this->elementStart('form', array(
239 'id' => 'form_delete_application',
240 'class' => 'form_delete_application',
242 'action' => common_local_url('deleteapplication',
243 array('id' => $this->application->id))));
245 $this->elementStart('fieldset');
246 $this->hidden('token', common_session_token());
247 $this->submit('delete', _('Delete'));
248 $this->elementEnd('fieldset');
249 $this->elementEnd('form');
250 $this->elementEnd('li');
252 $this->elementEnd('ul');
253 $this->elementEnd('div');
255 $this->elementStart('div', 'entity_data');
256 $this->element('h2', null, _('Application info'));
257 $this->elementStart('dl', 'entity_consumer_key');
258 $this->element('dt', null, _('Consumer key'));
259 $this->element('dd', null, $consumer->consumer_key);
260 $this->elementEnd('dl');
262 $this->elementStart('dl', 'entity_consumer_secret');
263 $this->element('dt', null, _('Consumer secret'));
264 $this->element('dd', null, $consumer->consumer_secret);
265 $this->elementEnd('dl');
267 $this->elementStart('dl', 'entity_request_token_url');
268 $this->element('dt', null, _('Request token URL'));
269 $this->element('dd', null, common_local_url('apioauthrequesttoken'));
270 $this->elementEnd('dl');
272 $this->elementStart('dl', 'entity_access_token_url');
273 $this->element('dt', null, _('Access token URL'));
274 $this->element('dd', null, common_local_url('apioauthaccesstoken'));
275 $this->elementEnd('dl');
277 $this->elementStart('dl', 'entity_authorize_url');
278 $this->element('dt', null, _('Authorize URL'));
279 $this->element('dd', null, common_local_url('apioauthauthorize'));
280 $this->elementEnd('dl');
282 $this->element('p', 'note',
283 _('Note: We support HMAC-SHA1 signatures. We do not support the plaintext signature method.'));
284 $this->elementEnd('div');
286 $this->elementStart('p', array('id' => 'application_action'));
288 array('href' => common_local_url('oauthappssettings'),
290 'View your applications');
291 $this->elementEnd('p');
296 $this->application->query('BEGIN');
298 $consumer = $this->application->getConsumer();
299 $result = $consumer->delete();
302 common_log_db_error($consumer, 'DELETE', __FILE__);
303 $this->success = false;
304 $this->msg = ('Unable to reset consumer key and secret.');
309 $consumer = Consumer::generateNew();
311 $result = $consumer->insert();
314 common_log_db_error($consumer, 'INSERT', __FILE__);
315 $this->application->query('ROLLBACK');
316 $this->success = false;
317 $this->msg = ('Unable to reset consumer key and secret.');
322 $orig = clone($this->application);
323 $this->application->consumer_key = $consumer->consumer_key;
324 $result = $this->application->update($orig);
327 common_log_db_error($application, 'UPDATE', __FILE__);
328 $this->application->query('ROLLBACK');
329 $this->success = false;
330 $this->msg = ('Unable to reset consumer key and secret.');
335 $this->application->query('COMMIT');
337 $this->success = true;
338 $this->msg = ('Consumer key and secret reset.');