validasi login 2
This commit is contained in:
parent
782b51fbb3
commit
1798868133
|
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -92,4 +92,3 @@ class="form-control file-upload-info"
|
|||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
Loading…
Reference in New Issue