TODO: Break OAuth out into a plugin.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-class NewApplicationAction extends FormAction
+class NewApplicationAction extends SettingsAction
{
function title()
{
if ($this->arg('cancel')) {
common_redirect(common_local_url('oauthappssettings'), 303);
} elseif ($this->arg('save')) {
+ //trySave will never return, just throw exception or redirect
$this->trySave();
}
return _('Use this form to register a new application.');
}
- private function trySave()
+ protected function trySave()
{
$name = $this->trimmed('name');
$description = $this->trimmed('description');
$app->query('BEGIN');
$app->name = $name;
- $app->owner = $this->scoped->id;
+ $app->owner = $this->scoped->getID();
$app->description = $description;
$app->source_url = $source_url;
$app->organization = $organization;
class OauthappssettingsAction extends SettingsAction
{
- var $page = 0;
+ protected $page = null;
- function prepare($args)
+ protected function doPreparation()
{
- parent::prepare($args);
- $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
-
- if (!common_logged_in()) {
- // TRANS: Message displayed to an anonymous user trying to view OAuth application list.
- $this->clientError(_('You must be logged in to list your applications.'));
- }
-
- return true;
+ $this->page = $this->int('page') ?: 1;
}
/**
return _('Applications you have registered');
}
- /**
- * Content area of the page
- *
- * @return void
- */
-
function showContent()
{
- $user = common_current_user();
-
$offset = ($this->page - 1) * APPS_PER_PAGE;
$limit = APPS_PER_PAGE + 1;
$application = new Oauth_application();
- $application->owner = $user->id;
+ $application->owner = $this->scoped->getID();
$application->whereAdd("name != 'anonymous'");
$application->limit($offset, $limit);
$application->orderBy('created DESC');
$cnt = 0;
if ($application) {
- $al = new ApplicationList($application, $user, $this);
+ $al = new ApplicationList($application, $this->scoped, $this);
$cnt = $al->show();
if (0 == $cnt) {
$this->showEmptyListMessage();
function showEmptyListMessage()
{
- // TRANS: Empty list message on page with OAuth applications.
+ // TRANS: Empty list message on page with OAuth applications. Markup allowed
$message = sprintf(_('You have not registered any applications yet.'));
$this->elementStart('div', 'guide');
$this->raw(common_markup_to_html($message));
$this->elementEnd('div');
}
-
- /**
- * Handle posts to this form
- *
- * Based on the button that was pressed, muxes out to other functions
- * to do the actual task requested.
- *
- * All sub-functions reload the form with a message -- success or failure.
- *
- * @return void
- */
-
- function handlePost()
- {
- // CSRF protection
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->showForm(_('There was a problem with your session token. '.
- 'Try again, please.'));
- return;
- }
- }
}
*/
class OauthconnectionssettingsAction extends SettingsAction
{
- var $page = null;
- var $oauth_token = null;
+ var $page = null;
- function prepare($args)
+ protected $oauth_token = null;
+
+ protected function doPreparation()
{
- parent::prepare($args);
$this->oauth_token = $this->arg('oauth_token');
- $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
- return true;
+ $this->page = $this->int('page') ?: 1;
}
/**
function showContent()
{
- $user = common_current_user();
- $profile = $user->getProfile();
-
$offset = ($this->page - 1) * APPS_PER_PAGE;
$limit = APPS_PER_PAGE + 1;
- $connection = $user->getConnectedApps($offset, $limit);
+ $connection = $this->scoped->getConnectedApps($offset, $limit);
$cnt = 0;
if (!empty($connection)) {
- $cal = new ConnectedAppsList($connection, $user, $this);
+ $cal = new ConnectedAppsList($connection, $this->scoped, $this);
$cnt = $cal->show();
}
$cnt > APPS_PER_PAGE,
$this->page,
'connectionssettings',
- array('nickname' => $user->nickname)
+ array('nickname' => $this->scoped->getNickname())
);
}
*
* @return void
*/
- function handlePost()
+ protected function doPost()
{
- // CSRF protection
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- // TRANS: Client error displayed when the session token does not match or is not given.
- $this->showForm(_('There was a problem with your session token. '.
- 'Try again, please.'));
- return;
- }
-
if ($this->arg('revoke')) {
- $this->revokeAccess($this->oauth_token);
- } else {
- // TRANS: Client error when submitting a form with unexpected information.
- $this->clientError(_('Unexpected form submission.'), 401);
+ return $this->revokeAccess($this->oauth_token);
}
+
+ // TRANS: Client error when submitting a form with unexpected information.
+ throw new ClientException(_('Unexpected form submission.'), 401);
}
/**
public function setPref($namespace, $topic, $data) {
return Profile_prefs::setData($this, $namespace, $topic, $data);
}
+
+ public function getConnectedApps($offset=0, $limit=null)
+ {
+ return $this->getUser()->getConnectedApps($offset, $limit);
+ }
}
/** Owner of this list */
var $owner = null;
- /** Action object using us. */
- var $action = null;
-
- function __construct($application, $owner=null, $action=null)
+ function __construct($application, Profile $owner, Action $out=null)
{
- parent::__construct($action);
+ parent::__construct($out);
$this->application = $application;
$this->owner = $owner;
- $this->action = $action;
}
function show()
if($cnt > APPS_PER_PAGE) {
break;
}
- $this->showapplication();
+ $this->showApplication();
}
$this->out->elementEnd('ul');
function showApplication()
{
- $user = common_current_user();
-
$this->out->elementStart('li', array('class' => 'application h-entry',
'id' => 'oauthclient-' . $this->application->id));
/** Owner of this list */
var $owner = null;
- /** Action object using us. */
- var $action = null;
-
- function __construct($connection, $owner=null, $action=null)
+ function __construct($connection, Profile $owner, Action $out=null)
{
- parent::__construct($action);
+ parent::__construct($out);
common_debug("ConnectedAppsList constructor");
$this->connection = $connection;
- $this->owner = $owner;
- $this->action = $action;
+ $this->owner = $owner;
}
/* Override this in subclasses. */