middleware('guest')->except('logout'); } public function username(): string { return 'name'; } /** * Handle a login request to the application. * * @param Request $request * @return array|JsonResponse|RedirectResponse|Response|\Symfony\Component\HttpFoundation\Response|void * * @throws ValidationException */ public function login(Request $request) { $rule = [ $this->username() => 'required|string', 'password' => 'required|string', ]; if($request['is_json']){ $errors=Validator::make($request->all(),$rule)->errors(); if($errors->count()>0){ return ['success'=>false,'errors'=>$errors]; } }else{ $request->validate($rule); } if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) { $this->fireLockoutEvent($request); if($request['is_json']){ return ['success'=>false,'message'=>'登录请求过于频繁']; } return $this->sendLockoutResponse($request); } if ($this->attemptLogin($request)) { if(env('DB_USERNAME')!='developer') app('LogService')->log(__METHOD__,__FUNCTION__,'',Auth::user()['id']); if($request['is_json']){ return ['success'=>true,'url'=>url($this->redirectTo)]; } return $this->sendLoginResponse($request)->header('Cache-Control','no-store'); } $this->incrementLoginAttempts($request); if(env('DB_USERNAME')!='developer') app('LogService')->log(__METHOD__,__FUNCTION__,'',Auth::user()['id']); if($request['is_json']){ return ['success'=>false,'errors'=>['name'=>['登录信息验证失败']]]; } return $this->sendFailedLoginResponse($request); } }