From ed6c3376f1130df4a678b39886036f72e857d2c9 Mon Sep 17 00:00:00 2001 From: elbacalau Date: Mon, 16 Dec 2024 17:16:33 +0100 Subject: [PATCH 01/10] feat: add AccountController and user configuration route with basic view --- .../Controllers/Admin/AccountController.php | 19 +++++++++++++++++++ app/src/app/Layouts/Admin/AdminLayout.php | 2 +- .../Admin/AccountConfig/AccountConfig.php | 3 +++ app/src/routes/admin.php | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/src/app/Controllers/Admin/AccountController.php create mode 100644 app/src/app/Views/Admin/AccountConfig/AccountConfig.php diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php new file mode 100644 index 0000000..f308cc4 --- /dev/null +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -0,0 +1,19 @@ + 'Admin/AccountConfig/AccountConfig', + 'title' => 'Contracts', + 'layout' => 'Admin/AdminLayout', + + ]); + } +} diff --git a/app/src/app/Layouts/Admin/AdminLayout.php b/app/src/app/Layouts/Admin/AdminLayout.php index 17d006b..2954abc 100644 --- a/app/src/app/Layouts/Admin/AdminLayout.php +++ b/app/src/app/Layouts/Admin/AdminLayout.php @@ -72,7 +72,7 @@ class="block text-gray-700">
- Configuración de la cuenta Soporte diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php new file mode 100644 index 0000000..f36490b --- /dev/null +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -0,0 +1,3 @@ +
+

works!

+
\ No newline at end of file diff --git a/app/src/routes/admin.php b/app/src/routes/admin.php index d51f75d..3b92f19 100644 --- a/app/src/routes/admin.php +++ b/app/src/routes/admin.php @@ -1,5 +1,6 @@ 'index', 'middlewares' => [AdminMiddleware::class], ], + '/user-config' => [ + 'controller' => AccountController::class, + 'method' => 'index', + 'middlewares' => [AdminMiddleware::class], + ], // === Users GET Routes '/admin/users' => [ 'controller' => UserController::class, From babac892d48654bb25ee96c54732632856b2f1f5 Mon Sep 17 00:00:00 2001 From: elbacalau Date: Mon, 16 Dec 2024 17:35:56 +0100 Subject: [PATCH 02/10] feat: enhance AccountConfig view with personal information section and Spanish localization --- .../Admin/AccountConfig/AccountConfig.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index f36490b..1f956df 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -1,3 +1,20 @@ -
-

works!

+
+

Configuración

+

Aquí podrás configurar tu cuenta.

+ +
+

Información personal

+ + +
+ User Avatar +
+ +

JPG or PNG. 1MB max.

