Grails 3.2.8 Контроллер регистра не расширяется
При использовании Grails 2.4.4 можно было запустить скрипт
grails s2ui-override register <controller-package>
и мы были с расширенным RegisterController с
controller/RegisterController.groovy
views/register/forgotPassword.gsp
views/register/register.gsp
views/register/resetPassword.gsp
И было также возможно расширить контроллер register() с помощью кода плагина, но в Grails 3.2.8 я просто получаю расширенный RegisterController и register.gsp в папке макета. И когда я расширяю grails.plugin.springsecurity.ui.RegisterController в Grails 3.2.8, как я это делаю в Grails 2.4.4, он выдает ошибку:
The return type of java.lang.Object getSaltSource() in
org.nfdb.userManagement.RegisterController is incompatible with
org.springframework.security.authentication.dao.SaltSource in
grails.plugin.springsecurity.ui.RegisterController
. At [-1:-1] @ line -1, column -1.
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output.
Мой контроллер это:
package org.xxxx.userManagement
import java.text.SimpleDateFormat
import grails.plugin.springsecurity.authentication.dao.NullSaltSource
class RegisterController extends
grails.plugin.springsecurity.ui.RegisterController {
def saltSource
def springSecurityUiService
def springSecurityService
def simpleCaptchaService
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
def register(RegisterCommand command){
println "PARAMS ARE "+command
println "PARAMS ARE with params"+params
//1. error checks
if (command.hasErrors()) {
println "print command == "+command.password
command.errors.each{ println it }
render view: 'index', model: [command: command]
return
}
def dob
if(params.dateOfBirth != null && params.dateOfBirth != ''){
SimpleDateFormat parser = new SimpleDateFormat("dd/MM/yyyy")
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy")
def dob11 = parser.parse(params.dateOfBirth)
def dob1 = formatter.format(dob11)
dob = dob11
}else{
dob=params.dateOfBirth
}
println"date of birth"+dob
println"date of birth 2"+params.dateOfBirth
def location
//2. Saving User
String salt = saltSource instanceof NullSaltSource ? null : command.username
def user = lookupUserClass().newInstance(email: command.email, username: command.username,
accountLocked: true, enabled: true,password:command.password,
dateOfBirth:dob ,phone:command.phone, mobile:command.mobile,name:command.name)
//3.
if(!user.save(flush:true)){
user.errors.each{ println "USER NOT SAVED" +it }
}
if(params.newRole){
def userRole = NfdbRole.findOrCreateByAuthority(params.newRole)
println "userroleeeeeeeeeeeeeeee......"+userRole
userRole.authority = params.newRole
if(!userRole.save(flush:true)){
userRole.errors.each{ println "USER NOT SAVED" +it }
}
String newrole = params.newRole
}
try{
mailService.sendMail {
to command.email
from conf.ui.register.emailFrom
subject conf.ui.register.emailSubject
html body.toString()
}
}
catch(Exception e){
println "Exception in sending email is:"+e
}
println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~all done sucessful~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
//6.
render view: 'index', model: [emailSent: true, user:user]
}
}
class RegisterCommand {
String username
String password
String password2
String email
String name
String mobile
String phone
String dateOfBirth
def grailsApplication
static constraints = {
username blank: false, validator: { value, command ->
if (value) {
def User = command.grailsApplication.getDomainClass(
SpringSecurityUtils.securityConfig.userLookup.userDomainClassName).clazz
if (User.findByUsername(value)) {
return 'registerCommand.username.unique'
}
}
}
email blank: false,validator:{ value, command ->
if (value){
def User = command.grailsApplication.getDomainClass(SpringSecurityUtils.securityConfig.userLookup.userDomainClassName).clazz
if (User.findByEmail(value)) {
return 'validator.messageeeeeee'
}
}
}
password blank: false, validator: RegisterController.passwordValidator
password2 validator: RegisterController.password2Validator
mobile nullable:true, blank:true
name nullable:true, blank:true
phone nullable:true, blank:true
dateOfBirth nullable:true, blank:true
}
}
1 ответ
В вашем контроллере измените:
def saltSource
в
org.springframework.security.authentication.dao.SaltSource saltSource