Created
August 19, 2015 06:14
-
-
Save pengan1987/71780d33f497faf91c10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Enter file contents here<?php namespace SleepingOwl\Admin\Http\Middleware; | |
| use AdminAuth; | |
| use Closure; | |
| class AdminAuthenticate | |
| { | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next) | |
| { | |
| if (AdminAuth::guest()) { | |
| if ($request->ajax()) { | |
| return response('Unauthorized.', 401); | |
| } else { | |
| return redirect()->guest(route('admin.login')); | |
| } | |
| } | |
| //in this example, I assume that in the table administrators is a flag "isAdmin", | |
| //but you can change it to whatever you can | |
| if (AdminAuth::user()->role < 10000) { | |
| //here i check the current request path against the config definitions | |
| $path = $request->path(); | |
| if ($path == "admin/users") { | |
| return redirect()->intended(route('admin.wildcard', '/')); | |
| } | |
| } | |
| return $next($request); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment