feature(admin-panel): admin can stop impersonating
- add a alert which shows which user admin is impersonating - add a logout icon, which stops impersonating and restore admin dashboard
This commit is contained in:
parent
c1ff760282
commit
aa3056e1d1
@ -11,6 +11,7 @@ class ImpersonatedUserController extends Controller
|
||||
public function store(User $user)
|
||||
{
|
||||
Session()->put('impersonate', Auth::id());
|
||||
Session()->put('impersonate_name', $user->name);
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
@ -24,6 +25,7 @@ public function destroy()
|
||||
Auth::loginUsingId($adminId);
|
||||
|
||||
Session()->forget('impersonate');
|
||||
Session()->forget('impersonate_name');
|
||||
|
||||
return to_route('admin.dashboard');
|
||||
}
|
||||
|
||||
8
resources/views/components/impersonate-alert.blade.php
Normal file
8
resources/views/components/impersonate-alert.blade.php
Normal file
@ -0,0 +1,8 @@
|
||||
<div class="fixed z-10 top-5 left-10 shadow-xl rounded-xl">
|
||||
<x-ui.alert variant="error">
|
||||
<div class="flex items-center">
|
||||
You are impersonating as {{session()->get('impersonate_name', 'a User')}}
|
||||
<x-ui.button :link="route('impersonate.destroy')" class="mr-0 pr-0" icon="arrow-right-end-on-rectangle" title="Stop Impersonating"/>
|
||||
</div>
|
||||
</x-ui.alert>
|
||||
</div>
|
||||
@ -26,6 +26,9 @@
|
||||
<body class="bg-[#FFFFFF] text-[#1b1b18] flex h-full w-full flex-col preload">
|
||||
<x-ui.preloader/>
|
||||
<div class="h-full w-full" style="display: none" id="content">
|
||||
@if(session()->has('impersonate_name'))
|
||||
<x-impersonate-alert />
|
||||
@endif
|
||||
{{$slot}}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@ -23,7 +23,9 @@
|
||||
@if($icon !=='')
|
||||
@svg("heroicon-o-$icon", 'w-5 h-5')
|
||||
@endif
|
||||
<p>{{$slot}}</p>
|
||||
@if(isset($slot))
|
||||
<p>{{$slot}}</p>
|
||||
@endif
|
||||
</div>
|
||||
</a>
|
||||
@else
|
||||
|
||||
@ -17,7 +17,9 @@
|
||||
->middleware('auth')
|
||||
->name('logout');
|
||||
|
||||
Route::middleware([HasRole::class.':'.UserTypes::Admin->value, 'auth'])->group(function () {
|
||||
Route::get('/impersonate/{user}', [ImpersonatedUserController::class, 'store'])->name('impersonate');
|
||||
Route::delete('/impersonate', [ImpersonatedUserController::class, 'destroy'])->name('impersonate.destroy');
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/impersonate/{user}', [ImpersonatedUserController::class, 'store'])
|
||||
->middleware(HasRole::class.':'.UserTypes::Admin->value)
|
||||
->name('impersonate');
|
||||
Route::get('/impersonate', [ImpersonatedUserController::class, 'destroy'])->name('impersonate.destroy');
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user