diff --git a/client/src/Pages/Account/components/ChangePasswordModal/index.jsx b/client/src/Pages/Account/components/ChangePasswordModal/index.jsx
index 375595b29..17984c3ae 100644
--- a/client/src/Pages/Account/components/ChangePasswordModal/index.jsx
+++ b/client/src/Pages/Account/components/ChangePasswordModal/index.jsx
@@ -1,20 +1,20 @@
import { useState } from "react";
import { Button, Stack } from "@mui/material";
-import { GenericDialog } from "../../../../Components/Dialog/genericDialog";
-import TextInput from "../../../../Components/Inputs/TextInput";
-import PasswordTooltip from "../../../Auth/components/PasswordTooltip";
+import { GenericDialog } from "@/Components/v1/Dialog/genericDialog";
+import TextInput from "@/Components/v1/Inputs/TextInput";
+import PasswordTooltip from "@/Pages/v1/Auth/components/PasswordTooltip";
import { useTheme } from "@emotion/react";
import { useTranslation } from "react-i18next";
import { createToast } from "../../../../Utils/toastUtils";
-import { PasswordEndAdornment } from "../../../../Components/Inputs/TextInput/Adornments";
-import usePasswordFeedback from "../../../Auth/hooks/usePasswordFeedback";
+import { PasswordEndAdornment } from "@/Components/v1/Inputs/TextInput/Adornments";
+import usePasswordFeedback from "@/Pages/v1/Auth/hooks/usePasswordFeedback";
+import PropTypes from "prop-types";
-const ChangePasswordModal = ({ isSaving, isLoading, userId, changePassword, email }) => {
+const ChangePasswordModal = ({ isSaving, isLoading, changePassword, email }) => {
const INITIAL_FORM_STATE = {
password: "",
confirm: "",
};
- console.log("email", email);
const theme = useTheme();
const { t } = useTranslation();
const { feedback, handlePasswordFeedback } = usePasswordFeedback();
@@ -30,7 +30,6 @@ const ChangePasswordModal = ({ isSaving, isLoading, userId, changePassword, emai
const onChange = (e) => {
let { name, value } = e.target;
const updatedForm = { ...form, [name]: value };
- //validateFields(name, value, updatedForm);
setForm(updatedForm);
handlePasswordFeedback(updatedForm, name, value, form, errors, setErrors);
@@ -130,11 +129,19 @@ const ChangePasswordModal = ({ isSaving, isLoading, userId, changePassword, emai
onClick={onsubmitChangePassword}
disabled={isLoadingSubmit || !isFormValid}
>
- Save
+ {t("save")}
>
);
};
+
+ChangePasswordModal.propTypes = {
+ isSaving: PropTypes.bool.isRequired,
+ isLoading: PropTypes.bool.isRequired,
+ changePassword: PropTypes.func.isRequired,
+ email: PropTypes.string.isRequired,
+};
+
export default ChangePasswordModal;
diff --git a/client/src/Pages/v1/Account/EditUser/index.jsx b/client/src/Pages/v1/Account/EditUser/index.jsx
index 9fe307cf2..e11716683 100644
--- a/client/src/Pages/v1/Account/EditUser/index.jsx
+++ b/client/src/Pages/v1/Account/EditUser/index.jsx
@@ -7,8 +7,7 @@ import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
import Search from "@/Components/v1/Inputs/Search/index.jsx";
import Button from "@mui/material/Button";
import RoleTable from "../components/RoleTable/index.jsx";
-import ChangePasswordModal from "../components/ChangePasswordModal";
-
+import ChangePasswordModal from "@/Pages/Account/components/ChangePasswordModal/index.jsx";
// Utils
import { useParams } from "react-router-dom";
import { useTheme } from "@emotion/react";
@@ -16,9 +15,12 @@ import { useTranslation } from "react-i18next";
import { useGetUser, useEditUser } from "../../../../Hooks/v1/userHooks.js";
import { EDITABLE_ROLES, ROLES } from "../../../../Utils/roleUtils.js";
import { useEditUserForm, useValidateEditUserForm } from "./hooks/editUser.js";
+import { useSelector } from "react-redux";
const EditUser = () => {
+ const { user } = useSelector((state) => state.auth);
const { userId } = useParams();
+ const isSameUser = user?._id === userId;
const theme = useTheme();
const { t } = useTranslation();
const BREADCRUMBS = [
@@ -26,7 +28,7 @@ const EditUser = () => {
{ name: t("editUserPage.title"), path: "" },
];
- const [user, isLoading, error] = useGetUser(userId);
+ const [userToEdit, isLoading, error] = useGetUser(userId);
const [editUser, isSaving, saveError, changePassword] = useEditUser(userId);
const [
form,
@@ -35,7 +37,7 @@ const EditUser = () => {
handleDeleteRole,
searchInput,
handleSearchInput,
- ] = useEditUserForm(user);
+ ] = useEditUserForm(userToEdit);
const [errors, validateForm, validateField] = useValidateEditUserForm();
const onChange = (e) => {
@@ -119,13 +121,14 @@ const EditUser = () => {
>
{t("editUserPage.form.save")}
-
+ {!isSameUser && (
+
+ )}
diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js
index 7401994bb..6372be646 100644
--- a/client/src/Utils/NetworkService.js
+++ b/client/src/Utils/NetworkService.js
@@ -1139,7 +1139,6 @@ class NetworkService {
async changePasswordByAdmin(config) {
const { userId, passwordForm } = config;
- console.log("Password form data:", passwordForm);
return this.axiosInstance.put(`auth/users/${userId}/password`, passwordForm, {
headers: {
"Content-Type": "application/json",
diff --git a/server/src/controllers/v1/authController.js b/server/src/controllers/v1/authController.js
index b84aaacd6..600c6730f 100755
--- a/server/src/controllers/v1/authController.js
+++ b/server/src/controllers/v1/authController.js
@@ -10,10 +10,12 @@ import {
editUserByIdParamValidation,
editUserByIdBodyValidation,
editSuperadminUserByIdBodyValidation,
+ editUserPasswordByIdBodyValidation,
} from "../../validation/joi.js";
+import ErrorService from "../../service/v1/infrastructure/errorService.js";
const SERVICE_NAME = "authController";
-
+const errorService = new ErrorService();
/**
* Authentication Controller
*
@@ -436,7 +438,7 @@ class AuthController extends BaseController {
async (req, res) => {
const roles = req?.user?.role;
if (!roles.includes("superadmin")) {
- throw createError("Unauthorized", 403);
+ throw errorService.createError("Unauthorized", 403);
}
const userId = req.params.userId;
@@ -456,29 +458,24 @@ class AuthController extends BaseController {
SERVICE_NAME,
"editUserById"
);
- editUserPasswordById = this.asyncHandler(
- async (req, res) => {
- console.log("editUserPasswordById called");
- const roles = req?.user?.role;
- if (!roles.includes("superadmin")) {
- console.log("entro a error editUserPasswordById");
- throw createError("Unauthorized", 403);
- }
-
- const userId = req.params.userId;
- console.log("userId param:", userId);
- const updates = { ...req.body };
- console.log("newPassword body:", req.body);
- await editUserByIdParamValidation.validateAsync(req.params);
- console.log("params validated");
- //await editUserPasswordByIdBodyValidation.validateAsync(req.body);
- console.log("body validated");
- await this.userService.setPasswordByUserId( userId, updates );
- return res.success({ msg: "Password reset successfully" });
- },
- SERVICE_NAME, "editUserPasswordById"
- )
+ editUserPasswordById = this.asyncHandler(
+ async (req, res) => {
+ const roles = req?.user?.role;
+ if (!roles.includes("superadmin")) {
+ throw errorService.createError("Unauthorized", 403);
+ }
+ const userId = req.params.userId;
+ const updates = { ...req.body };
+ console.log("body", req.body);
+ await editUserByIdParamValidation.validateAsync(req.params);
+ await editUserPasswordByIdBodyValidation.validateAsync(req.body);
+ await this.userService.setPasswordByUserId(userId, updates);
+ return res.success({ msg: "Password reset successfully" });
+ },
+ SERVICE_NAME,
+ "editUserPasswordById"
+ );
}
export default AuthController;
diff --git a/server/src/service/v1/business/userService.js b/server/src/service/v1/business/userService.js
index 6c036a5c8..c81d9135e 100644
--- a/server/src/service/v1/business/userService.js
+++ b/server/src/service/v1/business/userService.js
@@ -214,7 +214,6 @@ class UserService {
setPasswordByUserId = async (userId, updates) => {
const updatedUser = await this.db.userModule.updateUser({ userId: userId, user: updates, file: null });
return updatedUser;
- }
-
+ };
}
export default UserService;
diff --git a/server/src/validation/joi.js b/server/src/validation/joi.js
index 209135769..4005e2ebe 100755
--- a/server/src/validation/joi.js
+++ b/server/src/validation/joi.js
@@ -671,7 +671,9 @@ const editSuperadminUserByIdBodyValidation = joi.object({
});
const editUserPasswordByIdBodyValidation = joi.object({
+ email: joi.string().required(),
newPassword: joi.string().min(8).required().pattern(passwordPattern),
+ password: joi.string().min(8).required().pattern(passwordPattern),
});
export {