diff --git a/app/src/app/Controllers/Admin/AccountController.php b/app/src/app/Controllers/Admin/AccountController.php new file mode 100644 index 0000000..a90d862 --- /dev/null +++ b/app/src/app/Controllers/Admin/AccountController.php @@ -0,0 +1,83 @@ + 'Admin/AccountConfig/AccountConfig', + 'title' => 'Configuración de cuenta', + 'layout' => 'Admin/AdminLayout', + 'data' => [ + 'user' => $user + ] + ]); + } + + + public function update($id, $postData) + { + $user = User::find(id: $id); + + if (!$user) { + Session::set('error', 'Usuario no encontrado'); + header('Location: /admin/configuration'); + exit; + } + + // save the new data + $user->name = $postData['name']; + $user->surname = $postData['surname']; + + // detect password changes + 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, + 'surname' => $user->surname, + 'email' => $user->email, + 'role' => $user->role, + ]); + + Session::set('success', 'Usuario y/o contraseña actualizados correctamente'); + header('Location: /admin/configuration'); + } +} 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 17d006b..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 new file mode 100644 index 0000000..471ea25 --- /dev/null +++ b/app/src/app/Views/Admin/AccountConfig/AccountConfig.php @@ -0,0 +1,135 @@ + + + +
+

Configuración

+

Aquí podrás configurar tu cuenta.

+
+

Informacíon 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..800fd42 100644 --- a/app/src/public/assets/js/app.js +++ b/app/src/public/assets/js/app.js @@ -379,3 +379,44 @@ 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", + "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" + ); + } +} diff --git a/app/src/routes/admin.php b/app/src/routes/admin.php index d51f75d..4384543 100644 --- a/app/src/routes/admin.php +++ b/app/src/routes/admin.php @@ -1,5 +1,6 @@ 'index', 'middlewares' => [AdminMiddleware::class], ], + '/admin/configuration' => [ + 'controller' => AccountController::class, + 'method' => 'index', + 'middlewares' => [AdminMiddleware::class], + ], // === Users GET Routes '/admin/users' => [ 'controller' => UserController::class, @@ -296,5 +302,13 @@ 'method' => 'update', 'middlewares' => [AdminMiddleware::class], ], + + // === Config POST Routes + + '/admin/configuration/:id/update' => [ + 'controller' => AccountController::class, + 'method' => 'update', + 'middlewares' => [AdminMiddleware::class], + ], ], ];