2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The Guard implementation.
|
|
|
|
*
|
|
|
|
* @var Guard
|
|
|
|
*/
|
|
|
|
protected $auth;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new filter instance.
|
|
|
|
*
|
2015-12-14 13:22:39 +00:00
|
|
|
* @param Guard $auth
|
2015-12-13 04:42:28 +00:00
|
|
|
*/
|
|
|
|
public function __construct(Guard $auth)
|
|
|
|
{
|
|
|
|
$this->auth = $auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2015-12-14 13:22:39 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
2015-12-13 04:42:28 +00:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
if ($this->auth->guest()) {
|
2016-08-03 10:42:11 +00:00
|
|
|
if ($request->ajax() || $request->route()->getName() === 'play') {
|
2015-12-13 04:42:28 +00:00
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
|
|
|
return redirect()->guest('login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|