summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/apioauthauthorize.php58
-rw-r--r--actions/deleteapplication.php176
-rw-r--r--actions/editapplication.php24
-rw-r--r--actions/newapplication.php20
-rw-r--r--actions/oauthconnectionssettings.php24
-rw-r--r--actions/showapplication.php19
6 files changed, 288 insertions, 33 deletions
diff --git a/actions/apioauthauthorize.php b/actions/apioauthauthorize.php
index dec0dc9f6..e7c6f3761 100644
--- a/actions/apioauthauthorize.php
+++ b/actions/apioauthauthorize.php
@@ -67,8 +67,6 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
{
parent::prepare($args);
- common_debug("apioauthauthorize");
-
$this->nickname = $this->trimmed('nickname');
$this->password = $this->arg('password');
$this->oauth_token = $this->arg('oauth_token');
@@ -99,24 +97,17 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
} else {
- // XXX: make better error messages
-
if (empty($this->oauth_token)) {
-
- common_debug("No request token found.");
-
- $this->clientError(_('Bad request.'));
+ $this->clientError(_('No oauth_token parameter provided.'));
return;
}
if (empty($this->app)) {
- common_debug('No app for that token.');
- $this->clientError(_('Bad request.'));
+ $this->clientError(_('Invalid token.'));
return;
}
$name = $this->app->name;
- common_debug("Requesting auth for app: " . $name);
$this->showForm();
}
@@ -124,8 +115,6 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
function handlePost()
{
- common_debug("handlePost()");
-
// check session token for CSRF protection.
$token = $this->trimmed('token');
@@ -202,21 +191,15 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
// A callback specified in the app setup overrides whatever
// is passed in with the request.
- common_debug("Req token is authorized - doing callback");
-
if (!empty($this->app->callback_url)) {
$this->callback = $this->app->callback_url;
}
if (!empty($this->callback)) {
- // XXX: Need better way to build this redirect url.
-
$target_url = $this->getCallback($this->callback,
array('oauth_token' => $this->oauth_token));
- common_debug("Doing callback to $target_url");
-
common_redirect($target_url, 303);
} else {
common_debug("callback was empty!");
@@ -236,9 +219,12 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
} else if ($this->arg('deny')) {
+ $datastore = new ApiStatusNetOAuthDataStore();
+ $datastore->revoke_token($this->oauth_token, 0);
+
$this->elementStart('p');
- $this->raw(sprintf(_("The request token %s has been denied."),
+ $this->raw(sprintf(_("The request token %s has been denied and revoked."),
$this->oauth_token));
$this->elementEnd('p');
@@ -305,12 +291,15 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
$msg = _('The application <strong>%1$s</strong> by ' .
'<strong>%2$s</strong> would like the ability ' .
- 'to <strong>%3$s</strong> your account data.');
+ 'to <strong>%3$s</strong> your %4$s account data. ' .
+ 'You should only give access to your %4$s account ' .
+ 'to third parties you trust.');
$this->raw(sprintf($msg,
$this->app->name,
$this->app->organization,
- $access));
+ $access,
+ common_config('site', 'name')));
$this->elementEnd('p');
$this->elementEnd('li');
$this->elementEnd('ul');
@@ -372,6 +361,31 @@ class ApiOauthAuthorizeAction extends ApiOauthAction
function showLocalNav()
{
+ // NOP
+ }
+
+ /**
+ * Show site notice.
+ *
+ * @return nothing
+ */
+
+ function showSiteNotice()
+ {
+ // NOP
+ }
+
+ /**
+ * Show notice form.
+ *
+ * Show the form for posting a new notice
+ *
+ * @return nothing
+ */
+
+ function showNoticeForm()
+ {
+ // NOP
}
}
diff --git a/actions/deleteapplication.php b/actions/deleteapplication.php
new file mode 100644
index 000000000..17526e111
--- /dev/null
+++ b/actions/deleteapplication.php
@@ -0,0 +1,176 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Action class to delete an OAuth application
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Action
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+ exit(1);
+}
+
+/**
+ * Delete an OAuth appliction
+ *
+ * @category Action
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://status.net/
+ */
+
+class DeleteapplicationAction extends Action
+{
+ var $app = null;
+
+ /**
+ * Take arguments for running
+ *
+ * @param array $args $_REQUEST args
+ *
+ * @return boolean success flag
+ */
+
+ function prepare($args)
+ {
+ if (!parent::prepare($args)) {
+ return false;
+ }
+
+ if (!common_logged_in()) {
+ $this->clientError(_('You must be logged in to delete an application.'));
+ return false;
+ }
+
+ $id = (int)$this->arg('id');
+ $this->app = Oauth_application::staticGet('id', $id);
+
+ if (empty($this->app)) {
+ $this->clientError(_('Application not found.'));
+ return false;
+ }
+
+ $cur = common_current_user();
+
+ if ($cur->id != $this->app->owner) {
+ $this->clientError(_('You are not the owner of this application.'), 401);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Handle request
+ *
+ * Shows a page with list of favorite notices
+ *
+ * @param array $args $_REQUEST args; handled in prepare()
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+
+ // CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->clientError(_('There was a problem with your session token.'));
+ return;
+ }
+
+ if ($this->arg('no')) {
+ common_redirect(common_local_url('showapplication',
+ array('id' => $this->app->id)), 303);
+ } elseif ($this->arg('yes')) {
+ $this->handlePost();
+ common_redirect(common_local_url('oauthappssettings'), 303);
+ } else {
+ $this->showPage();
+ }
+ }
+ }
+
+ function showContent() {
+ $this->areYouSureForm();
+ }
+
+ function title() {
+ return _('Delete application');
+ }
+
+ function showNoticeForm() {
+ // nop
+ }
+
+ /**
+ * Confirm with user.
+ *
+ * Shows a confirmation form.
+ *
+ * @return void
+ */
+ function areYouSureForm()
+ {
+ $id = $this->app->id;
+ $this->elementStart('form', array('id' => 'deleteapplication-' . $id,
+ 'method' => 'post',
+ 'class' => 'form_settings form_entity_block',
+ 'action' => common_local_url('deleteapplication',
+ array('id' => $this->app->id))));
+ $this->elementStart('fieldset');
+ $this->hidden('token', common_session_token());
+ $this->element('legend', _('Delete application'));
+ $this->element('p', null,
+ _('Are you sure you want to delete this application? '.
+ 'This will clear all data about the application from the '.
+ 'database, including all existing user connections.'));
+ $this->submit('form_action-no',
+ _('No'),
+ 'submit form_action-primary',
+ 'no',
+ _("Do not delete this application"));
+ $this->submit('form_action-yes',
+ _('Yes'),
+ 'submit form_action-secondary',
+ 'yes', _('Delete this application'));
+ $this->elementEnd('fieldset');
+ $this->elementEnd('form');
+ }
+
+ /**
+ * Actually delete the app
+ *
+ * @return void
+ */
+
+ function handlePost()
+ {
+ $this->app->delete();
+ }
+}
+
diff --git a/actions/editapplication.php b/actions/editapplication.php
index 9cc3e3cea..029b622e8 100644
--- a/actions/editapplication.php
+++ b/actions/editapplication.php
@@ -179,6 +179,9 @@ class EditApplicationAction extends OwnerDesignAction
} elseif (mb_strlen($name) > 255) {
$this->showForm(_('Name is too long (max 255 chars).'));
return;
+ } else if ($this->nameExists($name)) {
+ $this->showForm(_('Name already in use. Try another one.'));
+ return;
} elseif (empty($description)) {
$this->showForm(_('Description is required.'));
return;
@@ -260,5 +263,26 @@ class EditApplicationAction extends OwnerDesignAction
common_redirect(common_local_url('oauthappssettings'), 303);
}
+ /**
+ * Does the app name already exist?
+ *
+ * Checks the DB to see someone has already registered and app
+ * with the same name.
+ *
+ * @param string $name app name to check
+ *
+ * @return boolean true if the name already exists
+ */
+
+ function nameExists($name)
+ {
+ $newapp = Oauth_application::staticGet('name', $name);
+ if (!$newapp) {
+ return false;
+ } else {
+ return $newapp->id != $this->app->id;
+ }
+ }
+
}
diff --git a/actions/newapplication.php b/actions/newapplication.php
index c499fe7c7..ba1cca5c9 100644
--- a/actions/newapplication.php
+++ b/actions/newapplication.php
@@ -158,6 +158,9 @@ class NewApplicationAction extends OwnerDesignAction
if (empty($name)) {
$this->showForm(_('Name is required.'));
return;
+ } else if ($this->nameExists($name)) {
+ $this->showForm(_('Name already in use. Try another one.'));
+ return;
} elseif (mb_strlen($name) > 255) {
$this->showForm(_('Name is too long (max 255 chars).'));
return;
@@ -273,5 +276,22 @@ class NewApplicationAction extends OwnerDesignAction
}
+ /**
+ * Does the app name already exist?
+ *
+ * Checks the DB to see someone has already registered and app
+ * with the same name.
+ *
+ * @param string $name app name to check
+ *
+ * @return boolean true if the name already exists
+ */
+
+ function nameExists($name)
+ {
+ $app = Oauth_application::staticGet('name', $name);
+ return ($app !== false);
+ }
+
}
diff --git a/actions/oauthconnectionssettings.php b/actions/oauthconnectionssettings.php
index c2e8d441b..b1467f0d0 100644
--- a/actions/oauthconnectionssettings.php
+++ b/actions/oauthconnectionssettings.php
@@ -33,6 +33,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
require_once INSTALLDIR . '/lib/connectsettingsaction.php';
require_once INSTALLDIR . '/lib/applicationlist.php';
+require_once INSTALLDIR . '/lib/apioauthstore.php';
/**
* Show connected OAuth applications
@@ -71,11 +72,6 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction
return _('Connected applications');
}
- function isReadOnly($args)
- {
- return true;
- }
-
/**
* Instructions for use
*
@@ -153,6 +149,13 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction
}
}
+ /**
+ * Revoke access to an authorized OAuth application
+ *
+ * @param int $appId the ID of the application
+ *
+ */
+
function revokeAccess($appId)
{
$cur = common_current_user();
@@ -164,6 +167,8 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction
return false;
}
+ // XXX: Transaction here?
+
$appUser = Oauth_application_user::getByKeys($cur, $app);
if (empty($appUser)) {
@@ -171,12 +176,13 @@ class OauthconnectionssettingsAction extends ConnectSettingsAction
return false;
}
- $orig = clone($appUser);
- $appUser->access_type = 0; // No access
- $result = $appUser->update();
+ $datastore = new ApiStatusNetOAuthDataStore();
+ $datastore->revoke_token($appUser->token, 1);
+
+ $result = $appUser->delete();
if (!$result) {
- common_log_db_error($orig, 'UPDATE', __FILE__);
+ common_log_db_error($orig, 'DELETE', __FILE__);
$this->clientError(_('Unable to revoke access for app: ' . $app->id));
return false;
}
diff --git a/actions/showapplication.php b/actions/showapplication.php
index a6ff425c7..d307ea452 100644
--- a/actions/showapplication.php
+++ b/actions/showapplication.php
@@ -222,18 +222,33 @@ class ShowApplicationAction extends OwnerDesignAction
$this->elementStart('li', 'entity_reset_keysecret');
$this->elementStart('form', array(
- 'id' => 'forma_reset_key',
+ 'id' => 'form_reset_key',
'class' => 'form_reset_key',
'method' => 'POST',
'action' => common_local_url('showapplication',
array('id' => $this->application->id))));
-
$this->elementStart('fieldset');
$this->hidden('token', common_session_token());
$this->submit('reset', _('Reset key & secret'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
$this->elementEnd('li');
+
+ $this->elementStart('li', 'entity_delete');
+ $this->elementStart('form', array(
+ 'id' => 'form_delete_application',
+ 'class' => 'form_delete_application',
+ 'method' => 'POST',
+ 'action' => common_local_url('deleteapplication',
+ array('id' => $this->application->id))));
+
+ $this->elementStart('fieldset');
+ $this->hidden('token', common_session_token());
+ $this->submit('delete', _('Delete'));
+ $this->elementEnd('fieldset');
+ $this->elementEnd('form');
+ $this->elementEnd('li');
+
$this->elementEnd('ul');
$this->elementEnd('div');