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')
|
$berita = Informasi::where('kategori_informasi', 'berita')
|
||||||
->where('id_informasi', $id)
|
->where('id_informasi', $id)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
$recentBerita = Informasi::where('kategori_informasi', 'berita')
|
$recentBerita = Informasi::where('kategori_informasi', 'berita')
|
||||||
->where('id_informasi', '!=', $id)
|
->where('id_informasi', '!=', $id)
|
||||||
->orderBy('tanggal_informasi', 'desc')
|
->orderBy('tanggal_informasi', 'desc')
|
||||||
->limit(5)
|
->limit(5)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return view('user.detail-berita', compact('berita', 'recentBerita'));
|
return view('user.detail-berita', compact('berita', 'recentBerita'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,5 +52,4 @@ public function hero()
|
||||||
|
|
||||||
return view('user.index', compact('beritaHero'));
|
return view('user.index', compact('beritaHero'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,20 +19,16 @@ public function index()
|
||||||
return view('user.pengumuman', compact('pengumuman'));
|
return view('user.pengumuman', compact('pengumuman'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$pengumuman = Informasi::where('kategori_informasi','pengumuman')
|
$pengumuman = Informasi::where('kategori_informasi','pengumuman')
|
||||||
->where('id_informasi',$id)
|
->where('id_informasi',$id)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
|
|
||||||
$recentPengumuman = Informasi::where('kategori_informasi','pengumuman')
|
$recentPengumuman = Informasi::where('kategori_informasi','pengumuman')
|
||||||
->where('id_informasi','!=',$id)
|
->where('id_informasi','!=',$id)
|
||||||
->orderBy('tanggal_informasi','desc')
|
->orderBy('tanggal_informasi','desc')
|
||||||
->limit(5)
|
->limit(5)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
return view('user.detail-pengumuman', compact('pengumuman','recentPengumuman'));
|
return view('user.detail-pengumuman', compact('pengumuman','recentPengumuman'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ public function authorize(): bool
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'username' => ['required', 'string'],
|
'username' => ['required', 'string', 'regex:/^[a-z]+$/'],
|
||||||
'password' => ['required', 'string', 'min:8'],
|
'password' => ['required', 'string', 'min:8'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -39,10 +39,11 @@ public function messages(): array
|
||||||
return [
|
return [
|
||||||
'username.required' => 'Username wajib diisi.',
|
'username.required' => 'Username wajib diisi.',
|
||||||
'username.string' => 'Username harus berupa teks.',
|
'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.required' => 'Password wajib diisi.',
|
||||||
'password.string' => 'Password harus berupa teks.',
|
'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)
|
// Cek limit login (anti brute force)
|
||||||
$this->ensureIsNotRateLimited();
|
$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) {
|
if (!$this->username && !$this->password) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'username' => 'Username dan password wajib diisi.',
|
'username' => 'Username dan password wajib diisi.',
|
||||||
|
|
@ -62,7 +66,7 @@ public function authenticate(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cek apakah username ada
|
// Cek apakah username ada
|
||||||
$user = User::where('username', $this->username)->first();
|
$user = User::where('username', $username)->first();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'username' => 'Username tidak terdaftar.',
|
'username' => 'Username tidak terdaftar.',
|
||||||
|
|
@ -71,7 +75,7 @@ public function authenticate(): void
|
||||||
|
|
||||||
// Cek password
|
// Cek password
|
||||||
if (!Auth::attempt([
|
if (!Auth::attempt([
|
||||||
'username' => $this->username,
|
'username' => $username,
|
||||||
'password' => $this->password,
|
'password' => $this->password,
|
||||||
])) {
|
])) {
|
||||||
RateLimiter::hit($this->throttleKey());
|
RateLimiter::hit($this->throttleKey());
|
||||||
|
|
|
||||||
|
|
@ -92,4 +92,3 @@ class="form-control file-upload-info"
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,6 @@
|
||||||
<form class="pt-3" method="POST" action="{{ route('login') }}" novalidate>
|
<form class="pt-3" method="POST" action="{{ route('login') }}" novalidate>
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
<!-- ERROR GLOBAL -->
|
|
||||||
{{-- @if ($errors->any())
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
{{ $errors->first() }}
|
|
||||||
</div>
|
|
||||||
@endif --}}
|
|
||||||
|
|
||||||
<!-- USERNAME -->
|
<!-- USERNAME -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue