shell bypass 403
const express = require('express');
const router = express.Router();
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const JWT_SECRET = "l!TtLeGr()O//En";
const Adminpanel = require('../../schema/Admin-panel')
router.post('/register', async (req, res) => {
try {
const { name, email, password } = req.body
console.log('body', req.body)
if (name && email && password) {
const checkTeacher = await Adminpanel.findOne({ email })
if (checkTeacher) {
return res.redirect("/sites/little-groovin-guitar/admin-panel/login?error=Email Address Already Used...")
}
const salt = await bcrypt.genSalt(10)
const hashPassword = await bcrypt.hash(password, salt)
const newTeacher = await Adminpanel.create({ name, email, password: hashPassword })
const fetchTeacher = await Adminpanel.findOne({ email })
const { _id } = fetchTeacher
const teacher = {
id: _id, name, email
}
const authtoken = jwt.sign(teacher, JWT_SECRET);
return res.status(200).cookie('authtoken', authtoken).redirect("/sites/little-groovin-guitar/admin-panel?message=admin-panel Registered Successfully...")
}
else {
console.log(req.body)
return res.redirect("/sites/little-groovin-guitar/admin-panel/login?error=Invalid Form Data...")
}
}
catch (err) {
console.log(err);
console.log(err.message);
return res.redirect("/sites/little-groovin-guitar/admin-panel/login?error=" + err.message)
}
})
router.post('/login', async (req, res) => {
try {
const { email, password } = req.body
console.log({ email, password })
// return
const checkTeacher = await Adminpanel.findOne({ email })
if (checkTeacher) {
const passwordCompare = await bcrypt.compare(password, checkTeacher.password);
if (passwordCompare) {
const { _id, email} = checkTeacher
const teacher = {
id: _id, email
}
const authtoken = jwt.sign(teacher, JWT_SECRET);
console.log(authtoken)
return res.status(200).cookie('authtoken', authtoken).redirect("/sites/little-groovin-guitar/admin-panel" + '?message=admin-panel Logged In Successfully...')
}
else {
console.log("Invalid Password")
return res.status(422).redirect("/sites/little-groovin-guitar/admin-panel/login" + '?error="Invalid Credentials')
}
}
else {
console.log("Invalid Email")
return res.status(422).redirect("/sites/little-groovin-guitar/admin-panel/login" + '?error="Invalid Credentials')
}
}
catch (err) {
console.log(err.message);
return res.status(422).redirect("/sites/little-groovin-guitar/admin-panel/login?error=" + err.message)
}
})
router.get('/logout', async (req, res) => {
res.clearCookie('authtoken')
return res.status(200).redirect('/sites/little-groovin-guitar/?message=Teacher Logged Out...')
})
router.get("/register" , (req, res) =>{
return res.render("admin-panel/register")
})
module.exports = router