Grails - 在不更改 URL 的情况下检索注册页面或主页
Grails - Retrieve Sign Up page or Home page without changing the URL
我正在使用具有 Spring 安全性的 Grails,并且希望当用户进入我的站点根目录 URL 时,它会收到一个不同的页面,这取决于他是否登录。
1.登录 - 主页有不同的数据
2. 未登录 - 注册页面
我不想使用 Spring UI 插件,我不想使用重定向,因为我希望 URL 留在根 url,最好的方法是什么?
将应用程序的根“/”映射到您定义的控制器(在 UrlMappings.groovy 中)。在该控制器的索引方法中,检查用户是否已登录(通过 SpringSecurity 的 API)。如果用户已登录,则呈现您的登录视图,否则呈现您的未登录视图。这样,URL 保持不变。
这是插件 documentation 的摘录:
class SomeController {
def springSecurityService
def index() {
if (springSecurityService.isLoggedIn() && SpringSecurityUtils.ifAnyGranted("USER_ROLE")) { // Example here checks if we have the "USER_ROLE"
render view: "A"
}
else {
render view: "B"
}
}
}
注意 Anonymous 角色。它将成功通过文档中指定的 isLoggedIn。
我正在使用具有 Spring 安全性的 Grails,并且希望当用户进入我的站点根目录 URL 时,它会收到一个不同的页面,这取决于他是否登录。 1.登录 - 主页有不同的数据 2. 未登录 - 注册页面
我不想使用 Spring UI 插件,我不想使用重定向,因为我希望 URL 留在根 url,最好的方法是什么?
将应用程序的根“/”映射到您定义的控制器(在 UrlMappings.groovy 中)。在该控制器的索引方法中,检查用户是否已登录(通过 SpringSecurity 的 API)。如果用户已登录,则呈现您的登录视图,否则呈现您的未登录视图。这样,URL 保持不变。
这是插件 documentation 的摘录:
class SomeController {
def springSecurityService
def index() {
if (springSecurityService.isLoggedIn() && SpringSecurityUtils.ifAnyGranted("USER_ROLE")) { // Example here checks if we have the "USER_ROLE"
render view: "A"
}
else {
render view: "B"
}
}
}
注意 Anonymous 角色。它将成功通过文档中指定的 isLoggedIn。