Rename GuestUser to ApplicationSession as middleware to hold any site wide variables

This commit is contained in:
Deon George 2023-03-02 12:15:08 +11:00
parent e0fb057c84
commit 35596ec867
5 changed files with 36 additions and 35 deletions

View File

@ -22,7 +22,7 @@ class APIController extends Controller
$dn = Crypt::decryptString($request->query('key'));
Log::debug(sprintf('%s: Query [%s] - Levels [%d]',__METHOD__,$dn,$levels));
return (new Server())
return (config('server'))
->children($dn)
->transform(function($item) {
return [

View File

@ -54,7 +54,7 @@ class HomeController extends Controller
public function info()
{
// Load our attributes
$s = new Server;
$s = config('server');
$s->schema('objectclasses');
$s->schema('attributetypes');
@ -73,7 +73,7 @@ class HomeController extends Controller
$dn = Crypt::decryptString($request->post('key'));
return view('frames.dn')
->with('o',(new Server)->fetch($dn))
->with('o',config('server')->fetch($dn))
->with('dn',$dn);
}
@ -87,7 +87,7 @@ class HomeController extends Controller
*/
public function schema_frame(Request $request)
{
$s = new Server;
$s = config('server');
// If an invalid key, we'll 404
if ($request->type && $request->key && ($s->schema($request->type)->has($request->key) === FALSE))

View File

@ -4,9 +4,7 @@ namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use App\Http\Middleware\GuestUser;
use App\Http\Middleware\SwapinAuthUser;
use App\Http\Middleware\CheckUpdate;
use App\Http\Middleware\{ApplicationSession,CheckUpdate,SwapinAuthUser};
class Kernel extends HttpKernel
{
@ -43,7 +41,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
GuestUser::class,
ApplicationSession::class,
CheckUpdate::class,
],
@ -51,6 +49,7 @@ class Kernel extends HttpKernel
'throttle:60,1',
\App\Http\Middleware\EncryptCookies::class,
SwapinAuthUser::class,
ApplicationSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

View File

@ -0,0 +1,29 @@
<?php
namespace App\Http\Middleware;
use App\Classes\LDAP\Server;
use App\Ldap\User;
use Closure;
/**
* This sets up our application session with any required values, ultimately for cache optimisation reasons
*/
class ApplicationSession
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request,Closure $next)
{
view()->share('user', auth()->user() ?: new User);
\Config::set('server',new Server);
return $next($request);
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace App\Http\Middleware;
use App\Ldap\User;
use Closure;
/**
* Class GuestUser
* @package Leenooks\Laravel\Http\Middleware
*/
class GuestUser
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request,Closure $next)
{
view()->share('user', auth()->user() ?: new User);
return $next($request);
}
}