From 42293fb11a0fa3bb61c5947efca39fe2f04c58ae Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 13 Mar 2024 10:10:53 +0100 Subject: [PATCH] feat: reset password --- app/Livewire/Profile/Index.php | 34 +++++++++++++++++-- .../livewire/force-password-reset.blade.php | 4 +-- .../views/livewire/profile/index.blade.php | 15 ++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/app/Livewire/Profile/Index.php b/app/Livewire/Profile/Index.php index 3499d4ff9..abfc0b972 100644 --- a/app/Livewire/Profile/Index.php +++ b/app/Livewire/Profile/Index.php @@ -2,6 +2,7 @@ namespace App\Livewire\Profile; +use Illuminate\Support\Facades\Hash; use Livewire\Attributes\Validate; use Livewire\Component; @@ -10,6 +11,13 @@ 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')] public string $name; public function mount() @@ -19,7 +27,6 @@ class Index extends Component $this->email = auth()->user()->email; } public function submit() - { try { $this->validate(); @@ -27,7 +34,30 @@ class Index extends Component 'name' => $this->name, ]); - $this->dispatch('success', 'Profile updated'); + $this->dispatch('success', 'Profile updated.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function resetPassword() + { + try { + $this->validate(); + if (!Hash::check($this->current_password, auth()->user()->password)) { + $this->dispatch('error', 'Current password is incorrect.'); + return; + } + if ($this->new_password !== $this->new_password_confirmation) { + $this->dispatch('error', 'The two new passwords does not match.'); + return; + } + auth()->user()->update([ + 'password' => Hash::make($this->new_password), + ]); + $this->dispatch('success', 'Password updated.'); + $this->current_password = ''; + $this->new_password = ''; + $this->new_password_confirmation = ''; } catch (\Throwable $e) { return handleError($e, $this); } diff --git a/resources/views/livewire/force-password-reset.blade.php b/resources/views/livewire/force-password-reset.blade.php index d6951d0ad..d77651675 100644 --- a/resources/views/livewire/force-password-reset.blade.php +++ b/resources/views/livewire/force-password-reset.blade.php @@ -5,9 +5,7 @@
Coolify
-
- Set your initial password -
+
diff --git a/resources/views/livewire/profile/index.blade.php b/resources/views/livewire/profile/index.blade.php index aa8cb5708..af4de1b2b 100644 --- a/resources/views/livewire/profile/index.blade.php +++ b/resources/views/livewire/profile/index.blade.php @@ -6,13 +6,22 @@

General

Save -
+
-

Subscription

- Check in Team Settings +
+
+

Reset Password

+ Reset +
+
+ + + +
+

Two-factor Authentication

@if (session('status') == 'two-factor-authentication-enabled')