2015-02-05 21:52:16 -06:00
|
|
|
<?php namespace FireflyIII\Http\Middleware;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-05-14 03:03:57 -05:00
|
|
|
use App;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Closure;
|
2015-05-16 02:41:14 -05:00
|
|
|
use Config;
|
2015-05-14 03:03:57 -05:00
|
|
|
use FireflyIII\Models\Preference;
|
2015-02-05 21:39:52 -06:00
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
2015-03-29 00:43:20 -05:00
|
|
|
use Illuminate\Http\Request;
|
2015-05-14 03:03:57 -05:00
|
|
|
use Preferences;
|
2015-05-16 02:41:14 -05:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Class Authenticate
|
|
|
|
*
|
2015-05-10 01:26:42 -05:00
|
|
|
* @codeCoverageIgnore
|
2015-02-11 00:35:10 -06:00
|
|
|
* @package FireflyIII\Http\Middleware
|
|
|
|
*/
|
|
|
|
class Authenticate
|
|
|
|
{
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* The Guard implementation.
|
|
|
|
*
|
|
|
|
* @var Guard
|
|
|
|
*/
|
|
|
|
protected $auth;
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Create a new filter instance.
|
|
|
|
*
|
|
|
|
* @param Guard $auth
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct(Guard $auth)
|
|
|
|
{
|
|
|
|
$this->auth = $auth;
|
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-03-29 00:43:20 -05:00
|
|
|
public function handle(Request $request, Closure $next)
|
2015-02-11 00:35:10 -06:00
|
|
|
{
|
|
|
|
if ($this->auth->guest()) {
|
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
|
|
|
return redirect()->guest('auth/login');
|
|
|
|
}
|
|
|
|
}
|
2015-05-14 03:03:57 -05:00
|
|
|
// if logged in, set user language:
|
|
|
|
$pref = Preferences::get('language', 'en');
|
|
|
|
App::setLocale($pref->data);
|
|
|
|
|
2015-05-16 02:41:14 -05:00
|
|
|
setlocale(LC_TIME, Config::get('firefly.locales.' . $pref->data));
|
2015-02-05 21:39:52 -06:00
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
return $next($request);
|
|
|
|
}
|
2015-02-05 21:39:52 -06:00
|
|
|
|
|
|
|
}
|