diff --git a/composer.json b/composer.json index 927b6f5..1399db7 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "description": "A simple package that adds the impersonate operation for admins", "type": "library", "require": { - "php": "^8.0", - "laravel/framework": "^8.0.0|^9.0.0|^10.0.0|^11.0.0", + "php": "^7.3|^8.0", + "laravel/framework": "^8.0.0|^9.0.0|^10.0.0", "backpack/crud": "^5.0|^6.0" }, "keywords": [ diff --git a/src/app/Http/Controllers/Operations/ImpersonateUserOperation.php b/src/app/Http/Controllers/Operations/ImpersonateUserOperation.php index 4612b85..c716c7b 100644 --- a/src/app/Http/Controllers/Operations/ImpersonateUserOperation.php +++ b/src/app/Http/Controllers/Operations/ImpersonateUserOperation.php @@ -78,6 +78,8 @@ public function impersonateUser(int $id): RedirectResponse } // Login + Auth::guard(config('impersonate_user.base_guard'))->logout(); + Session::flush(); Auth::guard(config('impersonate_user.base_guard'))->loginUsingId($id, false); // Remember impersonator session @@ -102,13 +104,12 @@ public function exitImpersonatedUser(): RedirectResponse } // Login impersonator back - Auth::guard(config('impersonate_user.base_guard'))->loginUsingId(intval(Session::get(config('impersonate_user.session_key')))); - - // Remove impersonator session - Session::forget(config('impersonate_user.session_key')); + Auth::guard(config('impersonate_user.base_guard'))->logout(); + $idOriginalUser = intval(Session::get(config('impersonate_user.session_key'))); $redirect = Session::get(config('impersonate_user.session_key') . '_last_url'); - Session::forget(config('impersonate_user.session_key') . '_last_url'); - Session::forget(config('impersonate_user.session_key') . '_exit_route'); + + Session::flush(); + Auth::guard(config('impersonate_user.base_guard'))->loginUsingId($idOriginalUser); // Feedback Alert::add('success', __('impersonate_user::messages.back_after_impersonating', ['username' => backpack_user()->name]))->flash(); diff --git a/src/resources/views/exit_impersonated.blade.php b/src/resources/views/exit_impersonated.blade.php index b5d5818..458b2bc 100644 --- a/src/resources/views/exit_impersonated.blade.php +++ b/src/resources/views/exit_impersonated.blade.php @@ -1,8 +1,8 @@ @if(Session::has(config('impersonate_user.session_key')) && Session::has(config('impersonate_user.session_key') . '_exit_route')) -
-@endif \ No newline at end of file +@endif diff --git a/src/resources/views/impersonate.blade.php b/src/resources/views/impersonate.blade.php index 6f99e73..be77500 100644 --- a/src/resources/views/impersonate.blade.php +++ b/src/resources/views/impersonate.blade.php @@ -1,11 +1,15 @@ @if(!Session::has(config('impersonate_user.session_key')) && backpack_user()->canImpersonateOthers() && $entry->canBeImpersonated()) @elseif(Session::has(config('impersonate_user.session_key')) && backpack_user()->id === $entry->getKey()) -@endif \ No newline at end of file +@endif