-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sam Poyigi <[email protected]>
- Loading branch information
Showing
5 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
resources/views/_partials/admin_impersonate_banner.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@if(AdminAuth::isImpersonator()) | ||
<div | ||
id="impersonate-banner" | ||
class="bg-dark position-fixed w-100 bottom-0 z-3 d-flex text-white justify-content-center align-items-center py-2" | ||
> | ||
<div class="fs-5"> | ||
@lang('igniter.user::default.text_impersonating_user'): <strong>{{AdminAuth::getStaffName()}}</strong> | ||
</div> | ||
|
||
<a | ||
class="btn btn-light ms-3" | ||
href="{{admin_url('logout')}}" | ||
>@lang('igniter.user::default.text_leave')</a> | ||
</div> | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
@if(AdminAuth::isImpersonator()) | ||
@if(app('main.auth')->isImpersonator()) | ||
<div | ||
id="impersonate-banner" | ||
class="bg-dark position-fixed w-100 bottom-0 z-3 d-flex text-white justify-content-center align-items-center py-2" | ||
> | ||
<div class="fs-5"> | ||
@lang('igniter.user::default.text_impersonating_user'): <strong>{{AdminAuth::getStaffName()}}</strong> | ||
<div class="fs-6"> | ||
@lang('igniter.user::default.text_impersonating_user'): <strong>{{app('main.auth')->getFullName()}}</strong> | ||
</div> | ||
|
||
<a | ||
class="btn btn-light ms-3" | ||
href="{{admin_url('logout')}}" | ||
href="{{page_url('logout')}}" | ||
>@lang('igniter.user::default.text_leave')</a> | ||
</div> | ||
@endif | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Igniter\User\Http\Middleware; | ||
|
||
use Igniter\Flame\Igniter; | ||
use Igniter\User\Facades\Auth; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class InjectImpersonateBanner | ||
{ | ||
public function handle($request, \Closure $next): Response | ||
{ | ||
$response = $next($request); | ||
|
||
if (Igniter::runningInAdmin()) { | ||
return $response; | ||
} | ||
|
||
if (!Auth::check() || !Auth::isImpersonator()) | ||
Check failure on line 19 in src/Http/Middleware/InjectImpersonateBanner.php
|
||
return $response; | ||
|
||
$this->injectBanner($response); | ||
|
||
return $response; | ||
} | ||
|
||
protected function injectBanner(Response $response): void | ||
{ | ||
$content = $response->getContent(); | ||
$banner = view('igniter.user::_partials.impersonate_banner')->render(); | ||
$pos = strripos($content, '</body>'); | ||
if (false !== $pos) { | ||
$content = substr($content, 0, $pos).$banner.substr($content, $pos); | ||
} else { | ||
$content .= $banner; | ||
} | ||
|
||
$response->setContent($content); | ||
} | ||
} |