Refactor password validation and update button label
This commit is contained in:
parent
fbc0a39a1c
commit
7a3bb14653
@ -11,11 +11,8 @@ class Index extends Component
|
||||
public int $userId;
|
||||
public string $email;
|
||||
|
||||
#[Validate('required')]
|
||||
public string $current_password;
|
||||
#[Validate('required|min:8')]
|
||||
public string $new_password;
|
||||
#[Validate('required|min:8|same:new_password')]
|
||||
public string $new_password_confirmation;
|
||||
|
||||
#[Validate('required')]
|
||||
@ -29,7 +26,9 @@ public function mount()
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->validate();
|
||||
$this->validate([
|
||||
'name' => 'required',
|
||||
]);
|
||||
auth()->user()->update([
|
||||
'name' => $this->name,
|
||||
]);
|
||||
@ -42,7 +41,11 @@ public function submit()
|
||||
public function resetPassword()
|
||||
{
|
||||
try {
|
||||
$this->validate();
|
||||
$this->validate([
|
||||
'current_password' => 'required',
|
||||
'new_password' => 'required|min:8',
|
||||
'new_password_confirmation' => 'required|min:8|same:new_password',
|
||||
]);
|
||||
if (!Hash::check($this->current_password, auth()->user()->password)) {
|
||||
$this->dispatch('error', 'Current password is incorrect.');
|
||||
return;
|
||||
|
@ -13,8 +13,8 @@
|
||||
</form>
|
||||
<form wire:submit='resetPassword' class="flex flex-col max-w-xl pt-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<h2>Reset Password</h2>
|
||||
<x-forms.button type="submit" label="Save">Reset</x-forms.button>
|
||||
<h2>Change Password</h2>
|
||||
<x-forms.button type="submit" label="Save">Save</x-forms.button>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<x-forms.input id="current_password" label="Current Password" required type="password" />
|
||||
|
Loading…
Reference in New Issue
Block a user