0
我一直在嘗試使用grails 3攔截器在第一次登錄時捕獲用戶電子郵件,但是在捕獲電子郵件後,下次他們登錄後,他們被重定向到電子郵件捕獲表單而不是設置的主頁。如果這是相關信息,我正在使用spring security。我的代碼片段咆哮顯示了我迄今爲止所做的。請告訴我是否有更簡單的方法來實現我的目標或我做錯了什麼。如何使用grails 3攔截器來強制執行表單然後恢復grails應用程序的正常流程
class HomeInterceptor {
public HomeInterceptor() {
// match all requests except requests
// to the auth controller
matchAll().excludes(controller: 'logout')
.excludes(controller: 'login')
.excludes(controller: 'home')
.excludes(controller: 'user', action: 'userProfile')
.excludes(controller: 'user', action: 'showUserProfile')
}
boolean before() {
// if the user's email has not been captured,
// redirect to the user profile
def springSecurityService = AppHolder.bean(SpringSecurityService)
def loggedInUser = springSecurityService.currentUser as User
if (loggedInUser?.email == null){
flash.message = "Please enter your email before you can proceed"
redirect(controller: 'user', action: 'userProfile')
return false
}else {
return true
}
}
boolean after() { true }
void afterView() {
// no-op
}
}
謝謝,這是有益的 –