added function to change user password with the admin panel
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user