make block actions use profileformaction superclass

This commit is contained in:
Evan Prodromou 2009-11-16 14:40:04 +01:00
parent 64677fc09a
commit ff88ef407a
3 changed files with 18 additions and 64 deletions

View File

@ -64,7 +64,7 @@ class BlockAction extends Action
$this->clientError(_('There was a problem with your session token. Try again, please.')); $this->clientError(_('There was a problem with your session token. Try again, please.'));
return; return;
} }
$id = $this->trimmed('blockto'); $id = $this->trimmed('profileid');
if (!$id) { if (!$id) {
$this->clientError(_('No profile specified.')); $this->clientError(_('No profile specified.'));
return false; return false;
@ -97,7 +97,7 @@ class BlockAction extends Action
303); 303);
} elseif ($this->arg('yes')) { } elseif ($this->arg('yes')) {
$this->blockProfile(); $this->blockProfile();
} elseif ($this->arg('blockto')) { } else {
$this->showPage(); $this->showPage();
} }
} }
@ -138,7 +138,7 @@ class BlockAction extends Action
'unable to subscribe to you in the future, and '. 'unable to subscribe to you in the future, and '.
'you will not be notified of any @-replies from them.')); 'you will not be notified of any @-replies from them.'));
$this->element('input', array('id' => 'blockto-' . $id, $this->element('input', array('id' => 'blockto-' . $id,
'name' => 'blockto', 'name' => 'profileid',
'type' => 'hidden', 'type' => 'hidden',
'value' => $id)); 'value' => $id));
foreach ($this->args as $k => $v) { foreach ($this->args as $k => $v) {

View File

@ -42,57 +42,25 @@ 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 UnblockAction extends Action
{
var $profile = null;
/** class UnblockAction extends ProfileFormAction
* Take arguments for running {
*
* @param array $args $_REQUEST args
*
* @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()) {
$this->clientError(_('There was a problem with your session token. Try again, please.'));
return;
}
$id = $this->trimmed('unblockto');
if (!$id) {
$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 true;
}
/** $cur = common_current_user();
* Handle request
* assert(!empty($cur)); // checked by parent
* Shows a page with list of favorite notices
* if (!$cur->hasBlocked($this->profile)) {
* @param array $args $_REQUEST args; handled in prepare() $this->clientError(_("You haven't blocked that user."));
* return false;
* @return void
*/
function handle($args)
{
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->unblockProfile();
} }
return true;
} }
/** /**
@ -100,7 +68,8 @@ class UnblockAction extends Action
* *
* @return void * @return void
*/ */
function unblockProfile()
function handlePost()
{ {
$cur = common_current_user(); $cur = common_current_user();
$result = $cur->unblock($this->profile); $result = $cur->unblock($this->profile);
@ -108,20 +77,5 @@ class UnblockAction extends Action
$this->serverError(_('Error removing the block.')); $this->serverError(_('Error removing the block.'));
return; return;
} }
foreach ($this->args as $k => $v) {
if ($k == 'returnto-action') {
$action = $v;
} else if (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);
}
}
}

View File

@ -134,6 +134,6 @@ class ProfileFormAction extends Action
function handlePost() function handlePost()
{ {
return; $this->serverError(_("unimplemented method"));
} }
} }