Refactor password validation and update button label

This commit is contained in:
Andras Bacsai 2024-03-21 14:46:34 +01:00
parent fbc0a39a1c
commit 7a3bb14653
2 changed files with 10 additions and 7 deletions

View File

@ -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;

View File

@ -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" />