v2board/app/Http/Middleware/User.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
namespace App\Http\Middleware;
use Closure;
class User
{
/**
* Handle an incoming request.
*
2020-01-11 13:36:52 +08:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
2019-10-29 15:33:36 +08:00
* @return mixed
*/
public function handle($request, Closure $next)
{
2021-02-19 00:15:37 +08:00
if ($request->input('auth_data')) {
$authData = explode(':', base64_decode($request->input('auth_data')));
2021-07-01 17:16:27 +08:00
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
2021-02-19 00:15:37 +08:00
$user = \App\Models\User::where('password', $authData[1])
->where('email', $authData[0])
->first();
2021-07-01 17:16:27 +08:00
if (!$user) abort(403, '鉴权失败,请重新登入');
2021-06-25 21:35:14 +08:00
$request->session()->put('email', $user->email);
$request->session()->put('id', $user->id);
2020-02-11 21:04:47 +08:00
}
// if ($request->input('lang')) {
// $request->session()->put('lang', $request->input('lang'));
// }
// if ($request->session()->get('lang')) {
// App::setLocale($request->session()->get('lang'));
// }
2019-10-29 15:33:36 +08:00
if (!$request->session()->get('id')) {
abort(403, '未登录或登陆已过期');
}
return $next($request);
}
}