Created
February 26, 2013 18:18
-
-
Save mikermcneil/5040752 to your computer and use it in GitHub Desktop.
Simplistic login example for Sails
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
/*--------------------- | |
:: Session | |
-> controller | |
---------------------*/ | |
var SessionController = { | |
login: function(req, res) { | |
// Get password and username from request | |
var username = req.param('username'); | |
var password = req.param('password'); | |
// No username/password entered | |
if(!(username && password)) { | |
res.send("No username or password specified!",500); | |
// TODO: redirect, storing an error in the session | |
} | |
else { | |
// Lookup the username/password combination | |
User.find({ | |
username: username, | |
password: password // TODO: hash the password first | |
}).done(function (err, user) { | |
// Login failed, incorrect username/password combination | |
if (err || !user) { | |
res.send("Invalid username and password combination!",500); | |
// TODO: redirect, storing an error in the session | |
} | |
// Login succeeded | |
if (user) { | |
req.session.authenticated = true; | |
req.session.User = user; | |
// Redirect to protected area | |
res.redirect('/dashboard'); | |
} | |
}); | |
} | |
} | |
}; | |
module.exports = SessionController; |
Hi @mikermcneil i agree with @frontpage can you include all file to support for this gits ?
and i think you have to create some sample apps using Sails so the beginner with nodeJs can learn fast sails.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be great if you included the code that is along side this, like the policies, model, routes anything. Sure it's a great starting point but for a beginner it leaves for a lot of guessing.
Thanks for the example either way.