123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Http\Middleware;
- use App\Model\SystemRecord;
- use App\Service\EmployeeService;
- use Closure;
- use App\Service\TokenService;
- class CheckLogin
- {
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- $token=$request->header('Authorization');
- if (empty($token)) return response()->json(['code'=>1,'msg'=>'缺少登录凭证','data'=>null]);
- //校验token
- $result = TokenService::verifyToken($token);
- if ($result < 0){
- return response()->json(['code'=>1,'msg'=>TokenService::error[$result],'data'=>null]);
- }
- //校验用户
- $checkResult = EmployeeService::checkUser($result);
- list($state, $data) = $checkResult;
- if(! $state) return response()->json(['code'=>1,'msg'=>$data,'data'=>null]);
- //人员角色
- // $data['role'] = EmployeeService::getPersonRole($result);
- //人员角色的菜单
- // $data['role_menu'] = EmployeeService::getMenuByRole($result);
- //写入user信息
- $request->userData = $data;
- $this->insert($request->path(),$data);//系统操作日志
- return $next($request);
- }
- public function insert($uri,$data){
- if (getenv('HTTP_CLIENT_IP')) {
- $ip = getenv('HTTP_CLIENT_IP');
- }
- elseif (getenv('HTTP_X_REAL_IP')) {
- $ip = getenv('HTTP_X_REAL_IP');
- } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
- $ip = getenv('HTTP_X_FORWARDED_FOR');
- $ips = explode(',', $ip);
- $ip = $ips[0];
- } elseif (getenv('REMOTE_ADDR')) {
- $ip = getenv('REMOTE_ADDR');
- } else {
- $ip = '0.0.0.0';
- }
- $map = config("routemap.map");
- if(isset($map[$uri])){
- $content = $map[$uri];
- $account = $data['account'];
- SystemRecord::insert([
- 'account' => $account,
- 'crt_time' => time(),
- 'ip' => $ip,
- 'content' => $content
- ]);
- }
- }
- }
|