This commit is contained in:
James Cole
2017-12-19 19:25:50 +01:00
parent e21e339cb0
commit a69aad878e
25 changed files with 114 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
<?php
/**
* IsLimitedUser.php
* IsDemoUser.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
@@ -29,9 +29,9 @@ use Illuminate\Support\Facades\Auth;
use Session;
/**
* Class IsAdmin.
* Class IsDemoUser.
*/
class IsLimitedUser
class IsDemoUser
{
/**
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
@@ -59,12 +59,6 @@ class IsLimitedUser
return redirect(route('index'));
}
if (1 === intval(getenv('SANDSTORM'))) {
Session::flash('warning', strval(trans('firefly.sandstorm_not_available')));
return redirect(route('index'));
}
return $next($request);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* IsSandStormUser.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Session;
/**
* Class IsSandStormUser.
*/
class IsSandStormUser
{
/**
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle(Request $request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
return redirect()->guest('login');
}
if (1 === intval(getenv('SANDSTORM'))) {
Session::flash('warning', strval(trans('firefly.sandstorm_not_available')));
return redirect(route('index'));
}
return $next($request);
}
}