Last active
December 15, 2015 22:09
-
-
Save marcbachmann/5331318 to your computer and use it in GitHub Desktop.
Login function with express-validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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