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