diff --git a/app/Livewire/Auth/ForgotPassword.php b/app/Livewire/Auth/ForgotPassword.php new file mode 100644 index 0000000..65b2125 --- /dev/null +++ b/app/Livewire/Auth/ForgotPassword.php @@ -0,0 +1,21 @@ +form->sendPasswordResetLink(); + } + + public function render() + { + return view('livewire.auth.forgot-password'); + } +} diff --git a/app/Livewire/Auth/ResetPassword.php b/app/Livewire/Auth/ResetPassword.php new file mode 100644 index 0000000..852e33b --- /dev/null +++ b/app/Livewire/Auth/ResetPassword.php @@ -0,0 +1,35 @@ +form->setToken($token); + + $this->form->setEmail(request()->string('email')); + } + + public function send(): void + { + if (!$this->form->resetPassword()) { + return; + } + + $this->redirect(route('login', absolute: false), navigate: true); + } + + public function render() + { + return view('livewire.auth.reset-password'); + } +} diff --git a/app/Livewire/Forms/ForgotPasswordForm.php b/app/Livewire/Forms/ForgotPasswordForm.php new file mode 100644 index 0000000..c3c3d2c --- /dev/null +++ b/app/Livewire/Forms/ForgotPasswordForm.php @@ -0,0 +1,47 @@ +validate(); + + // We will send the password reset link to this user. Once we have attempted + // to send the link, we will examine the response then see the message we + // need to show to the user. Finally, we'll send out a proper response. + $status = Password::sendResetLink( + $this->only('email') + ); + + if ($status != Password::RESET_LINK_SENT) { + $this->addError('email', __($status)); + + return; + } + + $this->reset('email'); + + session()->flash('status', __($status)); + } +} diff --git a/app/Livewire/Forms/ResetPasswordForm.php b/app/Livewire/Forms/ResetPasswordForm.php new file mode 100644 index 0000000..f3174e8 --- /dev/null +++ b/app/Livewire/Forms/ResetPasswordForm.php @@ -0,0 +1,77 @@ + ['required'], + 'email' => ['required', 'string', 'email'], + 'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()], + ]; + } + + public function setToken(string $token): void + { + $this->token = $token; + } + + public function setEmail(string $email): void + { + $this->email = $email; + } + + /** + * Reset the password for the given user. + */ + public function resetPassword(): bool + { + $this->validate(); + + // Here we will attempt to reset the user's password. If it is successful we + // will update the password on an actual user model and persist it to the + // database. Otherwise we will parse the error and return the response. + $status = Password::reset( + $this->only('email', 'password', 'password_confirmation', 'token'), + function ($user) { + $user->forceFill([ + 'password' => Hash::make($this->password), + 'remember_token' => Str::random(60), + ])->save(); + + event(new PasswordReset($user)); + } + ); + + // If the password was successfully reset, we will redirect the user back to + // the application's home authenticated view. If there is an error we can + // redirect them back to where they came from with their error message. + if ($status != Password::PASSWORD_RESET) { + $this->addError('email', __($status)); + + return false; + } + + Session::flash('status', __($status)); + + return true; + } +} diff --git a/resources/views/livewire/auth/forgot-password.blade.php b/resources/views/livewire/auth/forgot-password.blade.php new file mode 100644 index 0000000..89ce139 --- /dev/null +++ b/resources/views/livewire/auth/forgot-password.blade.php @@ -0,0 +1,41 @@ +