From 17988681333159265e10096cc04432a153e2e4e5 Mon Sep 17 00:00:00 2001 From: rahmagustin Date: Wed, 15 Apr 2026 15:22:40 +0700 Subject: [PATCH] validasi login 2 --- app/Http/Controllers/BeritaController.php | 75 +++++++++---------- app/Http/Controllers/PengumumanController.php | 28 +++---- app/Http/Requests/Auth/LoginRequest.php | 14 ++-- .../views/admin/kategori-tps/create.blade.php | 1 - resources/views/auth/login.blade.php | 6 -- 5 files changed, 57 insertions(+), 67 deletions(-) diff --git a/app/Http/Controllers/BeritaController.php b/app/Http/Controllers/BeritaController.php index ae85848..ab4e826 100644 --- a/app/Http/Controllers/BeritaController.php +++ b/app/Http/Controllers/BeritaController.php @@ -10,49 +10,46 @@ class BeritaController extends Controller { - /** - * Tampilkan semua berita - */ - public function index() - { - $berita = Informasi::where('kategori_informasi', 'berita') - ->orderBy('tanggal_informasi', 'desc') - ->paginate(6); + /** + * Tampilkan semua berita + */ + public function index() + { + $berita = Informasi::where('kategori_informasi', 'berita') + ->orderBy('tanggal_informasi', 'desc') + ->paginate(6); - return view('user.berita', compact('berita')); - } + return view('user.berita', compact('berita')); + } - /** - * Detail berita - */ - 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')); - } + /** + * Detail berita + */ + 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')); + } - /** - * Berita untuk hero slider - */ - public function hero() - { - $beritaHero = Informasi::where('kategori_informasi', 'berita') - ->orderBy('tanggal_informasi', 'desc') - ->take(3) - ->get(); - - return view('user.index', compact('beritaHero')); - } + /** + * Berita untuk hero slider + */ + public function hero() + { + $beritaHero = Informasi::where('kategori_informasi', 'berita') + ->orderBy('tanggal_informasi', 'desc') + ->take(3) + ->get(); + return view('user.index', compact('beritaHero')); + } } diff --git a/app/Http/Controllers/PengumumanController.php b/app/Http/Controllers/PengumumanController.php index 60487ea..924d736 100644 --- a/app/Http/Controllers/PengumumanController.php +++ b/app/Http/Controllers/PengumumanController.php @@ -19,22 +19,18 @@ 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')); - } +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')); +} public function hero() diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index 45f35d3..d1959e5 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -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()); diff --git a/resources/views/admin/kategori-tps/create.blade.php b/resources/views/admin/kategori-tps/create.blade.php index 6493036..ffea1fd 100644 --- a/resources/views/admin/kategori-tps/create.blade.php +++ b/resources/views/admin/kategori-tps/create.blade.php @@ -92,4 +92,3 @@ class="form-control file-upload-info" @endsection - diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 2d367d7..1c2b08e 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -33,12 +33,6 @@
@csrf - - {{-- @if ($errors->any()) -
- {{ $errors->first() }} -
- @endif --}}