嗨,请你能帮助我,
app.js上的我使用passport-ldapauth startegy并且有效!
...
var OPTS = {
server: {
url: 'ldap://myipldap:389',
bindDn: 'uid={{username}},O=My Company Group',
//bindCredentials: '{{req.body.password}}',
searchBase: 'O=My Company Group',
searchFilter: 'uid={{username}}'
}
};
passport.use(new LdapStrategy(OPTS));
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
app.post('/login', (req,res,next) => {
passport.authenticate('ldapauth', {
//session: false,
successRedirect:'/index',
failureRedirect:'/login',
failureFlash:true
})(req, res, next);
});
....在执行成功重定向之前我需要查询表mysql并检查用户的授权
我想我这样做,我有成功重定向到索引,我有一个导出模块调用accessoSicuro:
// accessSicuro It's exported module:
module.exports = {
accessoSicuro:function(req,res,next){
if(req.isAuthenticated()){
/*
HERE I WANT to check the mysql table and pass the returned parameter to next () method and then use the value to the middleware index
*/
return next();
}
req.flash('msg_errore','Sorry, no entry, no auth ldap');
res.redirect('/login');
}
}
app.get('/index',accessoSicuro,(req,res,next)=>{
// HERE THE RESPONSE VALUE OF mysql response FROM accessoSicuro method
sess=req.session;
idUser = sess.passport.user;
res.render('index');
});
非常感谢