added new feature: service config; Currently implemented in: loanMgmt and userMgmt (only Backend)

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-26 14:40:53 +02:00
parent 5442f2f1f3
commit 0964109c4b
4 changed files with 279 additions and 169 deletions
+47 -32
View File
@@ -1,5 +1,6 @@
import express from "express";
import { authenticate, generateToken } from "../../services/authentication.js";
import { checkIfServiceIsActive } from "../../services/functions.js";
const router = express.Router();
import dotenv from "dotenv";
dotenv.config();
@@ -8,41 +9,55 @@ dotenv.config();
import { loginFunc, changePassword } from "./database/userMgmt.database.js";
import { sendMail } from "./services/mailer_v2.js";
router.post("/login", async (req, res) => {
const result = await loginFunc(req.body.username, req.body.password);
if (result.success) {
const token = await generateToken({
username: result.data.username,
is_admin: result.data.is_admin,
first_name: result.data.first_name,
last_name: result.data.last_name,
role: result.data.role,
});
res.status(200).json({ message: "Login successful", token });
} else {
res.status(401).json({ message: "Invalid credentials" });
}
});
router.post(
"/login",
checkIfServiceIsActive("User Frontend"),
async (req, res) => {
const result = await loginFunc(req.body.username, req.body.password);
if (result.success) {
const token = await generateToken({
username: result.data.username,
is_admin: result.data.is_admin,
first_name: result.data.first_name,
last_name: result.data.last_name,
role: result.data.role,
});
res.status(200).json({ message: "Login successful", token });
} else {
res.status(401).json({ message: "Invalid credentials" });
}
},
);
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" });
}
});
router.post(
"/change-password",
checkIfServiceIsActive("User Frontend"),
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" });
}
},
);
router.post("/contact", authenticate, async (req, res) => {
const message = req.body.message;
const username = req.user.username;
router.post(
"/contact",
checkIfServiceIsActive("Contact Form Service"),
authenticate,
async (req, res) => {
const message = req.body.message;
const username = req.user.username;
sendMail(username, message);
sendMail(username, message);
res.status(200).json({ message: "Contact message sent successfully" });
});
res.status(200).json({ message: "Contact message sent successfully" });
},
);
export default router;