Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added register-admin route, reading json data from body #80

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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