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)
|
public function store(User $user)
|
||||||
{
|
{
|
||||||
Session()->put('impersonate', Auth::id());
|
Session()->put('impersonate', Auth::id());
|
||||||
|
Session()->put('impersonate_name', $user->name);
|
||||||
|
|
||||||
Auth::login($user);
|
Auth::login($user);
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ public function destroy()
|
|||||||
Auth::loginUsingId($adminId);
|
Auth::loginUsingId($adminId);
|
||||||
|
|
||||||
Session()->forget('impersonate');
|
Session()->forget('impersonate');
|
||||||
|
Session()->forget('impersonate_name');
|
||||||
|
|
||||||
return to_route('admin.dashboard');
|
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">
|
<body class="bg-[#FFFFFF] text-[#1b1b18] flex h-full w-full flex-col preload">
|
||||||
<x-ui.preloader/>
|
<x-ui.preloader/>
|
||||||
<div class="h-full w-full" style="display: none" id="content">
|
<div class="h-full w-full" style="display: none" id="content">
|
||||||
|
@if(session()->has('impersonate_name'))
|
||||||
|
<x-impersonate-alert />
|
||||||
|
@endif
|
||||||
{{$slot}}
|
{{$slot}}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -23,7 +23,9 @@
|
|||||||
@if($icon !=='')
|
@if($icon !=='')
|
||||||
@svg("heroicon-o-$icon", 'w-5 h-5')
|
@svg("heroicon-o-$icon", 'w-5 h-5')
|
||||||
@endif
|
@endif
|
||||||
|
@if(isset($slot))
|
||||||
<p>{{$slot}}</p>
|
<p>{{$slot}}</p>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
|
|||||||
@ -17,7 +17,9 @@
|
|||||||
->middleware('auth')
|
->middleware('auth')
|
||||||
->name('logout');
|
->name('logout');
|
||||||
|
|
||||||
Route::middleware([HasRole::class.':'.UserTypes::Admin->value, 'auth'])->group(function () {
|
Route::middleware('auth')->group(function () {
|
||||||
Route::get('/impersonate/{user}', [ImpersonatedUserController::class, 'store'])->name('impersonate');
|
Route::get('/impersonate/{user}', [ImpersonatedUserController::class, 'store'])
|
||||||
Route::delete('/impersonate', [ImpersonatedUserController::class, 'destroy'])->name('impersonate.destroy');
|
->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