3 * StatusNet, the distributed open-source microblogging tool
5 * Register a new 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 * Add a new application
37 * This is the form for adding a new 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 NewApplicationAction extends Action
52 return _('New Application');
59 function prepare($args)
61 parent::prepare($args);
63 if (!common_logged_in()) {
64 $this->clientError(_('You must be logged in to create a group.'));
74 * On GET, show the form. On POST, try to save the group.
76 * @param array $args unused
81 function handle($args)
83 parent::handle($args);
84 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91 function showForm($msg=null)
97 function showContent()
99 $form = new ApplicationEditForm($this);
103 function showPageNotice()
106 $this->element('p', 'error', $this->msg);
108 $this->element('p', 'instructions',
109 _('Use this form to register a new application.'));
115 $name = $this->trimmed('name');
116 $description = $this->trimmed('description');
117 $source_url = $this->trimmed('source_url');
118 $organization = $this->trimmed('organization');
119 $homepage = $this->trimmed('application');
120 $callback_url = $this->trimmed('callback_url');
121 $this->type = $this->trimmed('type');
122 $this->access_type = $this->trimmed('access_type');
124 if (!is_null($name) && mb_strlen($name) > 255) {
125 $this->showForm(_('Name is too long (max 255 chars).'));
127 } else if (User_group::descriptionTooLong($description)) {
128 $this->showForm(sprintf(
129 _('description is too long (max %d chars).'),
130 Oauth_application::maxDescription()));
132 } elseif (!is_null($source_url)
133 && (strlen($source_url) > 0)
136 array('allowed_schemes' => array('http', 'https'))
140 $this->showForm(_('Source URL is not valid.'));
142 } elseif (!is_null($homepage)
143 && (strlen($homepage) > 0)
146 array('allowed_schemes' => array('http', 'https'))
150 $this->showForm(_('Homepage is not a valid URL.'));
152 } elseif (!is_null($callback_url)
153 && (strlen($callback_url) > 0)
156 array('allowed_schemes' => array('http', 'https'))
160 $this->showForm(_('Callback URL is not valid.'));
164 $cur = common_current_user();
166 // Checked in prepare() above
168 assert(!is_null($cur));
170 $app = new Oauth_application();
172 $app->query('BEGIN');
175 $app->owner = $cur->id;
176 $app->description = $description;
177 $app->source_url = $souce_url;
178 $app->organization = $organization;
179 $app->homepage = $homepage;
180 $app->callback_url = $callback_url;
182 $app->access_type = $access_type;
184 // generate consumer key and secret
186 $app->created = common_sql_now();
188 $result = $app->insert();
191 common_log_db_error($group, 'INSERT', __FILE__);
192 $this->serverError(_('Could not create application.'));
195 $group->query('COMMIT');
197 common_redirect($group->homeUrl(), 303);