3 * StatusNet, the distributed open-source microblogging tool
5 * Action class to delete 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/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2010 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 * Delete an OAuth appliction
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
43 class DeleteapplicationAction extends Action
48 * Take arguments for running
50 * @param array $args $_REQUEST args
52 * @return boolean success flag
54 function prepare($args)
56 if (!parent::prepare($args)) {
60 if (!common_logged_in()) {
61 // TRANS: Client error displayed trying to delete an application while not logged in.
62 $this->clientError(_('You must be logged in to delete an application.'));
65 $id = (int)$this->arg('id');
66 $this->app = Oauth_application::getKV('id', $id);
68 if (empty($this->app)) {
69 // TRANS: Client error displayed trying to delete an application that does not exist.
70 $this->clientError(_('Application not found.'));
73 $cur = common_current_user();
75 if ($cur->id != $this->app->owner) {
76 // TRANS: Client error displayed trying to delete an application the current user does not own.
77 $this->clientError(_('You are not the owner of this application.'), 401);
86 * Shows a page with list of favorite notices
88 * @param array $args $_REQUEST args; handled in prepare()
92 function handle($args)
94 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
97 $token = $this->trimmed('token');
98 if (!$token || $token != common_session_token()) {
99 // TRANS: Client error displayed when the session token does not match or is not given.
100 $this->clientError(_('There was a problem with your session token.'));
103 if ($this->arg('no')) {
104 common_redirect(common_local_url('showapplication',
105 array('id' => $this->app->id)), 303);
106 } elseif ($this->arg('yes')) {
108 common_redirect(common_local_url('oauthappssettings'), 303);
115 function showContent() {
116 $this->areYouSureForm();
120 // TRANS: Title for delete application page.
121 return _('Delete application');
124 function showNoticeForm() {
131 * Shows a confirmation form.
135 function areYouSureForm()
137 $id = $this->app->id;
138 $this->elementStart('form', array('id' => 'deleteapplication-' . $id,
140 'class' => 'form_settings form_entity_block',
141 'action' => common_local_url('deleteapplication',
142 array('id' => $this->app->id))));
143 $this->elementStart('fieldset');
144 $this->hidden('token', common_session_token());
145 // TRANS: Fieldset legend on delete application page.
146 $this->element('legend', _('Delete application'));
147 $this->element('p', null,
148 // TRANS: Confirmation text on delete application page.
149 _('Are you sure you want to delete this application? '.
150 'This will clear all data about the application from the '.
151 'database, including all existing user connections.'));
152 $this->submit('form_action-no',
153 // TRANS: Button label on the delete application form.
155 'submit form_action-primary',
157 // TRANS: Submit button title for 'No' when deleting an application.
158 _('Do not delete this application.'));
159 $this->submit('form_action-yes',
160 // TRANS: Button label on the delete application form.
162 'submit form_action-secondary',
163 // TRANS: Submit button title for 'Yes' when deleting an application.
164 'yes', _('Delete this application.'));
165 $this->elementEnd('fieldset');
166 $this->elementEnd('form');
170 * Actually delete the app
174 function handlePost()
176 $this->app->delete();