adjusted new backend with new routes

This commit is contained in:
2025-11-17 21:37:29 +01:00
parent 757e13efe4
commit 3a03457f5a
5 changed files with 443 additions and 2 deletions

View File

@@ -5,7 +5,7 @@ import dotenv from "dotenv";
dotenv.config();
// database funcs import
import { loginFunc } from "./database/userMgmt.database.js";
import { loginFunc, changePassword } from "./database/userMgmt.database.js";
router.post("/login", async (req, res) => {
const result = await loginFunc(req.body.username, req.body.password);
@@ -20,4 +20,16 @@ router.post("/login", async (req, res) => {
}
});
router.post("/change-password", authenticate, async (req, res) => {
const oldPassword = req.body.oldPassword;
const newPassword = req.body.newPassword;
const username = req.user.username;
const result = await changePassword(username, oldPassword, newPassword);
if (result.success) {
res.status(200).json({ message: "Password changed successfully" });
} else {
res.status(500).json({ message: "Failed to change password" });
}
});
export default router;