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