My form looks like:
case class PasswordData(currentPassword: String, newPassword: String, verifyPassword: String)
val passwordForm = Form(
mapping(
)(PasswordData.apply)(PasswordData.unapply) verifying("Passwords do not match", fields => fields match {
case data => (data.newPassword == data.verifyPassword)
})
)
My controller action follows the usual pattern:
passwordForm.bindFromRequest.fold(
error => {},
form => {}
)
The problem I have now is I need to verify if the entered 'currentPassword' is the same as what is on the user's object.
userDao.getById(userId).password == form.currentPassword
But I can't do this because I am not sure how to pass int he userId to my form definition since it is dynamic.
i.e. I can't do it like:
"currentPassword" -> nonEmptyText.verifying(....) // userId not in scope
Update
I am trying to display these errors also using (they don't currently display the error, I only see the ul tags).
@if(form.hasGlobalErrors) {
<ul>
@form.errors.foreach { error =>
<li>@error.message</li>
}
</ul>
}
passwordandre-password... - sarveshseri