jeremykenedy /
laravel-material-design
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace App\Http\Middleware; |
||||||
| 4 | |||||||
| 5 | use Auth; |
||||||
| 6 | use Closure; |
||||||
| 7 | use Illuminate\Contracts\Auth\Guard; |
||||||
| 8 | use Illuminate\Http\Request; |
||||||
| 9 | use Illuminate\Support\Facades\Log; |
||||||
| 10 | use Illuminate\Support\Facades\Route; |
||||||
| 11 | |||||||
| 12 | class Authenticate |
||||||
| 13 | { |
||||||
| 14 | /** |
||||||
| 15 | * The Guard implementation. |
||||||
| 16 | * |
||||||
| 17 | * @var Guard |
||||||
| 18 | */ |
||||||
| 19 | protected $auth; |
||||||
| 20 | |||||||
| 21 | /** |
||||||
| 22 | * Create a new filter instance. |
||||||
| 23 | * |
||||||
| 24 | * @param Guard $auth |
||||||
| 25 | * |
||||||
| 26 | * @return void |
||||||
| 27 | */ |
||||||
| 28 | public function __construct(Guard $auth) |
||||||
| 29 | { |
||||||
| 30 | $this->auth = $auth; |
||||||
| 31 | } |
||||||
| 32 | |||||||
| 33 | /** |
||||||
| 34 | * Handle an incoming request. |
||||||
| 35 | * |
||||||
| 36 | * @param \Illuminate\Http\Request $request |
||||||
| 37 | * @param \Closure $next |
||||||
| 38 | * @param $role |
||||||
| 39 | * |
||||||
| 40 | * @return mixed |
||||||
| 41 | */ |
||||||
| 42 | public function handle($request, Closure $next, $role) |
||||||
|
0 ignored issues
–
show
|
|||||||
| 43 | { |
||||||
| 44 | if (!$this->auth->check()) { |
||||||
| 45 | return redirect()->to('/login') |
||||||
| 46 | ->with('status', 'success') |
||||||
| 47 | ->with('message', 'Please login.'); |
||||||
| 48 | } |
||||||
| 49 | //////////////// |
||||||
| 50 | // if($role == 'all') |
||||||
| 51 | // { |
||||||
| 52 | // return $next($request); |
||||||
| 53 | // } |
||||||
| 54 | |||||||
| 55 | // if( $this->auth->guest() || !$this->auth->user()->hasRole($role)) |
||||||
| 56 | // { |
||||||
| 57 | // abort(403); |
||||||
| 58 | // } |
||||||
| 59 | //////////////// |
||||||
| 60 | return $next($request); |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | public function terminate($request, $response) |
||||||
|
0 ignored issues
–
show
The parameter
$response is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 64 | { |
||||||
| 65 | $user = Auth::user(); |
||||||
| 66 | $currentRoute = Route::currentRouteName(); |
||||||
| 67 | Log::info('Authenticate middlware was used: '.$currentRoute.'. ', [$user]); |
||||||
| 68 | } |
||||||
| 69 | } |
||||||
| 70 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.