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' => 'forma_reset_key',
226 'class' => 'form_reset_key',
228 'action' => common_local_url('showapplication',
229 array('id' => $this->application->id))));
231 $this->elementStart('fieldset');
232 $this->hidden('token', common_session_token());
233 $this->submit('reset', _('Reset key & secret'));
234 $this->elementEnd('fieldset');
235 $this->elementEnd('form');
236 $this->elementEnd('li');
237 $this->elementEnd('ul');
238 $this->elementEnd('div');
240 $this->elementStart('div', 'entity_data');
241 $this->element('h2', null, _('Application info'));
242 $this->elementStart('dl', 'entity_consumer_key');
243 $this->element('dt', null, _('Consumer key'));
244 $this->element('dd', null, $consumer->consumer_key);
245 $this->elementEnd('dl');
247 $this->elementStart('dl', 'entity_consumer_secret');
248 $this->element('dt', null, _('Consumer secret'));
249 $this->element('dd', null, $consumer->consumer_secret);
250 $this->elementEnd('dl');
252 $this->elementStart('dl', 'entity_request_token_url');
253 $this->element('dt', null, _('Request token URL'));
254 $this->element('dd', null, common_local_url('apioauthrequesttoken'));
255 $this->elementEnd('dl');
257 $this->elementStart('dl', 'entity_access_token_url');
258 $this->element('dt', null, _('Access token URL'));
259 $this->element('dd', null, common_local_url('apioauthaccesstoken'));
260 $this->elementEnd('dl');
262 $this->elementStart('dl', 'entity_authorize_url');
263 $this->element('dt', null, _('Authorize URL'));
264 $this->element('dd', null, common_local_url('apioauthauthorize'));
265 $this->elementEnd('dl');
267 $this->element('p', 'note',
268 _('Note: We support HMAC-SHA1 signatures. We do not support the plaintext signature method.'));
269 $this->elementEnd('div');
271 $this->elementStart('p', array('id' => 'application_action'));
273 array('href' => common_local_url('oauthappssettings'),
275 'View your applications');
276 $this->elementEnd('p');
281 $this->application->query('BEGIN');
283 $consumer = $this->application->getConsumer();
284 $result = $consumer->delete();
287 common_log_db_error($consumer, 'DELETE', __FILE__);
288 $this->success = false;
289 $this->msg = ('Unable to reset consumer key and secret.');
294 $consumer = Consumer::generateNew();
296 $result = $consumer->insert();
299 common_log_db_error($consumer, 'INSERT', __FILE__);
300 $this->application->query('ROLLBACK');
301 $this->success = false;
302 $this->msg = ('Unable to reset consumer key and secret.');
307 $orig = clone($this->application);
308 $this->application->consumer_key = $consumer->consumer_key;
309 $result = $this->application->update($orig);
312 common_log_db_error($application, 'UPDATE', __FILE__);
313 $this->application->query('ROLLBACK');
314 $this->success = false;
315 $this->msg = ('Unable to reset consumer key and secret.');
320 $this->application->query('COMMIT');
322 $this->success = true;
323 $this->msg = ('Consumer key and secret reset.');