54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
/**
|
|
* 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) {
|
|
console.log('create');
|
|
passport.authenticate('local', function(err, user, info) {
|
|
if(err || !user) {
|
|
return res.json(403, { message: "Incorrect username or password." });
|
|
}
|
|
req.logIn(user, function(err) {
|
|
if (err) {
|
|
return res.json(403, { message: "Incorrect username or password." });
|
|
}
|
|
return res.json(201, { message: "Session created." });
|
|
});
|
|
})(req, res);
|
|
},
|
|
|
|
destroy: function(req, res) {
|
|
req.logout();
|
|
res.json({ message: "Successfully logged out." });
|
|
},
|
|
|
|
/**
|
|
* Overrides for the settings in `config/controllers.js`
|
|
* (specific to SessionController)
|
|
*/
|
|
_config: {
|
|
blueprints: {
|
|
shortcuts: false,
|
|
rest: false
|
|
}
|
|
}
|
|
|
|
|
|
};
|