Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
maurohmartinez committed Aug 14, 2024
2 parents a25254f + 3e5250e commit b14df12
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
13 changes: 7 additions & 6 deletions src/app/Http/Controllers/Operations/ImpersonateUserOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/resources/views/exit_impersonated.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@if(Session::has(config('impersonate_user.session_key')) && Session::has(config('impersonate_user.session_key') . '_exit_route'))
<form method="post" action="{{ Session::get(config('impersonate_user.session_key') . '_exit_route') }}">
<form method="post" action="{{ url(Session::get(config('impersonate_user.session_key') . '_exit_route')) }}">
@csrf
<button type="submit" class="{{ $class ?? 'btn btn-warning' }}">
<button type="submit" class="{{ $class ?? 'btn btn-warning me-2' }}">
<i class="la la-arrow-left"></i> {{ $label ?? 'Back to my user' }}
</button>
</form>
@endif
@endif
10 changes: 7 additions & 3 deletions src/resources/views/impersonate.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@if(!Session::has(config('impersonate_user.session_key')) && backpack_user()->canImpersonateOthers() && $entry->canBeImpersonated())
<form class="d-inline-block" method="post" action="{{ url($crud->route . '/impersonate-user/' . $entry->getKey()) }}">
@csrf
<button type="submit" class="btn btn-link"><i class="la la-unlock"></i> {{ __('impersonate_user::messages.btn_impersonate') }}</button>
<button type="submit" class="btn btn-sm btn-link">
<i class="la la-unlock me-1"></i> {{ __('impersonate_user::messages.btn_impersonate') }}
</button>
</form>
@elseif(Session::has(config('impersonate_user.session_key')) && backpack_user()->id === $entry->getKey())
<form class="d-inline-block" method="post" action="{{ url($crud->route . '/exit-impersonated-user') }}">
@csrf
<button type="submit" class="btn btn-link"><i class="la la-lock {{ config('impersonate_user.btn_exit_custom_class') }}"></i> {{ __('impersonate_user::messages.btn_exit_impersonated') }}</button>
<button type="submit" class="btn btn-sm btn-link">
<i class="la la-lock {{ config('impersonate_user.btn_exit_custom_class') }}"></i> {{ __('impersonate_user::messages.btn_exit_impersonated') }}
</button>
</form>
@endif
@endif

0 comments on commit b14df12

Please sign in to comment.