Complete passport setup

This commit is contained in:
Ben Ramey
2014-06-10 19:42:23 -05:00
parent 4915ad3233
commit fc9b789ad8
4 changed files with 65 additions and 5 deletions

View File

@@ -0,0 +1,52 @@
/**
* SessionController
*
* @module :: Controller
* @description :: A set of functions called `actions`.
*
* Actions contain code telling Sails how to respond to a certain type of request.
* (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
*
* You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
* and/or override them with custom routes (`config/routes.js`)
*
* NOTE: The code you write here supports both HTTP and Socket.io automatically.
*
* @docs :: http://sailsjs.org/#!documentation/controllers
*/
var passport = require('passport');
module.exports = {
create: function(req,res) {
passport.authenticate('local', function(err, user, info) {
if(err || !user) {
res.redirect('/login');
return;
}
req.logIn(user, function(err) {
if (err) {
res.redirect('/login');
}
return res.redirect('/');
});
})(req, res);
},
destroy: function(req, res) {
req.logout();
res.send('logout successful');
},
/**
* Overrides for the settings in `config/controllers.js`
* (specific to SessionController)
*/
_config: {
blueprints: {
shortcuts: false,
rest: false
}
};

View File

@@ -11,7 +11,7 @@ module.exports = function(req, res, next) {
// User is allowed, proceed to the next policy,
// or if this is the last policy, the controller
if (req.session.authenticated) {
if (req.isAuthenticated()) {
return next();
}