Play 2.5中的绑定表单值

时间:2017-04-06 13:33:52

标签: scala playframework playframework-2.5

我正在尝试将Play 2.2项目升级到Play 2.5。 我有一个在游戏2.2中工作正常的身份验证但如果我尝试在Play 2.5中实现相同的身份验证,它总是进入“未授权”页面。我认为我在绑定表单的值时遇到了一些问题。 这是我的代码:

Application.scala`

package controllers

import javax.inject._
import play.api._
import play.api.mvc._
import views._
import models.users.User
import models.users.UserDB
import models.users.UserForm
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n._

@Singleton
class Application @Inject()(
        userdb : User,
        val messagesApi: MessagesApi 
        ) extends Controller with I18nSupport {

    val userForm  : Form[UserForm]=  Form (
          mapping(
                  "email" -> nonEmptyText,
                  "password" -> nonEmptyText
          )(UserForm.apply)(UserForm.unapply))

    def index = Action { implicit request =>
        Ok(views.html.user.userLogin(userForm)).withNewSession

    }

    def login = Action { implicit request =>  
         userForm.bindFromRequest.fold( 
            errors=> BadRequest(html.user.userLogin( errors)),
                user => { 
                 Ok
                }
          )

    }


}`

这是我的UserForm案例类:

case class UserForm(email : String, password : String) {

}  

这是我的观点userLogin:

@( userForm: Form[models.users.UserForm])(implicit flash: Flash, messages: Messages)

@import helper._ 
.
.
.
//OTHER HTML STUFF....

@form(action = routes.Application.login()) {
                <div class="emailaddress">E-mail address:</div>
                <div class="inputbox">
                    @input(userForm("email"), '_id -> "email", '_label->"" ) { (id, name, value, args) => 
                                <input placeholder="" type="text" class="email-input" id="@id" name="@name" value="" @toHtmlArgs(args)>
                            }

                </div>
                <div class="password">Password:</div>
                <div class="inputbox1">
                    @helper.input(userForm("password"), '_id -> "password", '_label->"") { (id, name, value, args) => 
                                <input placeholder="" class="password-input" type="password" id="@id" name="@name" value="" @toHtmlArgs(args)>
                            }
                </div>
                <div >
                    <button id="submit-button" class="myButton" >Submit</button>
                </div>

            }
            @userForm.globalError.map { error =>
                <p class="error">
                    @error.message
                </p>
            }

我认为我的问题出在html文件中,因为我还试图用

来补充登录方法
 def login = Action { implicit request =>
        Ok
 } 

但它总是把我带到未经授权的页面。

感谢。

0 个答案:

没有答案