我做了下面的控制器。 我可以登錄和註銷,但是如何強制用戶先登錄? 我需要在登錄時啓動一個會話並在註銷時終止它。Grails安全實施
class UserController {
def scaffold = User
def login = {}
def authenticate = {
def user = User.findByLoginAndPassword(params.login, params.password)
if(user){
session.user = user
flash.message = "Hello ${user.name}!"
redirect(controller:"entry", action:"list")
} else {
flash.message = "Sorry, ${params.login}. Please try again."
redirect(action:"login")
}
}
def logout = {
flash.message = "Goodbye ${session.user.name}"
session.user = null
redirect(controller:"entry", action:"list")
}
}
我認爲這將有助於。我想你想要一種識別登錄用戶的方式http://stackoverflow.com/questions/38688075/request-map-direct-me-to-login-page-in-grails/38793608#38793608 – Vahid
糾正語法錯誤,收緊術語和固定代碼格式。 – Prune