Files
UNIT3D-Community-Edition/app/Http/Middleware/CheckIfBanned.php
HDVinnie 4afdfbdade Apply fixes from StyleCI
[ci skip] [skip ci]
2020-04-19 05:31:13 +00:00

48 lines
1.3 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Middleware;
use App\Models\Group;
use Closure;
class CheckIfBanned
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @throws \Exception
*
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
$user = $request->user();
$banned_group = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
if ($user && $user->group_id == $banned_group[0]) {
auth()->logout();
$request->session()->flush();
return redirect()->route('login')
->withErrors('This account is Banned!');
}
return $next($request);
}
}