From 8f590fd177e82750ab1efb3286d642724b4ef9f5 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Sun, 17 Nov 2024 13:03:22 +0700 Subject: [PATCH] Ubah login agar mendukung email atau NIK Menambahkan dukungan login dengan email atau NIK pada form input. Menyesuaikan validasi dan proses otentikasi untuk mengenali input sebagai email atau NIK. Mengganti nama input dari 'email' menjadi 'login' serta memperbarui pesan kesalahan yang relevan. --- app/Http/Requests/LoginRequest.php | 16 ++++++++++++---- resources/views/index.blade.php | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/Http/Requests/LoginRequest.php b/app/Http/Requests/LoginRequest.php index 9bb6b71..f6a4fea 100644 --- a/app/Http/Requests/LoginRequest.php +++ b/app/Http/Requests/LoginRequest.php @@ -20,8 +20,8 @@ : array { return [ - 'email' => 'required|email', - 'password' => 'required' + 'login' => 'required', + 'password' => 'required', ]; } @@ -37,11 +37,19 @@ { $this->ensureIsNotRateLimited(); - if (!Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { + $credentials = $this->only('login', 'password'); + $loginField = filter_var($credentials['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'nik'; + + $authData = [ + $loginField => $credentials['login'], + 'password' => $credentials['password'], + ]; + + if (!Auth::attempt($authData, $this->boolean('remember'))) { RateLimiter::hit($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => trans('auth.failed'), + 'login' => trans('auth.failed'), ]); } diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index bfa2508..e9a690b 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -24,10 +24,10 @@
- - @error('email') + + @error('login') {{ $message }} @enderror