+
+
+ + +
+
\ No newline at end of file From ab2192e559fabcda04d9e0ab6648a4f8456c1dca Mon Sep 17 00:00:00 2001 From: elbacalau Date: Mon, 16 Dec 2024 19:34:33 +0100 Subject: [PATCH 03/10] feat: update AccountConfig view with user information and change route to configuration --- .../Controllers/Admin/AccountController.php | 2 +- .../Admin/AccountConfig/AccountConfig.php | 38 +++++++++++++++---- app/src/routes/admin.php | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php index f308cc4..8c34044 100644 --- a/app/src/app/Controllers/Admin/AccountController.php +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -11,7 +11,7 @@ public function index($queryParams) { View::render([ 'view' => 'Admin/AccountConfig/AccountConfig', - 'title' => 'Contracts', + 'title' => 'Configuración de cuenta', 'layout' => 'Admin/AdminLayout', ]); diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index 1f956df..b3a0b77 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -1,12 +1,10 @@
-

Configuración

+

Aquí podrás configurar tu cuenta.

- -
-

Información personal

- +
+

Información personal

-
+
User Avatar
@@ -14,7 +12,31 @@
+ +
+
+
+ + +
+
+ + +
+
+
- -
\ No newline at end of file +
diff --git a/app/src/routes/admin.php b/app/src/routes/admin.php index 3b92f19..9e6695f 100644 --- a/app/src/routes/admin.php +++ b/app/src/routes/admin.php @@ -27,7 +27,7 @@ 'method' => 'index', 'middlewares' => [AdminMiddleware::class], ], - '/user-config' => [ + '/configuration' => [ 'controller' => AccountController::class, 'method' => 'index', 'middlewares' => [AdminMiddleware::class], From 552e3ffb03803b7586fca0e67ee093a0733b9c19 Mon Sep 17 00:00:00 2001 From: elbacalau Date: Mon, 16 Dec 2024 20:57:32 +0100 Subject: [PATCH 04/10] feat: implement user data retrieval in AccountController and add change detection in form --- .editorconfig | 59 ++++++++ .../Controllers/Admin/AccountController.php | 9 +- .../app/Controllers/Auth/AuthController.php | 1 + app/src/app/Layouts/Admin/AdminLayout.php | 2 +- .../Admin/AccountConfig/AccountConfig.php | 127 ++++++++++++++---- app/src/public/assets/js/app.js | 28 ++++ 6 files changed, 196 insertions(+), 30 deletions(-) diff --git a/.editorconfig b/.editorconfig index 20041cb..d217514 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,62 @@ indent_size = 2 [docker-compose.yml] indent_size = 2 +[*] +cpp_indent_braces=false +cpp_indent_multi_line_relative_to=innermost_parenthesis +cpp_indent_within_parentheses=indent +cpp_indent_preserve_within_parentheses=false +cpp_indent_case_labels=false +cpp_indent_case_contents=true +cpp_indent_case_contents_when_block=false +cpp_indent_lambda_braces_when_parameter=true +cpp_indent_goto_labels=one_left +cpp_indent_preprocessor=leftmost_column +cpp_indent_access_specifiers=false +cpp_indent_namespace_contents=true +cpp_indent_preserve_comments=false +cpp_new_line_before_open_brace_namespace=ignore +cpp_new_line_before_open_brace_type=ignore +cpp_new_line_before_open_brace_function=ignore +cpp_new_line_before_open_brace_block=ignore +cpp_new_line_before_open_brace_lambda=ignore +cpp_new_line_scope_braces_on_separate_lines=false +cpp_new_line_close_brace_same_line_empty_type=false +cpp_new_line_close_brace_same_line_empty_function=false +cpp_new_line_before_catch=true +cpp_new_line_before_else=true +cpp_new_line_before_while_in_do_while=false +cpp_space_before_function_open_parenthesis=remove +cpp_space_within_parameter_list_parentheses=false +cpp_space_between_empty_parameter_list_parentheses=false +cpp_space_after_keywords_in_control_flow_statements=true +cpp_space_within_control_flow_statement_parentheses=false +cpp_space_before_lambda_open_parenthesis=false +cpp_space_within_cast_parentheses=false +cpp_space_after_cast_close_parenthesis=false +cpp_space_within_expression_parentheses=false +cpp_space_before_block_open_brace=true +cpp_space_between_empty_braces=false +cpp_space_before_initializer_list_open_brace=false +cpp_space_within_initializer_list_braces=true +cpp_space_preserve_in_initializer_list=true +cpp_space_before_open_square_bracket=false +cpp_space_within_square_brackets=false +cpp_space_before_empty_square_brackets=false +cpp_space_between_empty_square_brackets=false +cpp_space_group_square_brackets=true +cpp_space_within_lambda_brackets=false +cpp_space_between_empty_lambda_brackets=false +cpp_space_before_comma=false +cpp_space_after_comma=true +cpp_space_remove_around_member_operators=true +cpp_space_before_inheritance_colon=true +cpp_space_before_constructor_colon=true +cpp_space_remove_before_semicolon=true +cpp_space_after_semicolon=false +cpp_space_remove_around_unary_operator=true +cpp_space_around_binary_operator=insert +cpp_space_around_assignment_operator=insert +cpp_space_pointer_reference_alignment=left +cpp_space_around_ternary_operator=insert +cpp_wrap_preserve_blocks=one_liners diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php index 8c34044..be36d8d 100644 --- a/app/src/app/Controllers/Admin/AccountController.php +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -4,16 +4,21 @@ use App\Core\Session; use App\Core\View; +use App\Models\User; class AccountController { public function index($queryParams) - { + { + + $user = User::find(Session::get('user')['id']); View::render([ 'view' => 'Admin/AccountConfig/AccountConfig', 'title' => 'Configuración de cuenta', 'layout' => 'Admin/AdminLayout', - + 'data' => [ + 'user' => $user + ] ]); } } diff --git a/app/src/app/Controllers/Auth/AuthController.php b/app/src/app/Controllers/Auth/AuthController.php index 603a0a4..c94f935 100644 --- a/app/src/app/Controllers/Auth/AuthController.php +++ b/app/src/app/Controllers/Auth/AuthController.php @@ -52,6 +52,7 @@ public function login($postData) 'surname' => $user->surname[0], 'email' => $user->email, 'role' => $user->role, + ]); if ($user->role === 0) { header('Location: /customer'); diff --git a/app/src/app/Layouts/Admin/AdminLayout.php b/app/src/app/Layouts/Admin/AdminLayout.php index 2954abc..0f7ef5c 100644 --- a/app/src/app/Layouts/Admin/AdminLayout.php +++ b/app/src/app/Layouts/Admin/AdminLayout.php @@ -72,7 +72,7 @@ class="block text-gray-700">
- Configuración de la cuenta Soporte diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index b3a0b77..4ece92e 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -1,42 +1,115 @@
-

+

Configuración

Aquí podrás configurar tu cuenta.

-
-

Información personal

- -
- User Avatar -
- -

JPG or PNG. 1MB max.

-
-
+
+

Información personal

+ + -
+
- +
- + +
+
+
+ +
+
+
+ + + +
+
+ +
+ + +
+ + +
+ User Avatar +
+ +

JPG or PNG. 1MB max.

+
+ +
+ +
-
+ + +
+
+

Cambiar contraseña

+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+ + +
\ No newline at end of file diff --git a/app/src/public/assets/js/app.js b/app/src/public/assets/js/app.js index 0774651..a4d9f94 100644 --- a/app/src/public/assets/js/app.js +++ b/app/src/public/assets/js/app.js @@ -379,3 +379,31 @@ function applySelection() { // Cierra el modal closeModal(); } + + +// func to active the button if detect changes in the form +function checkChanges() { + const inputs = document.querySelectorAll("input"); + const button = document.getElementById("button-save"); + + let changesDetected = false; + + + inputs.forEach(input => { + const originalValue = input.getAttribute("data-original-value"); + if (input.value !== originalValue) { + changesDetected = true; + } + }); + + + if (changesDetected) { + button.disabled = false; + button.classList.remove("bg-gray-400", "cursor-not-allowed"); + button.classList.add("bg-green-500", "hover:bg-green-600"); + } else { + button.disabled = true; + button.classList.add("bg-gray-400", "cursor-not-allowed"); + button.classList.remove("bg-green-500", "hover:bg-green-600"); + } +} From 7cba35299551a03e41a783a657578bba86f9721b Mon Sep 17 00:00:00 2001 From: elbacalau Date: Tue, 17 Dec 2024 17:02:55 +0100 Subject: [PATCH 05/10] refactor: clean up AccountConfig view by removing unused code and improving button consistency --- .../app/Views/Admin/AccountConfig/AccountConfig.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index 4ece92e..61ca63b 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -4,7 +4,7 @@

Información personal

- +
@@ -54,7 +54,7 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100"
- +
@@ -65,11 +65,6 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100"

JPG or PNG. 1MB max.

- - -
- -
@@ -77,7 +72,7 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100"

Cambiar contraseña

-
+
@@ -104,7 +99,7 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" oninput="checkChanges()">
- +
From 3d0d093009aabf4a7777ab8690d2201f2dab14ca Mon Sep 17 00:00:00 2001 From: elbacalau Date: Tue, 17 Dec 2024 17:05:54 +0100 Subject: [PATCH 06/10] feat: add disabled state to email input and save button in AccountConfig view --- .../app/Views/Admin/AccountConfig/AccountConfig.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index 61ca63b..bcfa768 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -4,7 +4,7 @@

Información personal

- +
@@ -50,11 +50,12 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" id="email" class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" value="email ?>" - oninput="checkChanges()"> + oninput="checkChanges()" + disabled>
- +
@@ -65,6 +66,11 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100"

JPG or PNG. 1MB max.

+ + +
+ +
From ecd9a18cb3549b32c9b3ee56500ec1adabb175d6 Mon Sep 17 00:00:00 2001 From: elbacalau Date: Tue, 17 Dec 2024 20:19:23 +0100 Subject: [PATCH 07/10] feat: add admin routes for user configuration updates and password management --- .../Controllers/Admin/AccountController.php | 72 +++++++- app/src/app/Layouts/Admin/AdminLayout.php | 2 +- .../Admin/AccountConfig/AccountConfig.php | 165 ++++++++++-------- app/src/public/assets/js/app.js | 70 +++++++- app/src/routes/admin.php | 14 +- 5 files changed, 242 insertions(+), 81 deletions(-) diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php index be36d8d..6af631f 100644 --- a/app/src/app/Controllers/Admin/AccountController.php +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -9,7 +9,7 @@ class AccountController { public function index($queryParams) - { + { $user = User::find(Session::get('user')['id']); View::render([ @@ -21,4 +21,74 @@ public function index($queryParams) ] ]); } + + + public function update($id, $postData) + { + + $user = User::find(id: $id); + + if (!$user) { + Session::set('error', 'Usuario no encontrado'); + header('Location: /admin/configuration'); + exit; + } + + $user->name = $postData['name']; + $user->surname = $postData['surname']; + $user->save(); + + // **warning: recharge the user session with the new data + Session::set('user', [ + 'id' => $user->getId(), + 'name' => $user->name, + 'surname' => $user->surname[0], + 'email' => $user->email, + 'role' => $user->role, + + ]); + + Session::set('success', 'Usuario actualizado correctamente'); + + + + header('Location: /admin/configuration'); + } + + // method to update the password + public function updatePassword($id, $postData) + { + + $user = User::find(id: $id); + + + if (!$user) { + Session::set('error', 'Usuario no encontrado'); + header('Location: /admin/configuration'); + exit; + } + + if (!password_verify($postData['current_password'], $user->password)) { + Session::set('error', 'La contraseña actual es incorrecta'); + header('Location: /admin/configuration'); + exit; + } + + + if ($postData['password'] !== $postData['password_confirmation']) { + Session::set('error', 'Las contraseñas no coinciden'); + header('Location: /admin/configuration'); + exit; + } + + + $user->password = password_hash($postData['password'], PASSWORD_DEFAULT); + $user->save(); + + session_unset(); + session_destroy(); + + Session::set('success', 'Contraseña actualizada correctamente'); + header('Location: /admin/configuration'); + } } diff --git a/app/src/app/Layouts/Admin/AdminLayout.php b/app/src/app/Layouts/Admin/AdminLayout.php index 0f7ef5c..baa8f59 100644 --- a/app/src/app/Layouts/Admin/AdminLayout.php +++ b/app/src/app/Layouts/Admin/AdminLayout.php @@ -72,7 +72,7 @@ class="block text-gray-700">
- Configuración de la cuenta Soporte diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index bcfa768..909c809 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -1,114 +1,139 @@

Configuración

Aquí podrás configurar tu cuenta.

-
-

Información personal

+
+

Informacíon personal

- +
+ +
+
+
+ + +
- -
- -
- - -
-
- - +
+ + +
- -
+
-
-
-
- - +
+
+
+ + +
+
+ + +
-
- - -
- - - -
+
- -
- User Avatar -
- -

JPG or PNG. 1MB max.

+ +
+ User Avatar +
+ +

JPG or PNG. 1MB max.

+
-
- -
- -
+ +
+ +
+
+
-
+

Cambiar contraseña

-
-
+ +
+ oninput="checkPasswordFields()">
+ oninput="checkPasswordFields()">
+ oninput="checkPasswordFields()">
+ +
- +
- -
+
+
diff --git a/app/src/public/assets/js/app.js b/app/src/public/assets/js/app.js index a4d9f94..eeb0124 100644 --- a/app/src/public/assets/js/app.js +++ b/app/src/public/assets/js/app.js @@ -380,7 +380,6 @@ function applySelection() { closeModal(); } - // func to active the button if detect changes in the form function checkChanges() { const inputs = document.querySelectorAll("input"); @@ -388,22 +387,77 @@ function checkChanges() { let changesDetected = false; - - inputs.forEach(input => { + inputs.forEach((input) => { const originalValue = input.getAttribute("data-original-value"); if (input.value !== originalValue) { changesDetected = true; } }); - if (changesDetected) { button.disabled = false; - button.classList.remove("bg-gray-400", "cursor-not-allowed"); - button.classList.add("bg-green-500", "hover:bg-green-600"); + button.classList.remove( + "bg-gray-400", + "cursor-not-allowed", + "text-gray-500" + ); + button.classList.add( + "bg-green-500", + "hover:bg-green-600", + "text-white" + ); + } else { + button.disabled = true; + button.classList.add( + "bg-gray-400", + "cursor-not-allowed", + "text-gray-500" + ); + button.classList.remove( + "bg-green-500", + "hover:bg-green-600", + "text-white" + ); + } +} + +function checkPasswordFields() { + const currentPassword = document + .getElementById("current-password") + .value.trim(); + const newPassword = document.getElementById("new-password").value.trim(); + const confirmPassword = document + .getElementById("confirm-password") + .value.trim(); + const button = document.getElementById("button-save-password"); + + if ( + currentPassword !== "" && + newPassword !== "" && + confirmPassword !== "" + ) { + button.disabled = false; + button.classList.remove( + "bg-gray-300", + "cursor-not-allowed", + "text-gray-500" + ); + button.classList.add( + "bg-green-500", + "hover:bg-green-600", + "text-white" + ); } else { button.disabled = true; - button.classList.add("bg-gray-400", "cursor-not-allowed"); - button.classList.remove("bg-green-500", "hover:bg-green-600"); + button.classList.add( + "bg-gray-300", + "cursor-not-allowed", + "text-gray-500" + ); + button.classList.remove( + "bg-green-500", + "hover:bg-green-600", + "text-white" + ); } } diff --git a/app/src/routes/admin.php b/app/src/routes/admin.php index 9e6695f..6770922 100644 --- a/app/src/routes/admin.php +++ b/app/src/routes/admin.php @@ -27,7 +27,7 @@ 'method' => 'index', 'middlewares' => [AdminMiddleware::class], ], - '/configuration' => [ + '/admin/configuration' => [ 'controller' => AccountController::class, 'method' => 'index', 'middlewares' => [AdminMiddleware::class], @@ -302,5 +302,17 @@ 'method' => 'update', 'middlewares' => [AdminMiddleware::class], ], + + // === Config POST Routes + '/admin/configuration/:id/update' => [ + 'controller' => AccountController::class, + 'method' => 'update', + 'middlewares' => [AdminMiddleware::class], + ], + '/admin/configuration/:id/update-password' => [ + 'controller' => AccountController::class, + 'method' => 'updatePassword', + 'middlewares' => [AdminMiddleware::class], + ], ], ]; From 2dd34afaf06b9cd57dcb17995d90effcbee6db9e Mon Sep 17 00:00:00 2001 From: elbacalau Date: Tue, 17 Dec 2024 21:07:10 +0100 Subject: [PATCH 08/10] feat: consolidate user update functionality by merging update and updatePassword methods in AccountController --- .../Controllers/Admin/AccountController.php | 56 ++++-------------- .../Admin/AccountConfig/AccountConfig.php | 59 +++++++------------ app/src/public/assets/js/app.js | 41 ------------- app/src/routes/admin.php | 6 +- 4 files changed, 32 insertions(+), 130 deletions(-) diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php index 6af631f..985dd19 100644 --- a/app/src/app/Controllers/Admin/AccountController.php +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -25,7 +25,6 @@ public function index($queryParams) public function update($id, $postData) { - $user = User::find(id: $id); if (!$user) { @@ -34,61 +33,28 @@ public function update($id, $postData) exit; } + $user->name = $postData['name']; $user->surname = $postData['surname']; + + // detect password changes + if (!empty($postData['password'])) { + $user->password = password_hash($postData['password'], PASSWORD_DEFAULT); + } + + $user->save(); - // **warning: recharge the user session with the new data + Session::set('user', [ 'id' => $user->getId(), 'name' => $user->name, - 'surname' => $user->surname[0], + 'surname' => $user->surname, 'email' => $user->email, 'role' => $user->role, - ]); - Session::set('success', 'Usuario actualizado correctamente'); - - - - header('Location: /admin/configuration'); - } - - // method to update the password - public function updatePassword($id, $postData) - { - - $user = User::find(id: $id); - - - if (!$user) { - Session::set('error', 'Usuario no encontrado'); - header('Location: /admin/configuration'); - exit; - } - - if (!password_verify($postData['current_password'], $user->password)) { - Session::set('error', 'La contraseña actual es incorrecta'); - header('Location: /admin/configuration'); - exit; - } - - - if ($postData['password'] !== $postData['password_confirmation']) { - Session::set('error', 'Las contraseñas no coinciden'); - header('Location: /admin/configuration'); - exit; - } - - - $user->password = password_hash($postData['password'], PASSWORD_DEFAULT); - $user->save(); - - session_unset(); - session_destroy(); - - Session::set('success', 'Contraseña actualizada correctamente'); + Session::set('success', 'Usuario y/o contraseña actualizados correctamente'); header('Location: /admin/configuration'); } } diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index 909c809..baa5589 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -1,8 +1,8 @@

Configuración

Aquí podrás configurar tu cuenta.

-
-

Informacíon personal

+
+

Informacíon personal

@@ -73,27 +73,9 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100 cursor-not-all
- -
- -
- - - - - -
-
-

Cambiar contraseña

- -
-
+ +

Cambiar contraseña

+
+ oninput="checkChanges()">
@@ -110,7 +92,7 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" id="new-password" name="password" class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" - oninput="checkPasswordFields()"> + oninput="checkChanges()">
@@ -119,23 +101,22 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" id="confirm-password" name="password_confirmation" class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100" - oninput="checkPasswordFields()"> -
- - -
- + oninput="checkChanges()">
- -
+ +
+ +
+ +
\ No newline at end of file diff --git a/app/src/public/assets/js/app.js b/app/src/public/assets/js/app.js index eeb0124..800fd42 100644 --- a/app/src/public/assets/js/app.js +++ b/app/src/public/assets/js/app.js @@ -420,44 +420,3 @@ function checkChanges() { ); } } - -function checkPasswordFields() { - const currentPassword = document - .getElementById("current-password") - .value.trim(); - const newPassword = document.getElementById("new-password").value.trim(); - const confirmPassword = document - .getElementById("confirm-password") - .value.trim(); - const button = document.getElementById("button-save-password"); - - if ( - currentPassword !== "" && - newPassword !== "" && - confirmPassword !== "" - ) { - button.disabled = false; - button.classList.remove( - "bg-gray-300", - "cursor-not-allowed", - "text-gray-500" - ); - button.classList.add( - "bg-green-500", - "hover:bg-green-600", - "text-white" - ); - } else { - button.disabled = true; - button.classList.add( - "bg-gray-300", - "cursor-not-allowed", - "text-gray-500" - ); - button.classList.remove( - "bg-green-500", - "hover:bg-green-600", - "text-white" - ); - } -} diff --git a/app/src/routes/admin.php b/app/src/routes/admin.php index 6770922..4384543 100644 --- a/app/src/routes/admin.php +++ b/app/src/routes/admin.php @@ -304,15 +304,11 @@ ], // === Config POST Routes + '/admin/configuration/:id/update' => [ 'controller' => AccountController::class, 'method' => 'update', 'middlewares' => [AdminMiddleware::class], ], - '/admin/configuration/:id/update-password' => [ - 'controller' => AccountController::class, - 'method' => 'updatePassword', - 'middlewares' => [AdminMiddleware::class], - ], ], ]; From 1ef2e15ea8c36b0b6202f6103192bd1ecab0dcc0 Mon Sep 17 00:00:00 2001 From: elbacalau Date: Wed, 18 Dec 2024 18:40:57 +0100 Subject: [PATCH 09/10] feat: enhance password change functionality with current password verification and error handling --- .../Controllers/Admin/AccountController.php | 33 +++++++-- .../Admin/AccountConfig/AccountConfig.php | 69 +++++++++++-------- 2 files changed, 69 insertions(+), 33 deletions(-) diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php index 985dd19..a90d862 100644 --- a/app/src/app/Controllers/Admin/AccountController.php +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -33,19 +33,42 @@ public function update($id, $postData) exit; } - + // save the new data $user->name = $postData['name']; $user->surname = $postData['surname']; // detect password changes - if (!empty($postData['password'])) { - $user->password = password_hash($postData['password'], PASSWORD_DEFAULT); + if (strlen($postData['current_password']) > 0) { + + + + if (!password_verify($postData['current_password'], $user->password)) { + Session::set('error', 'Contraseña incorrecta'); + header('Location: /admin/configuration'); + exit; + } + + + if (empty($postData['password']) || empty($postData['password_confirmation'])) { + Session::set('error', 'Completa los campos'); + header('Location: /admin/configuration'); + exit; + } + + + if ($postData['password'] !== $postData['password_confirmation']) { + Session::set('error', 'Las contraseñas no coinciden'); + header('Location: /admin/configuration'); + exit; + } + + $user->password = password_hash($postData['password'], PASSWORD_BCRYPT); } - $user->save(); - + + Session::set('user', [ 'id' => $user->getId(), 'name' => $user->name, diff --git a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php index baa5589..471ea25 100644 --- a/app/src/app/Views/Admin/AccountConfig/AccountConfig.php +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -1,9 +1,22 @@ + + +

Configuración

Aquí podrás configurar tu cuenta.

Informacíon personal

+ + + +
@@ -75,35 +88,35 @@ class="mt-1 px-3 py-2 border rounded-md text-gray-600 bg-gray-100 cursor-not-all

Cambiar contraseña

-
-
- - -
-
- - -
-
- - -
+ +
+ +
+
+ + +
+
+ + +
+ From bd320f93eddf067b710e553868c2a5ee10cfb74b Mon Sep 17 00:00:00 2001 From: elbacalau Date: Wed, 18 Dec 2024 18:47:17 +0100 Subject: [PATCH 10/10] revert: update .editorconfig --- .editorconfig | 59 --------------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/.editorconfig b/.editorconfig index d217514..20041cb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,62 +16,3 @@ indent_size = 2 [docker-compose.yml] indent_size = 2 -[*] -cpp_indent_braces=false -cpp_indent_multi_line_relative_to=innermost_parenthesis -cpp_indent_within_parentheses=indent -cpp_indent_preserve_within_parentheses=false -cpp_indent_case_labels=false -cpp_indent_case_contents=true -cpp_indent_case_contents_when_block=false -cpp_indent_lambda_braces_when_parameter=true -cpp_indent_goto_labels=one_left -cpp_indent_preprocessor=leftmost_column -cpp_indent_access_specifiers=false -cpp_indent_namespace_contents=true -cpp_indent_preserve_comments=false -cpp_new_line_before_open_brace_namespace=ignore -cpp_new_line_before_open_brace_type=ignore -cpp_new_line_before_open_brace_function=ignore -cpp_new_line_before_open_brace_block=ignore -cpp_new_line_before_open_brace_lambda=ignore -cpp_new_line_scope_braces_on_separate_lines=false -cpp_new_line_close_brace_same_line_empty_type=false -cpp_new_line_close_brace_same_line_empty_function=false -cpp_new_line_before_catch=true -cpp_new_line_before_else=true -cpp_new_line_before_while_in_do_while=false -cpp_space_before_function_open_parenthesis=remove -cpp_space_within_parameter_list_parentheses=false -cpp_space_between_empty_parameter_list_parentheses=false -cpp_space_after_keywords_in_control_flow_statements=true -cpp_space_within_control_flow_statement_parentheses=false -cpp_space_before_lambda_open_parenthesis=false -cpp_space_within_cast_parentheses=false -cpp_space_after_cast_close_parenthesis=false -cpp_space_within_expression_parentheses=false -cpp_space_before_block_open_brace=true -cpp_space_between_empty_braces=false -cpp_space_before_initializer_list_open_brace=false -cpp_space_within_initializer_list_braces=true -cpp_space_preserve_in_initializer_list=true -cpp_space_before_open_square_bracket=false -cpp_space_within_square_brackets=false -cpp_space_before_empty_square_brackets=false -cpp_space_between_empty_square_brackets=false -cpp_space_group_square_brackets=true -cpp_space_within_lambda_brackets=false -cpp_space_between_empty_lambda_brackets=false -cpp_space_before_comma=false -cpp_space_after_comma=true -cpp_space_remove_around_member_operators=true -cpp_space_before_inheritance_colon=true -cpp_space_before_constructor_colon=true -cpp_space_remove_before_semicolon=true -cpp_space_after_semicolon=false -cpp_space_remove_around_unary_operator=true -cpp_space_around_binary_operator=insert -cpp_space_around_assignment_operator=insert -cpp_space_pointer_reference_alignment=left -cpp_space_around_ternary_operator=insert -cpp_wrap_preserve_blocks=one_liners