gpt4 book ai didi

grails - Grails Controller 的beforeInterceptor

转载 作者:行者123 更新时间:2023-12-02 15:27:22 24 4
gpt4 key购买 nike

我试图做到这一点,以便无论访问 Controller 的什么功能,如果 session 已为空,则在弹出的对话框中单击“确定”后,它会返回登录页面,但该 session 已过期,但我不能完全正常工作。以下是此 Controller 的前几种方法:

def beforeInterceptor = {
[action:this.&checkSession()]
}

def checkSession() {
if (!session.user) {
render text: """<script type="text/javascript"> alert('Session expired. Please log in again.'); window.location.href = data.url;</script>""",
contentType: 'js'

}
}

def index() {
redirect (action: customerLogin)
}

def customerLogin = {
selectedBatch = null
}

def authenticate = {

def user = null

def possibleUsersList = User.findAllWhere(user_name: params.username)

possibleUsersList.each {
if (bcryptService.checkPassword(params.password, it.user_password))
user = it
}

if (user) {
session.user = user
greetingName = user.user_name
render(contentType: 'text/json') {
[success: true, url: createLink(controller: 'customer', action: 'custMainPage')]
}
}
else {
//def messages = ResourceBundle.getBundle('messages')
//def errorstring = bundle.getString("fatcaone.login.error")
//println "Login error: " + ${errorstring}
render (contentType: 'text/json') {
//["message": '<p>code=fatcaone.login.error</p>']
["message": '<p>Login or Password incorrect.</p>']
}
}
}

def logout = {
if (session.user != null) {
flash.message = "Goodbye ${session.user.fullName}"
session.user = null

}
redirect(action: customerLogin)
}

最佳答案

从Grails 3.0中删除了beforeInterceptor。
有关此问题的讨论,请参见https://github.com/grails/grails-core/issues/635

关于grails - Grails Controller 的beforeInterceptor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25898394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com