3 * StatusNet, the distributed open-source microblogging tool
5 * Edit 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 Applications
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 * Edit the details of an OAuth application
37 * This is the form for editing an application
39 * @category Application
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class EditApplicationAction extends OwnerDesignAction
54 return _('Edit Application');
61 function prepare($args)
63 parent::prepare($args);
65 if (!common_logged_in()) {
66 $this->clientError(_('You must be logged in to edit an application.'));
70 $id = (int)$this->arg('id');
71 $this->app = Oauth_application::staticGet($id);
74 $this->clientError(_('No such application.'));
84 * On GET, show the form. On POST, try to save the group.
86 * @param array $args unused
91 function handle($args)
93 parent::handle($args);
94 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
97 $token = $this->trimmed('token');
98 if (!$token || $token != common_session_token()) {
99 $this->clientError(_('There was a problem with your session token.'));
103 $cur = common_current_user();
105 if ($this->arg('cancel')) {
106 common_redirect(common_local_url('showapplication',
108 'nickname' => $cur->nickname,
109 'id' => $this->app->id)
111 } elseif ($this->arg('save')) {
114 $this->clientError(_('Unexpected form submission.'));
121 function showForm($msg=null)
127 function showContent()
129 $form = new ApplicationEditForm($this, $this->app);
133 function showPageNotice()
135 if (!empty($this->msg)) {
136 $this->element('p', 'error', $this->msg);
138 $this->element('p', 'instructions',
139 _('Use this form to edit your application.'));
145 $name = $this->trimmed('name');
146 $description = $this->trimmed('description');
147 $source_url = $this->trimmed('source_url');
148 $organization = $this->trimmed('organization');
149 $homepage = $this->trimmed('homepage');
150 $callback_url = $this->trimmed('callback_url');
151 $type = $this->arg('app_type');
152 $access_type = $this->arg('access_type');
155 $this->showForm(_('Name is required.'));
157 } elseif (mb_strlen($name) > 255) {
158 $this->showForm(_('Name is too long (max 255 chars).'));
160 } elseif (empty($description)) {
161 $this->showForm(_('Description is required.'));
163 } elseif (Oauth_application::descriptionTooLong($description)) {
164 $this->showForm(sprintf(
165 _('Description is too long (max %d chars).'),
166 Oauth_application::maxDescription()));
168 } elseif (empty($source_url)) {
169 $this->showForm(_('Source URL is required.'));
171 } elseif ((strlen($source_url) > 0)
174 array('allowed_schemes' => array('http', 'https'))
178 $this->showForm(_('Source URL is not valid.'));
180 } elseif (empty($organization)) {
181 $this->showForm(_('Organization is required.'));
183 } elseif (mb_strlen($organization) > 255) {
184 $this->showForm(_('Organization is too long (max 255 chars).'));
186 } elseif (empty($homepage)) {
187 $this->showForm(_('Organization homepage is required.'));
189 } elseif ((strlen($homepage) > 0)
192 array('allowed_schemes' => array('http', 'https'))
196 $this->showForm(_('Homepage is not a valid URL.'));
198 } elseif (empty($callback_url)) {
199 $this->showForm(_('Callback is required.'));
201 } elseif (strlen($callback_url) > 0
204 array('allowed_schemes' => array('http', 'https'))
208 $this->showForm(_('Callback URL is not valid.'));
212 $cur = common_current_user();
214 // Checked in prepare() above
216 assert(!is_null($cur));
218 $orig = clone($this->app);
220 $this->app->name = $name;
221 $this->app->description = $description;
222 $this->app->source_url = $source_url;
223 $this->app->organization = $organization;
224 $this->app->homepage = $homepage;
225 $this->app->callback_url = $callback_url;
226 $this->app->type = $type;
228 if ($access_type == 'r') {
229 $this->app->setAccessFlags(true, false);
231 $this->app->setAccessFlags(true, true);
234 $result = $this->app->update($orig);
237 common_log_db_error($app, 'UPDATE', __FILE__);
238 $this->serverError(_('Could not update application.'));
241 common_redirect(common_local_url('apps',
242 array('nickname' => $cur->nickname)), 303);