File tree Expand file tree Collapse file tree 4 files changed +75
-9
lines changed
inertia/resources/js/Pages/Profile
livewire/resources/views/profile Expand file tree Collapse file tree 4 files changed +75
-9
lines changed Original file line number Diff line number Diff line change 55use Illuminate \Contracts \Auth \StatefulGuard ;
66use Illuminate \Http \Request ;
77use Illuminate \Routing \Controller ;
8+ use Illuminate \Support \Facades \Hash ;
9+ use Illuminate \Validation \ValidationException ;
810use Laravel \Jetstream \Contracts \DeletesUsers ;
911
1012class CurrentUserController extends Controller
@@ -18,6 +20,12 @@ class CurrentUserController extends Controller
1820 */
1921 public function destroy (Request $ request , StatefulGuard $ auth )
2022 {
23+ if (! Hash::check ($ request ->password , $ request ->user ()->password )) {
24+ throw ValidationException::withMessages ([
25+ 'password ' => [__ ('This password does not match our records. ' )],
26+ ])->errorBag ('deleteUser ' );
27+ }
28+
2129 app (DeletesUsers::class)->delete ($ request ->user ()->fresh ());
2230
2331 $ auth ->logout ();
Original file line number Diff line number Diff line change 44
55use Illuminate \Contracts \Auth \StatefulGuard ;
66use Illuminate \Support \Facades \Auth ;
7+ use Illuminate \Support \Facades \Hash ;
8+ use Illuminate \Validation \ValidationException ;
79use Laravel \Jetstream \Contracts \DeletesUsers ;
810use Livewire \Component ;
911
@@ -16,6 +18,27 @@ class DeleteUserForm extends Component
1618 */
1719 public $ confirmingUserDeletion = false ;
1820
21+ /**
22+ * The user's current password.
23+ *
24+ * @var string
25+ */
26+ public $ password = '' ;
27+
28+ /**
29+ * Confirm that the user would like to delete their account.
30+ *
31+ * @return void
32+ */
33+ public function confirmDelete ()
34+ {
35+ $ this ->password = '' ;
36+
37+ $ this ->dispatchBrowserEvent ('confirming-delete-user ' );
38+
39+ $ this ->confirmingUserDeletion = true ;
40+ }
41+
1942 /**
2043 * Delete the current user.
2144 *
@@ -25,6 +48,14 @@ class DeleteUserForm extends Component
2548 */
2649 public function deleteUser (DeletesUsers $ deleter , StatefulGuard $ auth )
2750 {
51+ $ this ->resetErrorBag ();
52+
53+ if (! Hash::check ($ this ->password , Auth::user ()->password )) {
54+ throw ValidationException::withMessages ([
55+ 'password ' => [__ ('This password does not match our records. ' )],
56+ ]);
57+ }
58+
2859 $ deleter ->delete (Auth::user ()->fresh ());
2960
3061 $ auth ->logout ();
Original file line number Diff line number Diff line change 2626 </template >
2727
2828 <template #content >
29- Are you sure you want to delete your account? Once your account is deleted, all of its resources and data will be permanently deleted.
29+ Are you sure you want to delete your account? Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.
30+
31+ <div class =" mt-4" >
32+ <jet-input type =" password" class =" mt-1 block w-3/4" placeholder =" Password"
33+ ref =" password"
34+ v-model =" form.password"
35+ @keyup.enter.native =" deleteUser" />
36+
37+ <jet-input-error :message =" form.error('password')" class =" mt-2" />
38+ </div >
3039 </template >
3140
3241 <template #footer >
3342 <jet-secondary-button @click.native =" confirmingUserDeletion = false" >
3443 Nevermind
3544 </jet-secondary-button >
3645
37- <jet-danger-button class =" ml-2" @click.native =" deleteTeam " :class =" { 'opacity-25': form.processing }" :disabled =" form.processing" >
46+ <jet-danger-button class =" ml-2" @click.native =" deleteUser " :class =" { 'opacity-25': form.processing }" :disabled =" form.processing" >
3847 Delete Account
3948 </jet-danger-button >
4049 </template >
4857 import JetButton from ' ./../../Jetstream/Button'
4958 import JetConfirmationModal from ' ./../../Jetstream/ConfirmationModal'
5059 import JetDangerButton from ' ./../../Jetstream/DangerButton'
60+ import JetInput from ' ./../../Jetstream/Input'
61+ import JetInputError from ' ./../../Jetstream/InputError'
5162 import JetSecondaryButton from ' ./../../Jetstream/SecondaryButton'
5263
5364 export default {
5667 JetButton,
5768 JetConfirmationModal,
5869 JetDangerButton,
70+ JetInput,
71+ JetInputError,
5972 JetSecondaryButton,
6073 },
6174
6578 deleting: false ,
6679
6780 form: this .$inertia .form ({
68- //
81+ ' _method' : ' DELETE' ,
82+ password: ' ' ,
6983 }, {
7084 bag: ' deleteUser'
7185 })
7791 this .confirmingUserDeletion = true
7892 },
7993
80- deleteTeam () {
81- this .form .delete (' /user' , {
94+ deleteUser () {
95+ this .form .post (' /user' , {
8296 preserveScroll: true
83- });
97+ }).then (response => {
98+ if (! this .form .hasErrors ()) {
99+ this .confirmingUserDeletion = false
100+ }
101+ })
84102 },
85103 },
86104 }
Original file line number Diff line number Diff line change 1919 </div >
2020
2121 <!-- Delete User Confirmation Modal -->
22- <x-jet-confirmation -modal wire:model =" confirmingUserDeletion" >
22+ <x-jet-dialog -modal wire:model =" confirmingUserDeletion" >
2323 <x-slot name =" title" >
2424 Delete Account
2525 </x-slot >
2626
2727 <x-slot name =" content" >
28- Are you sure you want to delete your account? Once your account is deleted, all of its resources and data will be permanently deleted.
28+ Are you sure you want to delete your account? Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.
29+
30+ <div class =" mt-4" x-data =" {}" x-on:confirming-delete-user.window =" setTimeout(() => $refs.password.focus(), 250)" >
31+ <x-jet-input type =" password" class =" mt-1 block w-3/4" placeholder =" Password"
32+ x-ref =" password"
33+ wire:model.defer =" password"
34+ wire:keydown.enter =" deleteUser" />
35+
36+ <x-jet-input-error for =" password" class =" mt-2" />
37+ </div >
2938 </x-slot >
3039
3140 <x-slot name =" footer" >
3746 Delete Account
3847 </x-jet-danger-button >
3948 </x-slot >
40- </x-jet-confirmation -modal >
49+ </x-jet-dialog -modal >
4150 </x-slot >
4251</x-jet-action-section >
You can’t perform that action at this time.
0 commit comments