add eslint, fix bugs found
This commit is contained in:
parent
fc2c3a7114
commit
12558d3384
28 changed files with 1774 additions and 745 deletions
|
@ -1,39 +1,39 @@
|
|||
const verifyAuth = require('../../middlewares/verifyAuth');
|
||||
const bcrypt = require('bcrypt-nodejs');
|
||||
const express = require('express');
|
||||
const verifyAuth = require('../../middlewares/verifyAuth')
|
||||
const bcrypt = require('bcrypt-nodejs')
|
||||
const express = require('express')
|
||||
|
||||
module.exports = (db) => {
|
||||
const router = express.Router();
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', verifyAuth(), (req, res) => res.render('profile', { title: `Profile Settings - ${req.user._id}`}));
|
||||
router.get('/', verifyAuth(), (req, res) => res.render('profile', { title: `Profile Settings - ${req.user._id}` }))
|
||||
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 (err) throw err
|
||||
if (correct) {
|
||||
bcrypt.hash(req.body.newPassword, null, null, (err, hash) => {
|
||||
if (err) throw err;
|
||||
if (err) throw err
|
||||
db.get(req.user._id)
|
||||
.then(doc => {
|
||||
doc.password = hash;
|
||||
doc.password = hash
|
||||
db.put(doc)
|
||||
.then(() => {
|
||||
req.flash('success', 'Changes saved successfully!');
|
||||
res.redirect('/profile');
|
||||
req.flash('success', 'Changes saved successfully!')
|
||||
res.redirect('/profile')
|
||||
})
|
||||
.catch(err => { throw err; });
|
||||
.catch(err => { throw err })
|
||||
})
|
||||
.catch(err => { throw err; });
|
||||
});
|
||||
.catch(err => { throw err })
|
||||
})
|
||||
} else {
|
||||
req.flash('error', 'Incorrect old password');
|
||||
res.redirect('/profile');
|
||||
req.flash('error', 'Incorrect old password')
|
||||
res.redirect('/profile')
|
||||
}
|
||||
});
|
||||
})
|
||||
} else {
|
||||
res.redirect('/profile');
|
||||
res.redirect('/profile')
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
return router;
|
||||
};
|
||||
return router
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue