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 Forget Password #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions controllers/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a condition to check password as well, this way you are not authenticating the user

[email]
);
if (rows.length === 0) throw Error("Email not registered");
await pool.query(
"UPDATE admin SET password = $1 WHERE email = $2 ",[password,email]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant set a password like this directly, will need encryption, check the register-user logic

);
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;
Expand Down
1 change: 1 addition & 0 deletions router/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down