Initial commit - lms-v2 + CLAUDE.md
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Logout
|
||||
{
|
||||
/**
|
||||
* Log the current user out of the application.
|
||||
*/
|
||||
public function __invoke(): void
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
Session::invalidate();
|
||||
Session::regenerateToken();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class LoginForm extends Form
|
||||
{
|
||||
#[Validate('required|string|email')]
|
||||
public string $email = '';
|
||||
|
||||
#[Validate('required|string')]
|
||||
public string $password = '';
|
||||
|
||||
#[Validate('boolean')]
|
||||
public bool $remember = false;
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
// 1. Jalankan proses pencocokan email & password
|
||||
if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'form.email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Ambil data user yang berhasil login
|
||||
$user = Auth::user();
|
||||
|
||||
// 3. VALIDASI RBAC: Pastikan user memiliki minimal satu role aktif di database
|
||||
// Ini mencegah user tanpa role (data menggantung) bisa masuk ke sistem
|
||||
if ($user->roles()->count() === 0) {
|
||||
// Jika tidak punya role, paksa logout demi keamanan
|
||||
Auth::logout();
|
||||
request()->session()->invalidate();
|
||||
request()->session()->regenerateToken();
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'form.email' => 'Akun Anda aktif, namun belum dikonfigurasi memiliki Role (Akses) oleh Admin. Silakan hubungi IT/HRD.',
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the authentication request is not rate limited.
|
||||
*/
|
||||
protected function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout(request()));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'form.email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication rate limiting throttle key.
|
||||
*/
|
||||
protected function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Matrix;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\User;
|
||||
use App\Models\ExamResult;
|
||||
|
||||
class ComplianceMonitor extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
// Contoh logika sederhana: Menghitung persentase karyawan yang sudah lulus ujian
|
||||
$totalKaryawan = User::where('role', 'karyawan')->count();
|
||||
|
||||
// Hitung karyawan unik yang sudah memiliki minimal 1 hasil lulus
|
||||
$karyawanLulus = ExamResult::where('is_passed', true)
|
||||
->distinct('user_id')
|
||||
->count('user_id');
|
||||
|
||||
$complianceRate = $totalKaryawan > 0 ? round(($karyawanLulus / $totalKaryawan) * 100) : 0;
|
||||
|
||||
return view('livewire.matrix.compliance-monitor', [
|
||||
'complianceRate' => $complianceRate,
|
||||
'totalKaryawan' => $totalKaryawan,
|
||||
'karyawanLulus' => $karyawanLulus
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user