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;
|
2017-11-03 23:16:49 +00:00
|
|
|
use Illuminate\Auth\AuthenticationException;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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-11-03 23:16:49 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\AuthenticationException
|
2015-12-06 18:58:49 +00:00
|
|
|
*/
|
2017-10-29 17:37:25 +00:00
|
|
|
public function handle(Request $request, Closure $next)
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
2017-11-03 23:16:49 +00:00
|
|
|
if (! $request->user()) {
|
|
|
|
if ($request->ajax() || $request->expectsJson()) {
|
|
|
|
throw new AuthenticationException();
|
2015-12-06 18:58:49 +00:00
|
|
|
} else {
|
2017-11-03 23:16:49 +00:00
|
|
|
return redirect()->route('auth.login');
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|