parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->handlePost($args);
- } else {
- $this->showForm();
- }
+ $this->handlePost($args);
+ } else {
+ $this->showForm();
+ }
}
function handlePost($args)
{
- // Workaround for PHP returning empty $_POST and $_FILES when POST
+ // Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
if (empty($_FILES)
&& empty($_POST)
&& ($_SERVER['CONTENT_LENGTH'] > 0)
- ) {
+ ) {
$msg = _('The server was unable to handle that much POST ' .
- 'data (%s bytes) due to its current configuration.');
+ 'data (%s bytes) due to its current configuration.');
$this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
- // CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->clientError(_('There was a problem with your session token.'));
- return;
- }
-
- $cur = common_current_user();
-
- if ($this->arg('cancel')) {
- common_redirect(common_local_url('showapplication',
- array(
- 'nickname' => $cur->nickname,
- 'id' => $this->app->id)
- ), 303);
- } elseif ($this->arg('save')) {
- $this->trySave();
- } else {
- $this->clientError(_('Unexpected form submission.'));
- }
+ // CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->clientError(_('There was a problem with your session token.'));
+ return;
+ }
+
+ $cur = common_current_user();
+
+ if ($this->arg('cancel')) {
+ common_redirect(common_local_url('showapplication',
+ array(
+ 'nickname' => $cur->nickname,
+ 'id' => $this->app->id)
+ ), 303);
+ } elseif ($this->arg('save')) {
+ $this->trySave();
+ } else {
+ $this->clientError(_('Unexpected form submission.'));
+ }
}
function showForm($msg=null)
$access_type = $this->arg('default_access_type');
if (empty($name)) {
- $this->showForm(_('Name is required.'));
- return;
+ $this->showForm(_('Name is required.'));
+ return;
} elseif (mb_strlen($name) > 255) {
$this->showForm(_('Name is too long (max 255 chars).'));
return;
} elseif (Oauth_application::descriptionTooLong($description)) {
$this->showForm(sprintf(
_('Description is too long (max %d chars).'),
- Oauth_application::maxDescription()));
+ Oauth_application::maxDescription()));
return;
- } elseif (empty($source_url)) {
- $this->showForm(_('Source URL is required.'));
- return;
- } elseif ((strlen($source_url) > 0)
- && !Validate::uri(
- $source_url,
- array('allowed_schemes' => array('http', 'https'))
- )
- )
- {
- $this->showForm(_('Source URL is not valid.'));
+ } elseif (mb_strlen($source_url) > 255) {
+ $this->showForm(_('Source URL is too long.'));
return;
+ } elseif ((mb_strlen($source_url) > 0)
+ && !Validate::uri($source_url,
+ array('allowed_schemes' => array('http', 'https'))))
+ {
+ $this->showForm(_('Source URL is not valid.'));
+ return;
} elseif (empty($organization)) {
$this->showForm(_('Organization is required.'));
return;
} elseif (empty($homepage)) {
$this->showForm(_('Organization homepage is required.'));
return;
- } elseif ((strlen($homepage) > 0)
- && !Validate::uri(
- $homepage,
- array('allowed_schemes' => array('http', 'https'))
- )
- )
- {
- $this->showForm(_('Homepage is not a valid URL.'));
- return;
- } elseif (empty($callback_url)) {
- $this->showForm(_('Callback is required.'));
- return;
- } elseif (strlen($callback_url) > 0
- && !Validate::uri(
- $source_url,
- array('allowed_schemes' => array('http', 'https'))
- )
- )
- {
- $this->showForm(_('Callback URL is not valid.'));
- return;
- }
+ } elseif ((mb_strlen($homepage) > 0)
+ && !Validate::uri($homepage,
+ array('allowed_schemes' => array('http', 'https'))))
+ {
+ $this->showForm(_('Homepage is not a valid URL.'));
+ return;
+ } elseif (mb_strlen($callback_url) > 255) {
+ $this->showForm(_('Callback is too long.'));
+ return;
+ } elseif (mb_strlen($callback_url) > 0
+ && !Validate::uri($source_url,
+ array('allowed_schemes' => array('http', 'https'))
+ ))
+ {
+ $this->showForm(_('Callback URL is not valid.'));
+ return;
+ }
$cur = common_current_user();
// Checked in prepare() above
assert(!is_null($cur));
- assert(!is_null($this->app));
+ assert(!is_null($this->app));
$orig = clone($this->app);
$this->app->callback_url = $callback_url;
$this->app->type = $type;
- $result = $this->app->update($orig);
-
- common_debug("access_type = $access_type");
+ common_debug("access_type = $access_type");
if ($access_type == 'r') {
$this->app->access_type = 1;
$this->app->access_type = 3;
}
+ $result = $this->app->update($orig);
+
if (!$result) {
common_log_db_error($this->app, 'UPDATE', __FILE__);
$this->serverError(_('Could not update application.'));
}
+ $this->app->uploadLogo();
+
common_redirect(common_local_url('apps',
array('nickname' => $cur->nickname)), 303);
}
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->handlePost($args);
+ $this->handlePost($args);
} else {
$this->showForm();
}
function handlePost($args)
{
- // Workaround for PHP returning empty $_POST and $_FILES when POST
+ // Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
if (empty($_FILES)
&& empty($_POST)
&& ($_SERVER['CONTENT_LENGTH'] > 0)
- ) {
+ ) {
$msg = _('The server was unable to handle that much POST ' .
- 'data (%s bytes) due to its current configuration.');
+ 'data (%s bytes) due to its current configuration.');
$this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
- // CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->clientError(_('There was a problem with your session token.'));
- return;
- }
-
- $cur = common_current_user();
-
- if ($this->arg('cancel')) {
- common_redirect(common_local_url('apps',
- array('nickname' => $cur->nickname)), 303);
- } elseif ($this->arg('save')) {
- $this->trySave();
- } else {
- $this->clientError(_('Unexpected form submission.'));
- }
+ // CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->clientError(_('There was a problem with your session token.'));
+ return;
+ }
+
+ $cur = common_current_user();
+
+ if ($this->arg('cancel')) {
+ common_redirect(common_local_url('apps',
+ array('nickname' => $cur->nickname)), 303);
+ } elseif ($this->arg('save')) {
+ $this->trySave();
+ } else {
+ $this->clientError(_('Unexpected form submission.'));
+ }
}
function showForm($msg=null)
function trySave()
{
- $name = $this->trimmed('name');
+ $name = $this->trimmed('name');
$description = $this->trimmed('description');
$source_url = $this->trimmed('source_url');
$organization = $this->trimmed('organization');
{
$this->showForm(_('Homepage is not a valid URL.'));
return;
- } elseif (empty($callback_url)) {
- $this->showForm(_('Callback is required.'));
+ } elseif (mb_strlen($callback_url) > 255) {
+ $this->showForm(_('Callback is too long.'));
return;
} elseif (strlen($callback_url) > 0
&& !Validate::uri(
$app->query('ROLLBACK');
}
- $this->uploadLogo($app);
+ $this->app->uploadLogo();
$app->query('COMMIT');
}
- /**
- * Handle an image upload
- *
- * Does all the magic for handling an image upload, and crops the
- * image by default.
- *
- * @return void
- */
-
- function uploadLogo($app)
- {
- if ($_FILES['app_icon']['error'] ==
- UPLOAD_ERR_OK) {
-
- try {
- $imagefile = ImageFile::fromUpload('app_icon');
- } catch (Exception $e) {
- common_debug("damn that sucks");
- $this->showForm($e->getMessage());
- return;
- }
-
- $filename = Avatar::filename($app->id,
- image_type_to_extension($imagefile->type),
- null,
- 'oauth-app-icon-'.common_timestamp());
-
- $filepath = Avatar::path($filename);
-
- move_uploaded_file($imagefile->filepath, $filepath);
-
- $app->setOriginal($filename);
- }
- }
-
}
/* Static get */
function staticGet($k,$v=NULL) {
- return Memcached_DataObject::staticGet('Oauth_application',$k,$v);
+ return Memcached_DataObject::staticGet('Oauth_application',$k,$v);
}
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
static function getByConsumerKey($key)
{
- if (empty($key)) {
- return null;
- }
+ if (empty($key)) {
+ return null;
+ }
+
+ $app = new Oauth_application();
+ $app->consumer_key = $key;
+ $app->limit(1);
+ $result = $app->find(true);
+
+ return empty($result) ? null : $app;
+ }
+
+ /**
+ * Handle an image upload
+ *
+ * Does all the magic for handling an image upload, and crops the
+ * image by default.
+ *
+ * @return void
+ */
- $app = new Oauth_application();
- $app->consumer_key = $key;
- $app->limit(1);
- $result = $app->find(true);
+ function uploadLogo()
+ {
+ if ($_FILES['app_icon']['error'] ==
+ UPLOAD_ERR_OK) {
- return empty($result) ? null : $app;
+ try {
+ $imagefile = ImageFile::fromUpload('app_icon');
+ } catch (Exception $e) {
+ common_debug("damn that sucks");
+ $this->showForm($e->getMessage());
+ return;
+ }
+
+ $filename = Avatar::filename($this->id,
+ image_type_to_extension($imagefile->type),
+ null,
+ 'oauth-app-icon-'.common_timestamp());
+
+ $filepath = Avatar::path($filename);
+
+ move_uploaded_file($imagefile->filepath, $filepath);
+
+ $this->setOriginal($filename);
+ }
}
}