Update flash notifications on login, profile, signup pages to work with new express-flash
This commit is contained in:
@ -11,34 +11,7 @@ var User = require('../models/User');
|
|||||||
exports.getLogin = function(req, res) {
|
exports.getLogin = function(req, res) {
|
||||||
if (req.user) return res.redirect('/');
|
if (req.user) return res.redirect('/');
|
||||||
res.render('account/login', {
|
res.render('account/login', {
|
||||||
title: 'Login',
|
title: 'Login'
|
||||||
errors: req.flash('errors')
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GET /signup
|
|
||||||
* Signup page.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.getSignup = function(req, res) {
|
|
||||||
if (req.user) return res.redirect('/');
|
|
||||||
res.render('account/signup', {
|
|
||||||
title: 'Create Account',
|
|
||||||
errors: req.flash('errors')
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GET /account
|
|
||||||
* Profile page.
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.getAccount = function(req, res) {
|
|
||||||
res.render('account/profile', {
|
|
||||||
title: 'Account Management',
|
|
||||||
success: req.flash('success'),
|
|
||||||
error: req.flash('error')
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,6 +49,18 @@ exports.postLogin = function(req, res, next) {
|
|||||||
})(req, res, next);
|
})(req, res, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /signup
|
||||||
|
* Signup page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.getSignup = function(req, res) {
|
||||||
|
if (req.user) return res.redirect('/');
|
||||||
|
res.render('account/signup', {
|
||||||
|
title: 'Create Account'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /signup
|
* POST /signup
|
||||||
* Create a new local account.
|
* Create a new local account.
|
||||||
@ -116,11 +101,22 @@ exports.postSignup = function(req, res, next) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /account
|
||||||
|
* Profile page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.getAccount = function(req, res) {
|
||||||
|
res.render('account/profile', {
|
||||||
|
title: 'Account Management'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /account/profile
|
* POST /account/profile
|
||||||
* Update profile information.
|
* Update profile information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.postUpdateProfile = function(req, res, next) {
|
exports.postUpdateProfile = function(req, res, next) {
|
||||||
User.findById(req.user.id, function(err, user) {
|
User.findById(req.user.id, function(err, user) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
@ -133,7 +129,7 @@ exports.postUpdateProfile = function(req, res, next) {
|
|||||||
|
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
req.flash('success', 'Profile information updated.');
|
req.flash('success', { msg: 'Profile information updated.' });
|
||||||
res.redirect('/account');
|
res.redirect('/account');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -147,12 +143,12 @@ exports.postUpdateProfile = function(req, res, next) {
|
|||||||
|
|
||||||
exports.postUpdatePassword = function(req, res, next) {
|
exports.postUpdatePassword = function(req, res, next) {
|
||||||
if (!req.body.password) {
|
if (!req.body.password) {
|
||||||
req.flash('error', 'Password cannot be blank.');
|
req.flash('errors', { msg: 'Password cannot be blank.' });
|
||||||
return res.redirect('/account');
|
return res.redirect('/account');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.password !== req.body.confirmPassword) {
|
if (req.body.password !== req.body.confirmPassword) {
|
||||||
req.flash('error', 'Passwords do not match.');
|
req.flash('errors', { msg: 'Passwords do not match.' });
|
||||||
return res.redirect('/account');
|
return res.redirect('/account');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +159,7 @@ exports.postUpdatePassword = function(req, res, next) {
|
|||||||
|
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
req.flash('success', 'Password has been changed.');
|
req.flash('success', { msg: 'Password has been changed.' });
|
||||||
res.redirect('/account');
|
res.redirect('/account');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
extends ../layout
|
extends ../layout
|
||||||
|
|
||||||
block content
|
block content
|
||||||
if errors.length
|
|
||||||
.alert.alert-danger.animated.fadeIn
|
|
||||||
for error in errors
|
|
||||||
div= error.msg
|
|
||||||
|
|
||||||
.col-sm-8.col-sm-offset-2
|
.col-sm-8.col-sm-offset-2
|
||||||
form(method='POST')
|
form(method='POST')
|
||||||
legend Sign In
|
legend Sign In
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
extends ../layout
|
extends ../layout
|
||||||
|
|
||||||
block content
|
block content
|
||||||
if error.length
|
|
||||||
.alert.alert-danger.animated.fadeIn
|
|
||||||
button.close(data-dismiss='alert') ×
|
|
||||||
= error
|
|
||||||
if success.length
|
|
||||||
.alert.alert-success.animated.fadeInUp
|
|
||||||
button.close(data-dismiss='alert') ×
|
|
||||||
i.fa.fa-check
|
|
||||||
= success
|
|
||||||
|
|
||||||
.page-header
|
.page-header
|
||||||
h3 Profile Information
|
h3 Profile Information
|
||||||
|
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
extends ../layout
|
extends ../layout
|
||||||
|
|
||||||
block content
|
block content
|
||||||
if errors.length
|
|
||||||
.alert.alert-danger.animated.fadeIn
|
|
||||||
for error in errors
|
|
||||||
div= error.msg
|
|
||||||
|
|
||||||
form.form-horizontal(id='signup-form', method='POST')
|
form.form-horizontal(id='signup-form', method='POST')
|
||||||
legend Signup
|
legend Signup
|
||||||
.form-group
|
.form-group
|
||||||
|
Reference in New Issue
Block a user