Created
July 7, 2018 15:54
-
-
Save thihenos/a3db47d5c7e982ed25065154c822772f to your computer and use it in GitHub Desktop.
This file contains 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
// Using Passport for local strategy | |
passport.use('local-login', new LocalStrategy ({ | |
//In this part, passport will use' the input in HTML, by using it's name for the strategy | |
usernameField : 'login', | |
passwordField : 'password' | |
,passReqToCallback : true},function (req,login,password,done){ | |
//Querying on database to find the user by the email or the login | |
db.User.find({ where: { username: req.body.login }}).then(function(result) { | |
//Verify if the query returns a result | |
if(result){ | |
console.log('Login OK'); | |
//finishing the by sereliazing user object attributes | |
done(null,result); | |
} else { | |
console.log('Login ou senha errado'); | |
done(null,false,{message : 'Username or password are wrong :('}); | |
} | |
}); | |
}//Fim função de procura do usuario | |
));//Fim passport |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment