mirror of
https://github.com/v2board/v2board.git
synced 2025-06-16 14:47:48 +08:00
update: new auth
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Laravel\Horizon\Horizon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Admin
|
||||
{
|
||||
@ -20,14 +20,23 @@ class Admin
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$authData = explode(':', base64_decode($authorization));
|
||||
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
|
||||
$user = \App\Models\User::where('password', $authData[1])
|
||||
->where('email', $authData[0])
|
||||
->first();
|
||||
if (!$user) abort(403, '鉴权失败,请重新登入');
|
||||
if (!$user->is_admin) abort(403, '未登录或登陆已过期');
|
||||
if (!Cache::has($authorization)) {
|
||||
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
|
||||
$user = \App\Models\User::where('password', $authData[1])
|
||||
->where('email', $authData[0])
|
||||
->select([
|
||||
'id',
|
||||
'email',
|
||||
'is_admin',
|
||||
'is_staff'
|
||||
])
|
||||
->first();
|
||||
if (!$user) abort(403, '鉴权失败,请重新登入');
|
||||
if (!$user->is_admin) abort(403, '鉴权失败,请重新登入');
|
||||
Cache::put($authorization, $user->toArray(), 3600);
|
||||
}
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
'user' => Cache::get($authorization)
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
|
Reference in New Issue
Block a user