added function to change user password with the admin panel

This commit is contained in:
2025-09-03 14:10:42 +02:00
parent 423075e746
commit b8f13a37fd
5 changed files with 163 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ import {
getAllItems,
deleteItemID,
createItem,
changeUserPassword,
} from "../services/database.js";
import { authenticate, generateToken } from "../services/tokenService.js";
const router = express.Router();
@@ -276,4 +277,17 @@ router.post("/createItem", authenticate, async (req, res) => {
return res.status(500).json({ message: "Failed to create item" });
});
router.post("/changePWadmin", authenticate, async (req, res) => {
const newPassword = req.body.newPassword;
if (!newPassword) {
return res.status(400).json({ message: "New password is required" });
}
const result = await changeUserPassword(req.body.username, newPassword);
if (result.success) {
return res.status(200).json({ message: "Password changed successfully" });
}
return res.status(500).json({ message: "Failed to change password" });
});
export default router;