remove excess logging
This commit is contained in:
parent
9f24b54e47
commit
9c6c7df92b
1 changed files with 30 additions and 26 deletions
|
@ -16,33 +16,37 @@ module.exports = ({ db, ensurePfp }) => {
|
||||||
req.flash('success', 'Saved profile picture!')
|
req.flash('success', 'Saved profile picture!')
|
||||||
res.redirect(`${_CC.config.base}profile`)
|
res.redirect(`${_CC.config.base}profile`)
|
||||||
})
|
})
|
||||||
router.post('/', verifyAuth(), (req, res) => {
|
router.post('/password', verifyAuth(), (req, res) => {
|
||||||
if (req.body.oldPassword && req.body.newPassword) {
|
if (!req.body.oldPassword) {
|
||||||
bcrypt.compare(req.body.oldPassword, req.user.password, (err, correct) => {
|
req.flash('error', 'Old Password is required')
|
||||||
if (err) throw err
|
return res.redirect('/profile/password')
|
||||||
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')
|
|
||||||
}
|
}
|
||||||
|
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
|
return router
|
||||||
|
|
Loading…
Reference in a new issue