From 9c6c7df92b0628bd4fddd1fc61aaa04c06021ba3 Mon Sep 17 00:00:00 2001 From: Wingy Date: Wed, 15 Sep 2021 02:51:58 -0400 Subject: [PATCH] remove excess logging --- routes/profile/index.js | 56 ++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/routes/profile/index.js b/routes/profile/index.js index 4f8d0b7..0f08457 100644 --- a/routes/profile/index.js +++ b/routes/profile/index.js @@ -16,33 +16,37 @@ module.exports = ({ db, ensurePfp }) => { req.flash('success', 'Saved profile picture!') res.redirect(`${_CC.config.base}profile`) }) - router.post('/', verifyAuth(), (req, res) => { - if (req.body.oldPassword && req.body.newPassword) { - bcrypt.compare(req.body.oldPassword, req.user.password, (err, correct) => { - if (err) throw err - if (correct) { - bcrypt.hash(req.body.newPassword, null, null, (err, hash) => { - if (err) throw err - db.get(req.user._id) - .then(doc => { - doc.password = hash - db.put(doc) - .then(() => { - req.flash('success', 'Changes saved successfully!') - res.redirect('/profile') - }) - .catch(err => { throw err }) - }) - .catch(err => { throw err }) - }) - } else { - req.flash('error', 'Incorrect old password') - res.redirect('/profile') - } - }) - } else { - res.redirect('/profile') + router.post('/password', verifyAuth(), (req, res) => { + if (!req.body.oldPassword) { + req.flash('error', 'Old Password is required') + return res.redirect('/profile/password') } + if (!req.body.newPassword) { + req.flash('error', 'New Password is required') + return res.redirect('/profile/password') + } + bcrypt.compare(req.body.oldPassword, req.user.password, (err, correct) => { + if (err) throw err + if (correct) { + bcrypt.hash(req.body.newPassword, null, null, (err, hash) => { + if (err) throw err + db.get(req.user._id) + .then(doc => { + doc.password = hash + db.put(doc) + .then(() => { + req.flash('success', 'Changes saved successfully!') + res.redirect('/profile/password') + }) + .catch(err => { throw err }) + }) + .catch(err => { throw err }) + }) + } else { + req.flash('error', 'Incorrect old password') + res.redirect('/profile/password') + } + }) }) return router