From c517ec849d2d84a69555fe4b88937062683d8e36 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 29 Jun 2021 10:05:23 -0700 Subject: [PATCH] Small refactor for login Livewire Signed-off-by: snipe --- app/Http/Livewire/LoginForm.php | 35 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/app/Http/Livewire/LoginForm.php b/app/Http/Livewire/LoginForm.php index d1b196111..77edab9e6 100644 --- a/app/Http/Livewire/LoginForm.php +++ b/app/Http/Livewire/LoginForm.php @@ -33,38 +33,37 @@ class LoginForm extends Component */ public function updated($fields) { - $this->validateOnly($fields); - - if (!is_null($fields) && !empty($fields)) { - $this->can_submit = true; - } else { + + if (is_null($fields) || empty($fields)) { $this->can_submit = false; - } + } + + $this->validateOnly($fields); + + $this->can_submit = true; + } /** * Actually do the login thing * - * @todo fix missing LDAP stuff maybe? + * @todo fix missing LDAP stuff maybe? Not sure if it + * makes sense to even do this via LiveWire, since + * our login system is pretty complicated. + * * @author A. Ginaotto * @version v6.0 */ public function submitForm() { - $validatedData = $this->validate(); - - if (\Auth::attempt( - [ - 'username' => $this->username, - 'password' => $this->password - ] - )) - { - redirect()->route('dashboard'); + $this->can_submit = true; + + if (auth()->attempt($this->validate())) { + return redirect()->intended('/'); } else { - session()->flash('error', trans('auth/message.account_not_found')); + return session()->flash('error', trans('auth/message.account_not_found')); } }