简体   繁体   中英

Use username as email, Spring Security UI plugin

I'm using the Spring Security plugin, in combination with the Spring Security UI plugin.

They both work like a charm, but my problem is that I don't want my user to have a username, instead he/she should use the e-mail as username.

So in the register-phase I tried removing the username from the registration-page and setting

newUser.username = params.email

So that the plugins still can access the variable username, but this gave me validation errors and I just can't figure out a way to solve it.

Any ideas? Has anyone done anything similar?

You can modify the default User field that spring security uses

In your Config.groovy add the following

grails.plugins.springsecurity.userLookup.usernamePropertyName = 'XXX'

where XXX is the field of the User entity to be used

You can check the configuration attributes here

I have recently done this by copying views and controllers from spring security plugin to my grails-app and updated view to display emailAddress as oppose to username. I also replaced username property with emailAddress in User domain class. Make sure you update the constrains as follows:

static constraints = {
    emailAddress email: true, blank: false, unique: true
    password blank: false, password: true
}

What dimcookies suggest is correct and works for old version of Grails, the new syntax configuration, at least for Grails 2.3.1, is:

grails.plugin.springsecurity.userLookup.usernamePropertyName = 'emailAddress'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM