Skip to content

Commit

Permalink
Added register-admin route, readin json data from body
Browse files Browse the repository at this point in the history
  • Loading branch information
dhananjaysingh10 committed May 14, 2024
1 parent 41a5336 commit 006a6b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
30 changes: 25 additions & 5 deletions routers/adminRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 006a6b4

Please sign in to comment.