/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { /** * check for ban by ip */ $remote_ip = $request->ip(); $cache_key = '_ban_ip_' . $remote_ip; $ban_info = Cache::rememberForever($cache_key, function () use($remote_ip) { return AdBanIp::where('ban_ip', $remote_ip)->first(); }); if (!empty($ban_info) && !$request->is('ban')) { return redirect('ban'); } /** * check if user is banned my email */ if (Auth()->check()) { $user_mail = Auth()->user()->email; $cache_key = '_ban_email_' . $user_mail; $ban_info = Cache::rememberForever($cache_key, function () use($user_mail) { return AdBanEmail::where('ban_email', $user_mail)->first(); }); if (!empty($ban_info) && !$request->is('ban')) { return redirect('ban'); } } return $next($request); }
public function index(Request $request) { //message to show the user $message = trans('ban.You are banned.'); /** * check for ban by ip */ $remote_ip = $request->ip(); $cache_key = '_ban_ip_' . $remote_ip; $ban_info = Cache::rememberForever($cache_key, function () use($remote_ip) { return AdBanIp::where('ban_ip', $remote_ip)->first(); }); /** * check if user is banned my email */ if (Auth()->check()) { $user_mail = Auth()->user()->email; $cache_key = '_ban_email_' . $user_mail; $ban_info = Cache::rememberForever($cache_key, function () use($user_mail) { return AdBanEmail::where('ban_email', $user_mail)->first(); }); } //show ban reason if (!empty($ban_info)) { $message = $ban_info->ban_reason; } return view('errors.ban', ['message' => $message]); }
public function delete(Request $request) { //locations to be deleted $data = []; //check for single delete if (isset($request->id)) { $data[] = $request->id; } //check for mass delete if no single delete if (empty($data)) { $data = $request->input('ban_ip_id'); } //delete if (!empty($data)) { AdBanIp::destroy($data); //clear cache, set message, redirect to list Cache::flush(); session()->flash('message', trans('admin_common.Banned IP deleted')); return redirect(url('admin/ipban')); } //nothing for deletion set message and redirect session()->flash('message', trans('admin_common.Nothing for deletion')); return redirect(url('admin/ipban')); }