玩密码字段绑定的框架scala表单对象?
Play framework scala form object for password field binding?
我有以下型号:
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))
)
现在,我想在使用 slick 在数据库中获取 saved/inserted 之前使用散列来存储密码。
我可以尝试通过创建一个新的 User 对象来做到这一点,但这听起来不像是有效的方法。
还有其他方法吗?
提前致谢
---------------------------------------- 编辑 1 - ---------------------------------------------- ------
这是我的 slick 插入逻辑:
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)
}
怎么样:
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)
}
我有以下型号:
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))
)
现在,我想在使用 slick 在数据库中获取 saved/inserted 之前使用散列来存储密码。 我可以尝试通过创建一个新的 User 对象来做到这一点,但这听起来不像是有效的方法。
还有其他方法吗?
提前致谢
---------------------------------------- 编辑 1 - ---------------------------------------------- ------ 这是我的 slick 插入逻辑:
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)
}
怎么样:
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)
}