2012-04-30 42 views
-1

def user=User.findByUserIdAndPassword(params.userId,params.password)即使在註冊成功後也爲空......我正在使用Spring Security。def user = User.findByUserIdAndPassword(params.userId,params.password)爲空?? IN GRAILS

我的用戶領域類是

class User { 

    transient springSecurityService 

    Integer id 
    String userId 
    String password 
    byte[] photo 
    String fullName 
    String bio 
    String email 
    String address 
    String username 

    boolean enabled 
    boolean accountExpired 
    boolean accountLocked 
    boolean passwordExpired 

    static hasMany = [places: Place, badges: Badge, checkIns:CheckIn, friend:User] 

    static belongsTo = Place 

    String toString(){ 
     "$userId" 
    } 

    static constraints = { 
     fullName(nullable: true,maxSize:20,matches:"[a-zA-Z\40-\176]+") 
     bio(nullable: true, maxSize: 100,matches:"[a-zA-Z\40-\176]+") 
     email(email: true, blank: false) 
     photo(nullable: true,maxSize:1000000) 
     address(nullable:true,maxSize:40,matches:"[a-zA-Z0-9\40-\176]+") 
     userId(size:5..10,unique:true,nullable:false,matches:"[a-zA-Z][a-zA-Z0-9 ]+") 
     password(size:5..10,password:true,nullable:false) 
     username blank: false, unique: true 
    } 

    static mapping = { 
     password column: '`password`' 
    } 

    Set<Authority> getAuthorities() { 
     UserAuthority.findAllByUser(this).collect { it.authority } as Set 
    } 

    def beforeInsert() { 
     encodePassword() 
    } 

    def beforeUpdate() { 
     if (isDirty('password')) { 
     encodePassword() 
     } 
    } 

    protected void encodePassword() { 
     password = springSecurityService.encodePassword(password) 
    } 
} 

如果我實現

System.out.println(" userid------------------->" + params.userId); 
System.out.println(" password------------------->" + params.password); 
System.out.println(" username------------------->" + params.username); 

我能看到登錄用戶的用戶名和密碼......但爲什麼

def user=User.findByUserIdAndPassword(params.userId,params.password) NULL?

回答

1

密碼存儲在數據庫中。因此,params.password與存儲在數據庫中的值不匹配。

此外 - 你想達到什麼?您可以通過訪問該服務手動訪問用戶:

springSecurityService.currentUser

併爲登錄目的,我會建議使用彈簧安全的UI插件。

希望能幫到:)