Grails,spring-security我想注册新用户而无需确认电子邮件

时间:2017-05-29 13:45:44

标签: spring authentication grails

由管理员进行注册,不需要/需要电子邮件确认。

我使用了overide-script但它只是创建了一个空控制器,我不知道如何使用它。 它看起来像这样:

package com.myProj.security

class RegisterController extends grails.plugin.springsecurity.ui.RegisterController {
}

运行命令也给了我这个答案:

| Copying register resources
| Rendered template RegisterController.groovy.template to destination grails-app\controllers\com\testx\ui\RegisterController.groovy
| Error Command [s2ui-override] error: class path resource [layouts/register.gsp] cannot be opened because it does not exist (Use --stacktrace to see the full trace)
java.io.FileNotFoundException: class path resource [layouts/register.gsp] cannot be opened because it does not exist
        at org.grails.io.support.ClassPathResource.getInputStream(ClassPathResource.java:148)
        at org.grails.io.support.SpringIOUtils.copy(SpringIOUtils.java:196)
        at org.grails.cli.profile.commands.io.FileSystemInteractionImpl.copy(FileSystemInteractionImpl.groovy:144)
        at org.grails.cli.profile.commands.io.FileSystemInteractionImpl.copy(FileSystemInteractionImpl.groovy)
        at org.grails.cli.profile.commands.script.GroovyScriptCommand.copy(GroovyScriptCommand.groovy:58)
        at org.grails.cli.profile.commands.io.FileSystemInteraction$copy$2.callCurrent(Unknown Source)
        at s2ui-override.copy(s2ui-override.groovy:113)
        at s2ui-override.run(s2ui-override.groovy:108)
        at org.grails.cli.profile.commands.script.GroovyScriptCommand.handle(GroovyScriptCommand.groovy:152)
        at org.grails.cli.profile.AbstractProfile.handleCommand(AbstractProfile.groovy:481)
        at org.grails.cli.GrailsCli.handleCommand(GrailsCli.groovy:377)
        at org.grails.cli.GrailsCli.handleCommand(GrailsCli.groovy:350)
        at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:271)
        at org.grails.cli.GrailsCli.main(GrailsCli.groovy:159)

知道怎么办吗?手册没有帮助我。也许我想念那里的东西?

============================================== < / p>

我在GitHub上找到了一些代码并从RegisterController复制了一些代码并将其添加到我几乎空的RegisterController中。

package com.myProj.security
import grails.plugin.springsecurity.authentication.dao.NullSaltSource
import grails.plugin.springsecurity.ui.strategy.MailStrategy
import grails.plugin.springsecurity.ui.strategy.PropertiesStrategy
import grails.plugin.springsecurity.ui.strategy.RegistrationCodeStrategy
import groovy.text.SimpleTemplateEngine
import org.springframework.security.authentication.dao.SaltSource
import grails.plugin.springsecurity.annotation.Secured

class RegisterController extends grails.plugin.springsecurity.ui.RegisterController {
    def register(RegisterCommand registerCommand) {

        if (!request.post) {
            return [registerCommand: new RegisterCommand()]
        }

        if (registerCommand.hasErrors()) {
            return [registerCommand: registerCommand]
        }

        def user = uiRegistrationCodeStrategy.createUser(registerCommand)
        String salt = saltSource instanceof NullSaltSource ? null : registerCommand.username
        RegistrationCode registrationCode = uiRegistrationCodeStrategy.register(user, registerCommand.password, salt)

        if (registrationCode == null || registrationCode.hasErrors()) {
            // null means problem creating the user
            flash.error = message(code: 'spring.security.ui.register.miscError')
            return [registerCommand: registerCommand]
        }

        user = uiRegistrationCodeStrategy.finishRegistration(registrationCode)

        if (!user) {
            flash.error = message(code: 'spring.security.ui.register.badCode')
            redirect uri: successHandlerDefaultTargetUrl
            return
        }

        if (user.hasErrors()) {
            // expected to be handled already by ErrorsStrategy.handleValidationErrors
            return
        }

        flash.message = message(code: 'spring.security.ui.register.complete')
        redirect uri: registerPostRegisterUrl ?: successHandlerDefaultTargetUrl
    }
}

Theres没有对我说它不起作用,但我想知道作者是如何让我这样做的。导入看起来不可访问,因此代码不会编译。即使可以,我怎样才能确保调用此控制器?

0 个答案:

没有答案