有很多方法可以在keystone中实现自己的身份验证和帐户管理方法,因为它基于express.js。
然后,您可以添加一个“中间件”函数数组到路由,这些路由在将请求传递到控制器之前将会运行。
e.g 路线中间件之前加入
app.get('/admin', routes.views.userAdmin);
中间件功能
function isAuthenticated(req, res, next) {
// do any checks you want to in here
// CHECK THE USER STORED IN SESSION FOR A CUSTOM VARIABLE
// you can do this however you want with whatever variables you set up
if (req.user.authenticated)
return next();
// IF A USER ISN'T LOGGED IN, THEN REDIRECT THEM SOMEWHERE
res.redirect('/');
}
路线与中间件加入
app.get('/admin', isAuthenticated, routes.views.userAdmin);
这是一个非常宽泛的问题,所以我建议你去决定你想自己做的最好方法,因为每个人都有自己的个人喜好。您想要的搜索字词是“express middleware authentication”。很多人使用PassporJS http://passportjs.org/
希望帮助:)