Итак, у меня есть успешный вход в систему с моим приложением grails. Но я хочу выделить некоторые функции в разных контроллерах.с моей аутентификацией в другом контроллере в grails?
пример:
package MyApp
class CustomerController {
/*Keeping the scaffold for admin purposes.*/
static scaffold = Customer
//write redirects and make exceptions for scaffolds
// def index() { }
/*
* Access controllers are ordered after application flow.
**/
def login(){
}
/*
* Authentication based on email adress as the identifier.
*
**/
def authenticate() {
def authPwd
def authUser
if(User.findByEmail(params.email) == null){
flash.message = "login failed"
redirect(action: "login")
}else{
authUser = User.findByEmail(params.email)
authPwd = authUser.getPassword()
if(authPwd == params.pwd){
session["user"] = authUser
session["customer"] = authUser.getCompany()
println "current user is: " + session["user"]
println "current customer is: " + session["customer"]
redirect(controller: "portal", action: "start")
}else{
flash.message = "login failed"
redirect(action: "login")
}
}
}
def logout() {
session.invalidate()
redirect(action: "login")
}
}
Так что я хочу сделать, это взять на себя аутентификацию() отсюда и поместить его в новый контроллер под названием AuthenticateController()
только, будучи новым для Граалей, моя переадресация не работает, и я надеялся, что кто-то может дать мне понять, почему.
Так что я думал, что вы бы вывезти
def authenticate {
/* some code*/
}
положить его в новый контроллер. то просто используйте
redirect(controller: "authenticate", action: "authenticate")
но это не работает, и я получаю исключение.
Любая помощь будет высоко ценится
Edit: для целей комментария ниже ...
class CustomerController {
/*Keeping the scaffold for admin purposes.*/
static scaffold = Customer
//write redirects and make exceptions for scaffolds
// def index() { }
/*
* Access controllers are ordered after application flow.
**/
def login(){
redirect(controller:"authenticate", action:"authenticate")
}
/*
* Authentication based on email adress as the identifier.
*
**/
def logout() {
session.invalidate()
redirect(action: "login")
}
}
Тогда AuthenticateController
class AuthenticateController {
def authenticate() {
def authPwd
def authUser
if(User.findByEmail(params.email) == null){
flash.message = "login failed"
redirect(contoller:"customer", action: "login")
}else{
authUser = User.findByEmail(params.email)
authPwd = authUser.getPassword()
if(authPwd == params.pwd){
session["user"] = authUser
session["customer"] = authUser.getCompany()
println "current user is: " + session["user"]
println "current customer is: " + session["customer"]
redirect(controller: "portal", action: "start")
}else{
flash.message = "login failed"
redirect(contoller:"customer", action: "login")
}
}
}
}
ли код, который не работает , В основном копировать и вставлять.
Tomcat работает, но с 100 ошибок первых
type Status report
message /ClipEdit_v1/authenticate/login
description The requested resource is not available.
Итак, вы опубликовали код, который работает, но не код, который не работает, или ошибка, которую вы получаете? –
ok Я добавил его, сарказм не помог ни –
Есть ли причина, по которой вы не используете Spring Security? Похоже, что из ваших примеров вы храните пароль в виде обычного текста. Вы действительно не должны делать это самостоятельно, если хотите иметь безопасное приложение. –