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">= $_SESSION['user']['name'] . ' ' . $_SESSION['use class="hidden absolute right-0 z-10 mt-2 w-56 origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="menu-button" tabindex="-1">
Aquí podrás configurar tu cuenta.
+