2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2017-10-29 17:37:25 +00:00
|
|
|
use Illuminate\Http\Request;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The Guard implementation.
|
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @var \Illuminate\Contracts\Auth\Guard
|
2015-12-06 18:58:49 +00:00
|
|
|
*/
|
|
|
|
protected $auth;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new filter instance.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Contracts\Auth\Guard $auth
|
2015-12-06 18:58:49 +00:00
|
|
|
*/
|
|
|
|
public function __construct(Guard $auth)
|
|
|
|
{
|
|
|
|
$this->auth = $auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
2015-12-06 18:58:49 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2017-10-29 17:37:25 +00:00
|
|
|
public function handle(Request $request, Closure $next)
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
|
|
|
if ($this->auth->guest()) {
|
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
|
|
|
return redirect()->guest('auth/login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|