Files
spa-api/app/Http/Middleware/Authenticate.php

51 lines
751 B
PHP
Raw Normal View History

2014-10-06 15:25:53 -05:00
<?php namespace App\Http\Middleware;
2014-08-11 10:13:20 -05:00
2014-10-06 15:25:53 -05:00
use Closure;
2014-10-12 20:46:47 -05:00
use Illuminate\Contracts\Auth\Guard;
2014-08-11 10:13:20 -05:00
2015-01-05 13:16:21 -06:00
class Authenticate {
2014-08-11 10:13:20 -05:00
/**
2014-10-12 20:46:47 -05:00
* The Guard implementation.
*
2014-10-12 20:46:47 -05:00
* @var Guard
*/
protected $auth;
2014-09-22 20:21:58 -05:00
/**
* Create a new filter instance.
*
2014-10-12 20:46:47 -05:00
* @param Guard $auth
* @return void
*/
2014-11-05 11:18:00 -06:00
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
2014-09-22 20:21:58 -05:00
/**
2014-10-06 15:25:53 -05:00
* Handle an incoming request.
*
2014-10-06 15:46:34 -05:00
* @param \Illuminate\Http\Request $request
2014-10-06 15:25:53 -05:00
* @param \Closure $next
2014-10-06 15:46:34 -05:00
* @return mixed
*/
2014-10-06 15:25:53 -05:00
public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
2014-11-05 11:18:00 -06:00
return response('Unauthorized.', 401);
}
else
{
2014-11-05 11:18:00 -06:00
return redirect()->guest('auth/login');
}
}
2014-10-06 15:25:53 -05:00
return $next($request);
}
2014-08-11 10:13:20 -05:00
}