sails-hook-sanpassport
v3.0.0
Published
Passport hook for Sails
Downloads
3
Readme
sails-hook-sanpassport
About
Before use this hook you need to read sanpassport settings.
Use
Install
$ npm install sails-hook-sanpassport
Create config/passport.js
module.exports.passport = {
model: "user",
//optional
strategyFun: null,
//optional
ensureAuthenticated: null
}
Model settings
module.exports = {
attributes: {
username: {
type: 'string',
unique : true,
required : true
},
password: {
type: 'string',
minLength: 8,
required : true
},
comparePassword: function(candidatePassword, cb) {
cb(null,true);
}
},
};
AuthController options
module.exports = {
login: function(req, res){
//
},
logout: function(req, res){
//
},
signup: function(req, res){
var jsonBody = req.body;
sanpassport.createUser(jsonBody, function(err, user){
if(err || !user){
res.send(404);
}else{
res.send(200);
}
});
}
}
Policies settings
module.exports.policies = {
UserController: {
'*': ['sessionAuth']
},
AuthController: {
login: ['login'],
logout: ['logout']
}
};
Routes options
module.exports.routes = {
'/': [{policy: "sessionAuth"},{
view: 'homepage',
locals: {
layout: 'layout'
}
}],
'post /login': "AuthController.login",
'post /logout': "AuthController.logout",
'post /signup': "AuthController.signup"
};