我在Lift / Scala应用中使用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中的哈希密码匹配。 我有点陷入困境。
任何帮助都将不胜感激。
谢谢!