-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use Illuminate\Contracts\Auth\StatefulGuard; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Validation\ValidationException; | ||
use Laravel\Jetstream\Contracts\DeletesUsers; | ||
use Livewire\Component; | ||
|
||
class DeleteUserForm extends Component | ||
{ | ||
/** | ||
* Indicates if user deletion is being confirmed. | ||
* | ||
* @var bool | ||
*/ | ||
public $confirmingUserDeletion = false; | ||
|
||
/** | ||
* The user's current password. | ||
* | ||
* @var string | ||
*/ | ||
public $password = ''; | ||
|
||
/** | ||
* Confirm that the user would like to delete their account. | ||
* | ||
* @return void | ||
*/ | ||
public function confirmUserDeletion() | ||
{ | ||
$this->resetErrorBag(); | ||
|
||
$this->password = ''; | ||
|
||
$this->dispatchBrowserEvent('confirming-delete-user'); | ||
|
||
$this->confirmingUserDeletion = true; | ||
} | ||
|
||
/** | ||
* Delete the current user. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Laravel\Jetstream\Contracts\DeletesUsers $deleter | ||
* @param \Illuminate\Contracts\Auth\StatefulGuard $auth | ||
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse | ||
*/ | ||
public function deleteUser(Request $request, DeletesUsers $deleter, StatefulGuard $auth) | ||
{ | ||
$this->resetErrorBag(); | ||
if(Auth::user()->passwordSet()) { | ||
if (!Hash::check($this->password, Auth::user()->password)) { | ||
throw ValidationException::withMessages([ | ||
'password' => [__('This password does not match our records.')], | ||
]); | ||
} | ||
} | ||
|
||
$deleter->delete(Auth::user()->fresh()); | ||
|
||
$auth->logout(); | ||
|
||
if ($request->hasSession()) { | ||
$request->session()->invalidate(); | ||
$request->session()->regenerateToken(); | ||
} | ||
|
||
return redirect(config('fortify.redirects.logout') ?? '/'); | ||
} | ||
|
||
/** | ||
* Render the component. | ||
* | ||
* @return \Illuminate\View\View | ||
*/ | ||
public function render() | ||
{ | ||
return view('profile.delete-user-form'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters