Skip to content

Instantly share code, notes, and snippets.

@marcbachmann
Last active December 15, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcbachmann/5331318 to your computer and use it in GitHub Desktop.
Save marcbachmann/5331318 to your computer and use it in GitHub Desktop.
Login function with express-validator
function postLogin(req, res, next){
req.assert('username', 'username is required').notEmpty();
req.assert('password', 'password is required').notEmpty();
var username = (req.body.username)? req.body.username: '';
var password = (req.body.password)? req.body.password: '';
var errors = req.validationErrors(true);
if (errors) {
res.render('login.jade', {locals: { title: 'Login Error', username: username, password: password, errors: errors}});
return;
};
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err) }
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment