update: new auth

This commit is contained in:
tokumeikoi
2022-07-11 14:48:35 +08:00
parent 2073727a0a
commit dc27410c12
28 changed files with 117 additions and 123 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Middleware;
use App\Utils\Helper;
use Closure;
class User
@ -16,19 +17,17 @@ class User
public function handle($request, Closure $next)
{
$authorization = $request->input('auth_data') ?? $request->header('authorization');
if ($authorization) {
$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, '鉴权失败,请重新登入');
$request->session()->put('email', $user->email);
$request->session()->put('id', $user->id);
}
if (!$request->session()->get('id')) {
abort(403, '未登录或登陆已过期');
}
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, '鉴权失败,请重新登入');
$request->merge([
'user' => $user
]);
return $next($request);
}
}