Grails 3.2.8注册控制器没有扩展

时间:2017-08-02 06:06:54

标签: grails grails3

使用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 3.2.8中扩展 grails.plugin.springsecurity.ui.RegisterController 时,我在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 个答案:

答案 0 :(得分:0)

在您的控制器中,更改:

def saltSource

org.springframework.security.authentication.dao.SaltSource saltSource