目前我在我的BaseController
和每个控制器方法中都有一个方法,我需要对用户进行身份验证,我总是调用这段代码:
user, err := c.getUser()
if err != nil {
return c.Redirect(UserController.Login)
}
哪个只是检查是否
revel.InterceptMethod((*UserController).CheckUser, revel.BEFORE)
(在 init.go 中)已将有效用户添加到.RenderArgs["user"]
.
无论如何我可以将此重定向到登录页面,包括。auth 检查成一个过滤/拦截方法,所以我不必重复上面的代码 10 次?(我围绕 revel v0.9~0.10 开发了这段代码)
我想出的一个解决方案是编写一个类似于新的 csrf 模块的模块/应用程序。
编辑 4.11.2015:这个问题是前一段时间发布的,请查看官方Revel 文档,因为 revel 已经经历了相当多的发展