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.
This commit is contained in:
@@ -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'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user