我的模型如下:
case class User(uid: Option[Int], email: String, password: String, created_at: Timestamp, updated_at: Timestamp)
case class UserProfile(firstname: String, lastname: String, gender: Int, user_id: Long)
我将表单绑定定义如下:
val date = new Date()
val currentTimestamp= new Timestamp(date.getTime());
val registerForm = Form(
tuple(
"user" -> mapping(
"uid" -> optional(number),
"email" -> email,
"password" -> nonEmptyText,
"created_at" -> ignored(currentTimestamp),
"updated_at" -> ignored(currentTimestamp)
) (User.apply)(User.unapply),
"profile" -> mapping(
"firstname"->nonEmptyText,
"lastname"->nonEmptyText,
"gender" -> ignored(0),
"user_id" -> ignored(0L)
)(UserProfile.apply)(UserProfile.unapply))
)
现在,我想使用散列来保存密码,然后使用光滑保存/插入数据库。 我可以尝试通过创建一个新的User对象来实现它,但这听起来不像有效的方法。
还有其他方法吗?
提前致谢
------------------------------------------编辑1 --- -------------------------------------------------- ----- 这是我的插入逻辑与光滑:
def insert(user: User): Future[Any] = {
println("coming inside insert of user dao")
println(user)
// insertUP(user)
db.run((Users returning Users.map(_.uid)) += user)
}
答案 0 :(得分:1)
如下:
def insert(user: User): Future[Any] = {
val hashedPassword = hashPassword(user.password)
val updatedUser = user.copy(password = hashedPassword)
db.run((Users returning Users.map(_.uid)) += updatedUser)
}