make block action use ProfileFormAction superclass

This commit is contained in:
Evan Prodromou 2009-11-16 16:14:49 +01:00
parent 985986e7e9
commit e290f86c99
1 changed files with 20 additions and 45 deletions

View File

@ -42,9 +42,11 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/ * @link http://status.net/
*/ */
class BlockAction extends Action
class BlockAction extends ProfileFormAction
{ {
var $profile = null; var $profile = null;
/** /**
* Take arguments for running * Take arguments for running
* *
@ -52,28 +54,22 @@ class BlockAction extends Action
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) function prepare($args)
{ {
parent::prepare($args); if (!parent::prepare($args)) {
if (!common_logged_in()) {
$this->clientError(_('Not logged in.'));
return false; return false;
} }
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) { $cur = common_current_user();
$this->clientError(_('There was a problem with your session token. Try again, please.'));
return; assert(!empty($cur)); // checked by parent
}
$id = $this->trimmed('profileid'); if ($cur->hasBlocked($this->profile)) {
if (!$id) { $this->clientError(_("You already blocked that user."));
$this->clientError(_('No profile specified.'));
return false;
}
$this->profile = Profile::staticGet('id', $id);
if (!$this->profile) {
$this->clientError(_('No profile with that ID.'));
return false; return false;
} }
return true; return true;
} }
@ -86,17 +82,15 @@ class BlockAction extends Action
* *
* @return void * @return void
*/ */
function handle($args) function handle($args)
{ {
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($this->arg('no')) { if ($this->arg('no')) {
$cur = common_current_user(); $this->returnToArgs();
$other = Profile::staticGet('id', $this->arg('blockto'));
common_redirect(common_local_url('showstream', array('nickname' => $other->nickname)),
303);
} elseif ($this->arg('yes')) { } elseif ($this->arg('yes')) {
$this->blockProfile(); $this->handlePost();
$this->returnToArgs();
} else { } else {
$this->showPage(); $this->showPage();
} }
@ -157,36 +151,17 @@ class BlockAction extends Action
* *
* @return void * @return void
*/ */
function blockProfile()
function handlePost()
{ {
$cur = common_current_user(); $cur = common_current_user();
if ($cur->hasBlocked($this->profile)) {
$this->clientError(_('You have already blocked this user.'));
return;
}
$result = $cur->block($this->profile); $result = $cur->block($this->profile);
if (!$result) { if (!$result) {
$this->serverError(_('Failed to save block information.')); $this->serverError(_('Failed to save block information.'));
return; 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);
}
} }
} }