mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
[exam] finish assign and remove
This commit is contained in:
31
app/Http/Middleware/Permission.php
Normal file
31
app/Http/Middleware/Permission.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\UnauthorizedException;
|
||||
|
||||
class Permission
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$user = $request->user();
|
||||
$targetClass = User::CLASS_MODERATOR;
|
||||
$log = sprintf('user: %s, class: %s, target class: %s', $user->id, $user->class, $targetClass);
|
||||
if (!$user || $user->class < $targetClass) {
|
||||
do_log("$log, denied!");
|
||||
throw new UnauthorizedException('Unauthorized!');
|
||||
}
|
||||
do_log("$log, pass!");
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user