アレッ*_*ックス 0 scala playframework playframework-2.2
我有一个标准的,简单的代码来验证用户:
# controller
val addForm = Form(
tuple("email" -> nonEmptyText, "password" -> nonEmptyText)
.verifying("Invalid email or password", result => User.authenticate(result._1, result._2).isRight)
)
def add = Action { Ok(views.html.session.add(addForm)) }
def create = Action {
addForm.bindFromRequest.fold(
failure => BadRequest(views.html.session.add(failure)),
success => Redirect(routes.Home.index)
.flashing("key1" -> "You have logged in.")
)
}
Run Code Online (Sandbox Code Playgroud)
我希望它能显示错误,如果没有,User.authenticate(result._1, result._2).isRight但没有出现错误.是的,身份验证运行良好,但失败时没有错误.
@helper.form(action = routes.Session.create()) {
@helper.inputText(form("email"))
@helper.inputText(form("password"))
<!-- ........... -->
}
Run Code Online (Sandbox Code Playgroud)
为什么?
你有没有检查你的观点
@if(addForm.hasErrors) { ... }
Run Code Online (Sandbox Code Playgroud)
例如,基本布局可能是:
@if(addForm.hasErrors) {
<div class="alert-message error">
<p>Please correct the following:</p>
<ul>
@addForm.errors.map { error =>
<li>@error.key @error.message</li>
}
</ul>
</div>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
301 次 |
| 最近记录: |