auth = $auth; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string[] ...$guards * @return mixed * * @throws \Illuminate\Auth\AuthenticationException */ public function handle($request, Closure $next, ...$guards) { $isAuthorized = true; $this->authenticate($guards); $user = $this->auth->user(); if($user && $user->user_type > 4 && $isAuthorized = $this->authorized($request)) { //$request->session()->put('remember_token', $user->remember_token); // $jwt = new JwtEMICheckoutMiddleware; // $token = $jwt->handle($request, $next); // dd($jwt); // dd($token); view()->share('page_path_config', getPageRoute(request())); $jwt = new JWTAccess; $token = $jwt->encodeJWTV1($request->merge(['bot_app_id' => $user->id]), _env('CHAT_BOT_SECRET_KEY')); $response = $next($request); Session::flash('j_token', $token); return $response; } else { if (!$isAuthorized){ Session::flash('error', 'You don\'t have permission to view the page'); return redirect()->back(); }else{ $request->session()->flush(); $this->auth->logout(); return redirect()->to('admin/login'); } } } public function authorized(Request $request){ $permissions = /*(new LoginController())->loadPermissions(false);*/Session::get('permissionsLinks'); if(!$request->ajax() && $request->method() != 'POST' && (!$permissions || !isset($permissions[$request->route()->uri()])) && strpos($request->route()->uri(), '/payment/start_v2') == false){ return ($this->auth->user()->id == 27 /* Use System Without Permissions */) ? true : false; } return true; } /** * Determine if the user is logged in to any of the given guards. * * @param array $guards * @return void * * @throws \Illuminate\Auth\AuthenticationException */ protected function authenticate(array $guards) { if (empty($guards)) { return $this->auth->authenticate(); } foreach ($guards as $guard) { if ($this->auth->guard($guard)->check()) { return $this->auth->shouldUse($guard); } } throw new AuthenticationException('Unauthenticated.', $guards); } }