diff --git a/app.js b/app.js index ae001f2..9a8b325 100644 --- a/app.js +++ b/app.js @@ -15,6 +15,7 @@ const flash = require('express-flash'); const Admin=require("./model/admin") app.use(bodyParser.urlencoded({ extended: true })); +app.use(bodyParser.json()); app.use(express.static("public")); const NGO=require("./model/ngo") diff --git a/routers/adminRoutes.js b/routers/adminRoutes.js index 0236ad6..bb4bf56 100644 --- a/routers/adminRoutes.js +++ b/routers/adminRoutes.js @@ -12,19 +12,39 @@ const Query = require("../model/query"); // Adjust the path based on your projec const problem=require("../model/query") -const {transporter}=require("../helpers/emailHelpers") - +const {transporter}=require("../helpers/emailHelpers") -const ad = Admin({username:"sahilkaitha@gmail.com",password:"123",fullName:"Sahil Hossain",Mobile:"9635955320"}) -ad.save() +router.post("/register-admin", async (req, res) => { + // Dummy data for admin + // { + // "username": "sahilkaitha@gmail.com", + // "password": "123", + // "fullName": "Sahil Hossain", + // "Mobile": "9635955320" + // } + try { + const admin = await Admin.findOne({ username: req.body.username }); + if (admin) { + res.status(302).send("Already have an account, Please Login "); + } else { + const { username, password, fullName, mobile } = req.body; + const hashedPassword = await bcrypt.hash(password, saltRounds); + const admin = new Admin({ username, password: hashedPassword, fullName, mobile }); + await admin.save(); + res.status(201).send("Admin registered successfully"); + } + } catch (error) { + console.error(error); + res.status(500).send(error,"An error occurred while registering the admin"); + } +}); router.post("/admin-login", async (req, res) => { const username = req.body.username; const password = req.body.password; - const admin = await Admin.findOne({ username: username, password: password }); console.log(admin); try {