add password change functionality with frontend integration

This commit is contained in:
2025-09-03 14:50:35 +02:00
parent a24b2697b0
commit 68f13f369c
4 changed files with 72 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ import {
deleteItemID,
createItem,
changeUserPassword,
changeUserPasswordFRONTEND,
} from "../services/database.js";
import { authenticate, generateToken } from "../services/tokenService.js";
const router = express.Router();
@@ -176,6 +177,21 @@ router.post("/createLoan", authenticate, async (req, res) => {
}
});
router.post("/changePassword", authenticate, async (req, res) => {
const { oldPassword, newPassword } = req.body || {};
const username = req.user.username;
const result = await changeUserPasswordFRONTEND(
username,
oldPassword,
newPassword
);
if (result.success) {
res.status(200).json({ message: "Password changed successfully" });
} else {
res.status(500).json({ message: "Failed to change password" });
}
});
// Admin panel functions
router.post("/loginAdmin", async (req, res) => {