reset-password.blade.php (3553B)
1 <?php 2 3 use Illuminate\Auth\Events\PasswordReset; 4 use Illuminate\Support\Facades\Hash; 5 use Illuminate\Support\Facades\Password; 6 use Illuminate\Support\Str; 7 use Illuminate\Validation\Rules; 8 use Livewire\Attributes\Layout; 9 use Livewire\Attributes\Locked; 10 use Livewire\Volt\Component; 11 12 new #[Layout('layouts.guest')] class extends Component 13 { 14 #[Locked] 15 public string $token = ''; 16 17 public string $email = ''; 18 19 public string $password = ''; 20 21 public string $password_confirmation = ''; 22 23 public function mount(string $token): void 24 { 25 $this->token = $token; 26 27 $this->email = request()->string('email'); 28 } 29 30 public function resetPassword(): void 31 { 32 $this->validate([ 33 'token' => ['required'], 34 'email' => ['required', 'string', 'email'], 35 'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()], 36 ]); 37 38 // Here we will attempt to reset the user's password. If it is successful we 39 // will update the password on an actual user model and persist it to the 40 // database. Otherwise we will parse the error and return the response. 41 $status = Password::reset( 42 $this->only('email', 'password', 'password_confirmation', 'token'), 43 function ($user) { 44 $user->forceFill([ 45 'password' => Hash::make($this->password), 46 'remember_token' => Str::random(60), 47 ])->save(); 48 49 event(new PasswordReset($user)); 50 } 51 ); 52 53 // If the password was successfully reset, we will redirect the user back to 54 // the application's home authenticated view. If there is an error we can 55 // redirect them back to where they came from with their error message. 56 if ($status != Password::PASSWORD_RESET) { 57 $this->addError('email', __($status)); 58 59 return; 60 } 61 62 session()->flash('status', __($status)); 63 64 $this->redirectRoute('login', navigate: true); 65 } 66 }; ?> 67 68 <div> 69 <form wire:submit="resetPassword"> 70 <!-- Email Address --> 71 <div> 72 <x-input-label for="email" :value="__('Email')" /> 73 <x-text-input wire:model="email" id="email" class="block mt-1 w-full" type="email" name="email" required autofocus autocomplete="username" /> 74 <x-input-error :messages="$errors->get('email')" class="mt-2" /> 75 </div> 76 77 <!-- Password --> 78 <div class="mt-4"> 79 <x-input-label for="password" :value="__('Password')" /> 80 <x-text-input wire:model="password" id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" /> 81 <x-input-error :messages="$errors->get('password')" class="mt-2" /> 82 </div> 83 84 <!-- Confirm Password --> 85 <div class="mt-4"> 86 <x-input-label for="password_confirmation" :value="__('Confirm Password')" /> 87 88 <x-text-input wire:model="password_confirmation" id="password_confirmation" class="block mt-1 w-full" 89 type="password" 90 name="password_confirmation" required autocomplete="new-password" /> 91 92 <x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" /> 93 </div> 94 95 <div class="flex items-center justify-end mt-4"> 96 <x-primary-button> 97 {{ __('Reset Password') }} 98 </x-primary-button> 99 </div> 100 </form> 101 </div>