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 @@
Aquí podrás configurar tu cuenta.
-