feat: Logout jarak jauh wali — cabut semua token Sanctum dari panel admin, app langsung 401 → login ulang
This commit is contained in:
@@ -47,6 +47,20 @@ class WaliMuridController extends Controller
|
||||
return view('parents.index', compact('users', 'total', 'totalAktif', 'pending', 'baruMingguIni'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout jarak jauh: cabut semua token Sanctum akun wali
|
||||
* → app di semua perangkat langsung 401 → otomatis kembali ke login.
|
||||
*/
|
||||
public function forceLogout(int $userId): RedirectResponse
|
||||
{
|
||||
$user = User::where('role', 'parent')->findOrFail($userId);
|
||||
|
||||
$user->tokens()->delete();
|
||||
$user->forceFill(['active_session_token' => null])->save();
|
||||
|
||||
return back()->with('success', 'Semua perangkat akun "' . $user->name . '" telah di-logout dari jarak jauh.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus akun wali murid beserta tautan anak & perangkatnya.
|
||||
* Hanya akun role=parent yang boleh dihapus lewat sini.
|
||||
|
||||
@@ -255,6 +255,11 @@
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<button onclick="forceLogoutWali({{ $user->id }}, '{{ addslashes($user->name) }}')"
|
||||
class="inline-flex items-center gap-2 px-3.5 py-2 rounded-xl bg-white border border-slate-200 text-slate-600 text-xs font-bold shadow-sm hover:shadow-md hover:-translate-y-0.5 hover:border-red-200 hover:text-red-600 transition-all"
|
||||
title="Logout akun di semua perangkat">
|
||||
<i class="fa-solid fa-right-from-bracket"></i> Logout
|
||||
</button>
|
||||
<button onclick="resetWaliPassword({{ $user->id }}, '{{ addslashes($user->name) }}')"
|
||||
class="inline-flex items-center gap-2 px-3.5 py-2 rounded-xl bg-gradient-to-r from-amber-400 to-orange-500 text-white text-xs font-bold shadow-md shadow-amber-500/30 hover:shadow-lg hover:-translate-y-0.5 hover:brightness-105 transition-all"
|
||||
title="Set password baru">
|
||||
@@ -281,6 +286,31 @@
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
function forceLogoutWali(userId, userName) {
|
||||
Swal.fire({
|
||||
title: 'Logout jarak jauh?',
|
||||
html: 'Semua perangkat akun <b>' + userName + '</b> akan di-logout paksa.<br>Wali harus login ulang dengan password.',
|
||||
icon: 'question',
|
||||
confirmButtonText: '<i class="fa-solid fa-right-from-bracket"></i> Ya, Logout',
|
||||
showCancelButton: true,
|
||||
cancelButtonText: 'Batal',
|
||||
confirmButtonColor: '#6366f1',
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
fetch('{{ url('parents') }}/' + userId + '/force-logout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
}).then(r => {
|
||||
if (r.redirected) window.location.href = r.url;
|
||||
else location.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteWali(userId, userName) {
|
||||
Swal.fire({
|
||||
title: 'Hapus akun ' + userName + '?',
|
||||
|
||||
@@ -143,6 +143,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::middleware('permission:parents-verify')->group(function () {
|
||||
Route::get('/parents', [\App\Http\Controllers\Admin\WaliMuridController::class, 'index'])->name('parents.index');
|
||||
Route::delete('/parents/{user}', [\App\Http\Controllers\Admin\WaliMuridController::class, 'destroy'])->name('parents.destroy');
|
||||
Route::post('/parents/{user}/force-logout', [\App\Http\Controllers\Admin\WaliMuridController::class, 'forceLogout'])->name('parents.force-logout');
|
||||
Route::get('/parents/verification', [\App\Http\Controllers\Admin\ParentVerificationController::class, 'index'])->name('parents.verification');
|
||||
Route::post('/parents/verification/{link}/approve', [\App\Http\Controllers\Admin\ParentVerificationController::class, 'approve'])->name('parents.verification.approve');
|
||||
Route::post('/parents/verification/{link}/reject', [\App\Http\Controllers\Admin\ParentVerificationController::class, 'reject'])->name('parents.verification.reject');
|
||||
|
||||
Reference in New Issue
Block a user