Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Aug 31, 2024
1 parent d0daef2 commit 5b56160
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
15 changes: 15 additions & 0 deletions resources/views/_partials/admin_impersonate_banner.blade.php
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
10 changes: 5 additions & 5 deletions resources/views/_partials/impersonate_banner.blade.php
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
14 changes: 9 additions & 5 deletions src/Actions/LogoutUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ public function handle()
{
$user = Auth::getUser();

Auth::logout();
if (Auth::isImpersonator()) {

Check failure on line 14 in src/Actions/LogoutUser.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::isImpersonator().

Check failure on line 14 in src/Actions/LogoutUser.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::isImpersonator().
Auth::stopImpersonate();

Check failure on line 15 in src/Actions/LogoutUser.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::stopImpersonate().

Check failure on line 15 in src/Actions/LogoutUser.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::stopImpersonate().
} else {
Auth::logout();

session()->invalidate();
session()->invalidate();

session()->regenerateToken();
session()->regenerateToken();

if ($user) {
Event::fire('igniter.user.logout', [$user]);
if ($user) {
Event::fire('igniter.user.logout', [$user]);
}
}

flash()->success(lang('igniter.user::default.alert_logout_success'));
Expand Down
3 changes: 2 additions & 1 deletion src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function register()

Route::pushMiddlewareToGroup('igniter:admin', \Igniter\User\Http\Middleware\Authenticate::class);
Route::pushMiddlewareToGroup('igniter:admin', \Igniter\User\Http\Middleware\LogUserLastSeen::class);
Route::pushMiddlewareToGroup('igniter', \Igniter\User\Http\Middleware\InjectImpersonateBanner::class);
}

public function boot()
Expand All @@ -95,7 +96,7 @@ public function boot()
});

Template::registerHook('endBody', function() {
return view('igniter.user::_partials.impersonate_banner');
return view('igniter.user::_partials.admin_impersonate_banner');
});

Event::listen(NotificationSent::class, function(NotificationSent $event) {
Expand Down
40 changes: 40 additions & 0 deletions src/Http/Middleware/InjectImpersonateBanner.php
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

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::check().

Check failure on line 19 in src/Http/Middleware/InjectImpersonateBanner.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::isImpersonator().

Check failure on line 19 in src/Http/Middleware/InjectImpersonateBanner.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::check().

Check failure on line 19 in src/Http/Middleware/InjectImpersonateBanner.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Facades\Auth::isImpersonator().
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);
}
}

0 comments on commit 5b56160

Please sign in to comment.