Removed In dev Pro editor
This commit is contained in:
1 parent
43f662982e
commit
877ad3c8d0
3 files changed
-141
No files matched your search
@@ -30,76 +30,6 @@ router.get('/register', forwardAuthenticated, (req, res) => res.render('register
|
||||
// Edit page
|
||||
router.get('/edit', (req, res) => res.render('edit'));
|
||||
|
||||
// Edit
|
||||
router.post('/edit', (req, res) => {
|
||||
const { user, name, email, oldPassword, newPassword, newPassword2 } = req.body;
|
||||
let errors = [];
|
||||
|
||||
if (!name || !email || !oldPassword || !newPassword || !newPassword2) {
|
||||
errors.push({ msg: 'Please enter all fields' });
|
||||
}
|
||||
|
||||
if (oldPassword != user.password) {
|
||||
errors.push({ msg: 'Password is incorrect' });
|
||||
}
|
||||
|
||||
if (newPassword != newPassword2) {
|
||||
errors.push({ msg: 'New password doesnt match' });
|
||||
}
|
||||
|
||||
if (oldPassword == newPassword) {
|
||||
errors.push({ msg: 'Cant use the same password' })
|
||||
}
|
||||
|
||||
if (newPassword.length < 6) {
|
||||
errors.push({ msg: 'Password must be at least 6 characters' });
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
res.render('register', {
|
||||
errors,
|
||||
name,
|
||||
email,
|
||||
oldPassword,
|
||||
newPassword2,
|
||||
newPassword2
|
||||
});
|
||||
} else {
|
||||
User.findOne({ email: email }).then(user => {
|
||||
if (user) {
|
||||
errors.push({ msg: 'Email already exists' });
|
||||
res.render('register', {
|
||||
errors,
|
||||
name,
|
||||
email,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
newPassword2
|
||||
});
|
||||
} else {
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
bcrypt.hash(newPassword, salt, (err, hash) => {
|
||||
if (err) throw err;
|
||||
user.password = hash;
|
||||
user.name = name;
|
||||
user.email = email;
|
||||
user
|
||||
.save()
|
||||
.then(user => {
|
||||
req.flash(
|
||||
'success_msg',
|
||||
'You are now registered and can log in'
|
||||
);
|
||||
res.redirect('/users/login');
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Register
|
||||
router.post('/register', upload.single('image'), (req, res, next) => {
|
||||
const { name, email, password, password2 } = req.body;
|
||||
|
||||
Reference in new issue
Block a user