File tree 4 files changed +75
-9
lines changed
inertia/resources/js/Pages/Profile
livewire/resources/views/profile
4 files changed +75
-9
lines changed Original file line number Diff line number Diff line change 5
5
use Illuminate \Contracts \Auth \StatefulGuard ;
6
6
use Illuminate \Http \Request ;
7
7
use Illuminate \Routing \Controller ;
8
+ use Illuminate \Support \Facades \Hash ;
9
+ use Illuminate \Validation \ValidationException ;
8
10
use Laravel \Jetstream \Contracts \DeletesUsers ;
9
11
10
12
class CurrentUserController extends Controller
@@ -18,6 +20,12 @@ class CurrentUserController extends Controller
18
20
*/
19
21
public function destroy (Request $ request , StatefulGuard $ auth )
20
22
{
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
+
21
29
app (DeletesUsers::class)->delete ($ request ->user ()->fresh ());
22
30
23
31
$ auth ->logout ();
Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Contracts \Auth \StatefulGuard ;
6
6
use Illuminate \Support \Facades \Auth ;
7
+ use Illuminate \Support \Facades \Hash ;
8
+ use Illuminate \Validation \ValidationException ;
7
9
use Laravel \Jetstream \Contracts \DeletesUsers ;
8
10
use Livewire \Component ;
9
11
@@ -16,6 +18,27 @@ class DeleteUserForm extends Component
16
18
*/
17
19
public $ confirmingUserDeletion = false ;
18
20
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
+
19
42
/**
20
43
* Delete the current user.
21
44
*
@@ -25,6 +48,14 @@ class DeleteUserForm extends Component
25
48
*/
26
49
public function deleteUser (DeletesUsers $ deleter , StatefulGuard $ auth )
27
50
{
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
+
28
59
$ deleter ->delete (Auth::user ()->fresh ());
29
60
30
61
$ auth ->logout ();
Original file line number Diff line number Diff line change 26
26
</template >
27
27
28
28
<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 >
30
39
</template >
31
40
32
41
<template #footer >
33
42
<jet-secondary-button @click.native =" confirmingUserDeletion = false" >
34
43
Nevermind
35
44
</jet-secondary-button >
36
45
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" >
38
47
Delete Account
39
48
</jet-danger-button >
40
49
</template >
48
57
import JetButton from ' ./../../Jetstream/Button'
49
58
import JetConfirmationModal from ' ./../../Jetstream/ConfirmationModal'
50
59
import JetDangerButton from ' ./../../Jetstream/DangerButton'
60
+ import JetInput from ' ./../../Jetstream/Input'
61
+ import JetInputError from ' ./../../Jetstream/InputError'
51
62
import JetSecondaryButton from ' ./../../Jetstream/SecondaryButton'
52
63
53
64
export default {
56
67
JetButton,
57
68
JetConfirmationModal,
58
69
JetDangerButton,
70
+ JetInput,
71
+ JetInputError,
59
72
JetSecondaryButton,
60
73
},
61
74
65
78
deleting: false ,
66
79
67
80
form: this .$inertia .form ({
68
- //
81
+ ' _method' : ' DELETE' ,
82
+ password: ' ' ,
69
83
}, {
70
84
bag: ' deleteUser'
71
85
})
77
91
this .confirmingUserDeletion = true
78
92
},
79
93
80
- deleteTeam () {
81
- this .form .delete (' /user' , {
94
+ deleteUser () {
95
+ this .form .post (' /user' , {
82
96
preserveScroll: true
83
- });
97
+ }).then (response => {
98
+ if (! this .form .hasErrors ()) {
99
+ this .confirmingUserDeletion = false
100
+ }
101
+ })
84
102
},
85
103
},
86
104
}
Original file line number Diff line number Diff line change 19
19
</div >
20
20
21
21
<!-- Delete User Confirmation Modal -->
22
- <x-jet-confirmation -modal wire:model =" confirmingUserDeletion" >
22
+ <x-jet-dialog -modal wire:model =" confirmingUserDeletion" >
23
23
<x-slot name =" title" >
24
24
Delete Account
25
25
</x-slot >
26
26
27
27
<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 >
29
38
</x-slot >
30
39
31
40
<x-slot name =" footer" >
37
46
Delete Account
38
47
</x-jet-danger-button >
39
48
</x-slot >
40
- </x-jet-confirmation -modal >
49
+ </x-jet-dialog -modal >
41
50
</x-slot >
42
51
</x-jet-action-section >
You can’t perform that action at this time.
0 commit comments