Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/** Sesi login aktif. Tahap tampilan: mengakhiri sesi hanya menampilkan notifikasi. */
|
||||
class SesiAktifController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
// Sesi ini dibuat dari permintaan nyata; sesi lain berupa data contoh.
|
||||
$ini = [
|
||||
'id' => 'sesi-ini',
|
||||
'nama' => $user->name,
|
||||
'username' => $user->username,
|
||||
'role' => $user->role->label(),
|
||||
'perangkat' => $this->perangkat((string) $request->userAgent()),
|
||||
'ip' => (string) $request->ip(),
|
||||
'lokasi' => '-',
|
||||
'mulai' => now()->format('Y-m-d H:i'),
|
||||
'terakhir' => now()->format('Y-m-d H:i'),
|
||||
'saat_ini' => true,
|
||||
];
|
||||
|
||||
return view('superuser.sesi-aktif.index', [
|
||||
'sesi' => SuperuserData::sesiLain()->prepend($ini),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(string $id): RedirectResponse
|
||||
{
|
||||
$sesi = SuperuserData::sesiLain()->firstWhere('id', $id);
|
||||
abort_if($sesi === null, 404);
|
||||
|
||||
return redirect()->route('superuser.sesi-aktif')
|
||||
->with('info', "Sesi {$sesi['nama']} pada {$sesi['perangkat']} berhasil diakhiri. Tampilan prototipe: perubahan belum disimpan karena basis data belum dibangun.");
|
||||
}
|
||||
|
||||
public function destroyAll(): RedirectResponse
|
||||
{
|
||||
return redirect()->route('superuser.sesi-aktif')
|
||||
->with('info', 'Semua sesi lain berhasil diakhiri. Tampilan prototipe: perubahan belum disimpan karena basis data belum dibangun.');
|
||||
}
|
||||
|
||||
private function perangkat(string $agent): string
|
||||
{
|
||||
$browser = match (true) {
|
||||
str_contains($agent, 'Edg/') => 'Edge',
|
||||
str_contains($agent, 'Firefox/') => 'Firefox',
|
||||
str_contains($agent, 'Chrome/') => 'Chrome',
|
||||
str_contains($agent, 'Safari/') => 'Safari',
|
||||
default => 'Peramban',
|
||||
};
|
||||
$os = match (true) {
|
||||
str_contains($agent, 'Windows') => 'Windows',
|
||||
str_contains($agent, 'Android') => 'Android',
|
||||
str_contains($agent, 'iPhone'), str_contains($agent, 'iPad') => 'iOS',
|
||||
str_contains($agent, 'Mac OS') => 'macOS',
|
||||
str_contains($agent, 'Linux') => 'Linux',
|
||||
default => 'perangkat tidak dikenal',
|
||||
};
|
||||
|
||||
return "{$browser} di {$os}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user