vpn.keks.cloud/app/Http/Middleware/GUIMiddleware.php

48 lines
1 KiB
PHP
Raw Normal View History

2020-11-08 02:07:10 +00:00
<?php
namespace App\Http\Middleware;
use App\Models\VPN;
use Closure;
use Illuminate\Support\Facades\Auth;
use \Illuminate\Support\Facades\View;
class GUIMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//Get Curretn user
$user = Auth::user();
View::share("user", $user);
//Get ALL VPNS
$vpn = VPN::findForUser($user->id);
View::share("vpn", $vpn);
//Get Selectet VPN
$currentVPNId = session()->get("current_vpn");
if($currentVPNId === null && count($vpn)==1) {
session()->put("current_vpn", $vpn[0]->id);
$currentVPNId = $vpn[0]->id;
}
$currentVPN = VPN::query()->where("id", "=", $currentVPNId)->first();
if($currentVPN != null) {
View::share("currentVPNName", $currentVPN->name);
}
return $next($request);
}
}