This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/app/controllers/BlocksController.php

30 lines
906 B
PHP
Raw Permalink Normal View History

2013-10-27 01:06:58 +02:00
<?php
class CanNotBanSelf extends Exception {}
class BlocksController extends ApplicationController
{
public function blockIp()
{
try {
IpBans::transaction(function() {
$ban = IpBans::create(array_merge($this->params()->ban, ['banned_by' => current_user()->id]));
if (IpBans::where("id = ? and ip_addr = ?", $ban->id, $this->request()->remoteIp())->first()) {
throw new CanNotBanSelf();
}
});
} catch (CanNotBanSelf $e) {
$this->notice("You can not ban yourself");
}
$this->redirectTo('user#show_blocked_users');
}
public function unblockIp()
{
foreach (array_keys($this->params()->ip_ban) as $ban_id) {
IpBans::destroyAll("id = ?", $ban_id);
}
$this->redirectTo("user#show_blocked_users");
}
}