for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of Laravel Ban.
*
* (c) Anton Komarev <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cog\Laravel\Ban\Http\Middleware;
use Closure;
use Cog\Contracts\Ban\Bannable as BannableContract;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\StatefulGuard as StatefulGuardContract;
/**
* Class LogsOutBannedUser.
* @package Cog\Laravel\Ban\Http\Middleware
class LogsOutBannedUser
{
* The Guard implementation.
* @var \Illuminate\Contracts\Auth\Guard
protected $auth;
* @param \Illuminate\Contracts\Auth\Guard $auth
public function __construct(Guard $auth)
$this->auth = $auth;
}
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
* @throws \Exception
public function handle($request, Closure $next)
$user = $this->auth->user();
if ($user && $user instanceof BannableContract && $user->isBanned()) {
if ($this->auth instanceof StatefulGuardContract) {
// TODO: Cover with tests
$this->auth->logout();
return redirect()->back()->withInput()->withErrors([
'login' => 'This account is blocked.',
]);
return $next($request);