summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-11-16 16:14:49 +0100
committerEvan Prodromou <evan@status.net>2009-11-16 16:14:49 +0100
commite290f86c99f64385a9fdb9c94424beff0d3e3e82 (patch)
treef74777c897718d8743e7e62f1809a633ad8ff069
parent985986e7e94862a943271b9c3030b35e74bc28e1 (diff)
make block action use ProfileFormAction superclass
-rw-r--r--actions/block.php65
1 files changed, 20 insertions, 45 deletions
diff --git a/actions/block.php b/actions/block.php
index 2443b3010..71a34e087 100644
--- a/actions/block.php
+++ b/actions/block.php
@@ -42,9 +42,11 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*/
-class BlockAction extends Action
+
+class BlockAction extends ProfileFormAction
{
var $profile = null;
+
/**
* Take arguments for running
*
@@ -52,28 +54,22 @@ class BlockAction extends Action
*
* @return boolean success flag
*/
+
function prepare($args)
{
- parent::prepare($args);
- if (!common_logged_in()) {
- $this->clientError(_('Not logged in.'));
- return false;
- }
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->clientError(_('There was a problem with your session token. Try again, please.'));
- return;
- }
- $id = $this->trimmed('profileid');
- if (!$id) {
- $this->clientError(_('No profile specified.'));
+ if (!parent::prepare($args)) {
return false;
}
- $this->profile = Profile::staticGet('id', $id);
- if (!$this->profile) {
- $this->clientError(_('No profile with that ID.'));
+
+ $cur = common_current_user();
+
+ assert(!empty($cur)); // checked by parent
+
+ if ($cur->hasBlocked($this->profile)) {
+ $this->clientError(_("You already blocked that user."));
return false;
}
+
return true;
}
@@ -86,17 +82,15 @@ class BlockAction extends Action
*
* @return void
*/
+
function handle($args)
{
- parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($this->arg('no')) {
- $cur = common_current_user();
- $other = Profile::staticGet('id', $this->arg('blockto'));
- common_redirect(common_local_url('showstream', array('nickname' => $other->nickname)),
- 303);
+ $this->returnToArgs();
} elseif ($this->arg('yes')) {
- $this->blockProfile();
+ $this->handlePost();
+ $this->returnToArgs();
} else {
$this->showPage();
}
@@ -157,36 +151,17 @@ class BlockAction extends Action
*
* @return void
*/
- function blockProfile()
+
+ function handlePost()
{
$cur = common_current_user();
- if ($cur->hasBlocked($this->profile)) {
- $this->clientError(_('You have already blocked this user.'));
- return;
- }
$result = $cur->block($this->profile);
+
if (!$result) {
$this->serverError(_('Failed to save block information.'));
return;
}
-
- // Now, gotta figure where we go back to
- foreach ($this->args as $k => $v) {
- if ($k == 'returnto-action') {
- $action = $v;
- } elseif (substr($k, 0, 9) == 'returnto-') {
- $args[substr($k, 9)] = $v;
- }
- }
-
- if ($action) {
- common_redirect(common_local_url($action, $args), 303);
- } else {
- common_redirect(common_local_url('subscribers',
- array('nickname' => $cur->nickname)),
- 303);
- }
}
}