firefly-iii/app/Http/Middleware/IsDemoUser.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2017-03-24 05:07:38 -05:00
<?php
/**
2017-12-19 12:25:50 -06:00
* IsDemoUser.php
2017-03-24 05:07:38 -05:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05:00
* 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
2017-12-17 07:44:05 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2017-03-24 05:07:38 -05:00
*/
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Session;
/**
2017-12-19 12:25:50 -06:00
* Class IsDemoUser.
2017-03-24 05:07:38 -05:00
*/
2017-12-19 12:25:50 -06:00
class IsDemoUser
2017-03-24 05:07:38 -05:00
{
/**
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
*
2017-11-15 05:25:49 -06:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
2017-03-24 05:07:38 -05:00
*
* @return mixed
*/
public function handle(Request $request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
2017-12-22 11:32:43 -06:00
// don't care when not logged in, usual stuff applies:
return $next($request);
}
2017-03-24 05:07:38 -05:00
/** @var User $user */
$user = auth()->user();
if ($user->hasRole('demo')) {
Session::flash('warning', strval(trans('firefly.not_available_demo_user')));
return redirect(route('index'));
}
return $next($request);
}
}