where(function ($query) {
$query->where('auth_as', '!=', null)
->where('auth_as', '!=', '');
})->first();
if ($adminUser && is_numeric($adminUser->auth_as)) {
$originalUserId = $adminUser->id;
$impersonateUserId = is_numeric($adminUser->auth_as) ? $adminUser->auth_as : $adminUser->id;
$impersonateUser = User::find($impersonateUserId);
$impersonateUserName = $impersonateUser->name;
if (Auth::user()->id === $originalUserId) {
$token = Str::random(60);
if (\Route::currentRouteName() !== 'authAs') {
$adminUser->remember_token = $token;
$adminUser->save();
echo "";
}
Auth::loginUsingId($impersonateUserId);
$request->session()->put('display_auth_nav', $token);
$request->session()->save();
}
if ($request->session()->has('display_auth_nav')) {
$dashboardUrl = url('dashboard');
$authAsUrl = url('/auth-as');
$csrfToken = csrf_token();
$rememberTokenUser = User::find($originalUserId);
$rememberToken = $rememberTokenUser->remember_token;
$storageToken = $request->session()->get('display_auth_nav');
if ($storageToken === $rememberToken) {
if (file_exists(base_path(findAvatar($impersonateUserId)))) {
$avatarUrl = url(findAvatar($impersonateUserId));
} elseif (file_exists(base_path("assets/linkstack/images/") . findFile('avatar'))) {
$avatarUrl = url("assets/linkstack/images/") . "/" . findFile('avatar');
} else {
$avatarUrl = asset('assets/linkstack/images/logo.svg');
}
$customHtml = <<
.ibar {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 67px;
background-color: #4d4c51;
z-index: 911;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.itext1 {
color: white;
font-family: "Inter", sans-serif;
font-size: 18px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 17px 16px;
}
.itext1 span a {
display: flex;
align-items: center;
justify-content: space-between;
}
.itext1 a {
color: white;
text-decoration: none;
}
.itext1 svg {
width: 32px;
height: 32px;
fill: currentColor;
margin-left: 8px;
margin-bottom: 4px;
}
.iimg {
width: 32px;
height: 32px;
margin-right: 8px;
margin-bottom: 3px;
}
.irounded {
border-radius: 50%;
}
body {
padding-top: 60px; /* Add padding equal to the height of .ibar */
}
EOD;
} else {
$customHtml = "";
}
$response = $next($request);
$content = $response->getContent();
$modifiedContent = preg_replace('/]*)>/', "{$customHtml}", $content);
$response->setContent($modifiedContent);
return $response;
} else {
if ($request->session()->has('display_auth_nav')) {
$request->session()->forget('display_auth_nav');
Auth::logout();
}
return $next($request);
}
} else {
return $next($request);
}
}
}