Cachet/app/Http/Middleware/Authenticate.php

57 lines
1.1 KiB
PHP
Raw Normal View History

2015-03-20 18:30:45 -06:00
<?php
/*
* This file is part of Cachet.
*
2015-05-25 17:59:08 +01:00
* (c) Cachet HQ <support@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2015-03-20 18:30:45 -06:00
namespace CachetHQ\Cachet\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate
{
/**
* The Guard implementation.
*
2015-05-20 17:01:26 -05:00
* @var \Illuminate\Contracts\Auth\Guard
2015-03-20 18:30:45 -06:00
*/
protected $auth;
/**
* Create a new filter instance.
*
2015-05-20 17:01:26 -05:00
* @param \Illuminate\Contracts\Auth\Guard $auth
2015-03-20 18:30:45 -06:00
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
return $next($request);
}
}