/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if (!$request->is("sitemap") && $request->fullUrl() != '' && $this->auth->guest()) { $aSiteMap = \Cache::get('sitemap', []); $changefreq = 'always'; if (!empty($aSiteMap[$request->fullUrl()]['added'])) { $aDateDiff = Carbon::createFromTimestamp($aSiteMap[$request->fullUrl()]['added'])->diff(Carbon::now()); if ($aDateDiff->y > 0) { $changefreq = 'yearly'; } else { if ($aDateDiff->m > 0) { $changefreq = 'monthly'; } else { if ($aDateDiff->d > 6) { $changefreq = 'weekly'; } else { if ($aDateDiff->d > 0 && $aDateDiff->d < 7) { $changefreq = 'daily'; } else { if ($aDateDiff->h > 0) { $changefreq = 'hourly'; } else { $changefreq = 'always'; } } } } } } $aSiteMap[$request->fullUrl()] = ['added' => time(), 'lastmod' => Carbon::now()->toIso8601String(), 'priority' => 1 - substr_count($request->getPathInfo(), '/') / 10, 'changefreq' => $changefreq]; \Cache::put('sitemap', $aSiteMap, 2880); } return $next($request); }
public function handle($request, Closure $next, $limit = self::DEFAULT_LIMIT, $time_in_mins = self::DEFAULT_TIME) { $response = $next($request); $key = sprintf('api:%s', $request->getClientIp()); \Cache::add($key, 0, $time_in_mins); $count = \Cache::increment($key); if ($count > $limit) { $response->setContent('..........'); } $response->header('X-RateLimit-Time', $time_in_mins)->header('X-RateLimit-Limit', $limit); return $response; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next, $perm) { //$authUserRoles = $request->user()->roles()->first(); //$AuthUserRolePerms = $authUserRoles->perms()->get()->lists('name')->toArray(); //dd(\Crypt::decrypt(\Session::get('permission.Users'))); //dd($perm); //dd(\Cache::get($perm)); if (in_array($perm, [\Cache::get($perm)], true)) { return $next($request); } //Auth::logout(); dd('blocked cookie here'); /*return redirect('home')->with(['error' => 'messages.error.access_denied']) ->withCookie(Cookie::make('blocked', Crypt::encrypt('blocked'), '1'));*/ }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } if (auth()->user()->confirmed == 0) { Auth::logout(); return redirect()->guest('login'); } $menus_id = AdminMenuRole::whereIn('role_id', function ($query) { return $query->from(AdminAssignedRole::query()->getModel()->getTable())->select("role_id")->where('user_id', auth()->user()->id); })->lists('menu_id'); $_menus = AdminMenu::with(array('menus' => function ($query) use($menus_id) { $query->whereIn('id', $menus_id); $query->where('parent_id', '>', 0); $query->orderBy('order_by', 'asc'); }))->where('parent_id', 0)->orderBy('order_by', 'asc')->get(); view()->share('_menus', $_menus); $menus = []; $_menus = $_menus->pluck("menus")->toArray(); foreach ($_menus as $v) { $menus = array_merge($menus, $v); } $routes = array_pluck($menus, 'route'); $routes = str_replace(["/"], ["\\/"], $routes); array_walk($routes, function (&$v, $k) { $v = "^{$v}*"; }); $all_routes = \Cache::get("all_routes", function () { $all_routes = AdminMenu::where('parent_id', '>', 0)->lists("route")->toArray(); $all_routes = str_replace(["/"], ["\\/"], $all_routes); array_walk($all_routes, function (&$v, $k) { $v = "^{$v}*"; }); \Cache::forever("all_routes", $all_routes); return $all_routes; }); $currentRoute = Route::currentRouteName(); if (!preg_match('/' . implode("|", $routes) . '/', $currentRoute) && preg_match('/' . implode("|", $all_routes) . '/', $currentRoute)) { return redirect()->to("/"); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $array = []; /* $t = microtime(true); $micro = sprintf("%06d",($t - floor($t)) * 1000000); $d = new \DateTime( date('Y-m-d H:i:s.'.$micro, $t) ); */ $time_now = Carbon::now(); //$dd = "2016-03-20T18:00:30+0000" ; $dd = $time_now->toIso8601String(); // $microSeconds = str_replace("+0000","+02:00", $dd); if (!$request->is("sitemap") && $request->fullUrl() != '' && $this->auth->guest()) { $aSiteMap = \Cache::get('sitemap', []); $changefreq = 'always'; if (!empty($aSiteMap[$request->fullUrl()]['added'])) { $aDateDiff = Carbon::createFromTimestamp($aSiteMap[$request->fullUrl()]['added'])->diff($time_now); if ($aDateDiff->y > 0) { $changefreq = 'yearly'; } else { if ($aDateDiff->m > 0) { $changefreq = 'monthly'; } else { if ($aDateDiff->d > 6) { $changefreq = 'weekly'; } else { if ($aDateDiff->d > 0 && $aDateDiff->d < 7) { $changefreq = 'daily'; } else { if ($aDateDiff->h > 0) { $changefreq = 'hourly'; } else { $changefreq = 'always'; } } } } } } $aSiteMap[$request->fullUrl()] = ['added' => time(), 'lastmod' => $dd, 'priority' => 1 - substr_count($request->getPathInfo(), '/') / 10, 'changefreq' => 'always']; \Cache::put('sitemap', $aSiteMap, 2880); } return $next($request); }