diff --git a/controllers/adminController.js b/controllers/adminController.js index 0e903b8..e18ad5d 100644 --- a/controllers/adminController.js +++ b/controllers/adminController.js @@ -40,6 +40,28 @@ const controller = { res.status(400).json(error.message); } }, + + //forget + forget: async (req, res) => { + try { + const { email, password } = req.body; + if (!email || !password) throw Error("All fields are mandatory"); + const { rows } = await pool.query( + "SELECT * FROM admin WHERE email = $1", + [email] + ); + if (rows.length === 0) throw Error("Email not registered"); + await pool.query( + "UPDATE admin SET password = $1 WHERE email = $2 ",[password,email] + ); + res.json("password updated"); + } catch (error) { + console.error(error); + res.status(400).json(error.message); + } + }, + + login: async (req, res) => { try { const { email, password } = req.body; diff --git a/router/admin.js b/router/admin.js index 463b11e..4f3877a 100644 --- a/router/admin.js +++ b/router/admin.js @@ -7,6 +7,7 @@ const upload = require('../middlewares/multer') router.post('/register', adminController.register) router.post('/login', adminController.login) router.post('/logout', adminController.logout) +router.post('/forget', adminController.forget) router.get('/', authAdmin, adminController.getUser) router.post('/', upload.single('music'), authAdmin, adminController.addMusic) router.get('/uploaded', authAdmin, adminController.getUploaded)