2011-07-18 232 views
1

我在我的Lift/Scala應用程序中使用MegaProtoUser來管理用戶。MongoMetaRecord MegaProtoUser登錄時不密碼密碼

在我的正在運行的應用程序中,我可以正常註冊一個新用戶,並且在註冊後仍然保持焦躁不安。 註銷並嘗試使用相同的用戶名和密碼登錄後,應用程序會抱怨用戶名/密碼無效。

我檢查了密碼字段的mongo數據庫條目,發現密碼被散列。

如果我直接複製並粘貼哈希密碼在Web應用程序的密碼字段蒙戈數據庫,用戶登錄 密碼數據庫看起來是這樣的:oqGR/CR + phb7fpSOL1Bpi8mtV ...

對於model.User.scala

代碼:

/** 
* The singleton that has methods for accessing the database 
*/ 
object User extends User with MongoMetaRecord[User] with MetaMegaProtoUser[User] { 
    override def screenWrap = Full(<lift:surround with="default" at="content"> 
     <lift:bind /></lift:surround>) 
    // define the order fields will appear in forms and output 
    override def fieldOrder = List(id, firstName, lastName, email, 
           locale, timezone, password) 

    // comment this line out to require email validations 
    override def skipEmailValidation = true 

} 

/** 
* An O-R mapped "User" class that includes first name, last name, password and we add a "Personal Essay" to it 
*/ 
class User private() extends MongoRecord[User] with MegaProtoUser[User] { 
    def meta = User // what's the "meta" server 
    protected def userFromStringId(id: String): Box[User] = meta.find(id) 

    protected def findUserByUniqueId(id: String): Box[User] = { 
    var searchListHeadOption = meta.findAll("_id",id).headOption 
    searchListHeadOption match { 
     case Some(x) => Full(x) 
     case None => return Empty 
    } 
    } 
    /** 
    * Given an username (probably email address), find the user 
    */ 
    protected def findUserByEmail(email: String): Box[User] = { 
    var searchListHeadOption = meta.findAll("email",email).headOption 
    searchListHeadOption match { 
     case Some(x) => Full(x) 
     case None => return Empty 
    } 
    } 


    protected def findUserByUserName(email: String): Box[User] = findUserByEmail(email) 

    override def valUnique(errorMsg: => String)(emailValue: String) = { 
    meta.findAll("email",emailValue) match { 
     case Nil => Nil 
     case usr :: Nil if (usr.id == id) => Nil 
     case _ => List(FieldError(email, "The email should be unique")) 
    } 
    } 

    // define an additional field for a personal essay 
} 

在登錄時,所輸入的密碼與從DB哈希密碼相匹配。 我有點卡在這一點。

任何幫助,將不勝感激。

謝謝!

回答

1

關於Record的PasswordField打開,我看到類似的Lift issue。希望能幫助到你!

+0

太棒了!感謝這個數據,@酯。 我希望這是儘快解決的。 – JazJ