validasi login 2

This commit is contained in:
rahmagustin 2026-04-15 15:22:40 +07:00
parent 782b51fbb3
commit 1798868133
5 changed files with 57 additions and 67 deletions

View File

@ -31,13 +31,11 @@ public function show($id)
$berita = Informasi::where('kategori_informasi', 'berita')
->where('id_informasi', $id)
->firstOrFail();
$recentBerita = Informasi::where('kategori_informasi', 'berita')
->where('id_informasi', '!=', $id)
->orderBy('tanggal_informasi', 'desc')
->limit(5)
->get();
return view('user.detail-berita', compact('berita', 'recentBerita'));
}
@ -54,5 +52,4 @@ public function hero()
return view('user.index', compact('beritaHero'));
}
}

View File

@ -19,20 +19,16 @@ public function index()
return view('user.pengumuman', compact('pengumuman'));
}
public function show($id)
{
$pengumuman = Informasi::where('kategori_informasi','pengumuman')
->where('id_informasi',$id)
->firstOrFail();
$recentPengumuman = Informasi::where('kategori_informasi','pengumuman')
->where('id_informasi','!=',$id)
->orderBy('tanggal_informasi','desc')
->limit(5)
->get();
return view('user.detail-pengumuman', compact('pengumuman','recentPengumuman'));
}

View File

@ -26,7 +26,7 @@ public function authorize(): bool
public function rules(): array
{
return [
'username' => ['required', 'string'],
'username' => ['required', 'string', 'regex:/^[a-z]+$/'],
'password' => ['required', 'string', 'min:8'],
];
}
@ -39,10 +39,11 @@ public function messages(): array
return [
'username.required' => 'Username wajib diisi.',
'username.string' => 'Username harus berupa teks.',
'username.regex' => 'Username hanya boleh huruf kecil (a-z) tanpa angka atau simbol.',
'password.required' => 'Password wajib diisi.',
'password.string' => 'Password harus berupa teks.',
'password.min' => 'Password minimal 6 karakter.',
'password.min' => 'Password minimal 8 karakter.',
];
}
@ -54,7 +55,10 @@ public function authenticate(): void
// Cek limit login (anti brute force)
$this->ensureIsNotRateLimited();
// Jika dua-duanya kosong (optional tambahan biar lebih jelas)
// Ambil username dalam bentuk huruf kecil (biar konsisten)
$username = strtolower($this->username);
// Jika dua-duanya kosong
if (!$this->username && !$this->password) {
throw ValidationException::withMessages([
'username' => 'Username dan password wajib diisi.',
@ -62,7 +66,7 @@ public function authenticate(): void
}
// Cek apakah username ada
$user = User::where('username', $this->username)->first();
$user = User::where('username', $username)->first();
if (!$user) {
throw ValidationException::withMessages([
'username' => 'Username tidak terdaftar.',
@ -71,7 +75,7 @@ public function authenticate(): void
// Cek password
if (!Auth::attempt([
'username' => $this->username,
'username' => $username,
'password' => $this->password,
])) {
RateLimiter::hit($this->throttleKey());

View File

@ -92,4 +92,3 @@ class="form-control file-upload-info"
</div>
</div>
@endsection

View File

@ -33,12 +33,6 @@
<form class="pt-3" method="POST" action="{{ route('login') }}" novalidate>
@csrf
<!-- ERROR GLOBAL -->
{{-- @if ($errors->any())
<div class="alert alert-danger">
{{ $errors->first() }}
</div>
@endif --}}
<!-- USERNAME -->
<div class="form-group">