2
我使用的IntelliJ 14游戏框架,我认为框架的版本号为2的关于信息向我表明:关于发挥框架验证表单
[info] The current project is built against Scala 2.10.4
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugi
n, play.Play, play.PlayJava, play.PlayScala, play.twirl.sbt.SbtTwirl, com.typesafe.sbt.jse.SbtJsEngine, com.typesafe.sbt.jse.Sb
tJsTask, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.webdriver.SbtWebDriver, com.typesafe.sbt.coffeescript.SbtCoffeeScript, c
om.typesafe.sbt.less.SbtLess, com.typesafe.sbt.jshint.SbtJSHint, com.typesafe.sbt.rjs.SbtRjs, com.typesafe.sbt.digest.SbtDigest
, com.typesafe.sbt.mocha.SbtMocha, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.Sb
tNativePackager
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
我试图创建一个登录表单,它运行良好,但我无法正确验证它,并显示错误消息。见我的代码波纹管:
POST /authorize controllers.LoginController.authorize
控制器阶:
package controllers
import models.{DB, User}
import play.api.data.Form
import play.api.data.Forms._
import play.api.libs.json.Json
import play.api.mvc._
/**
* Created by jlopesde on 26-12-2014.
*/
object LoginController extends Controller {
val loginForm: Form[User] = Form (
mapping (
"user" -> nonEmptyText,
"password" -> nonEmptyText
)(User.apply)(User.unapply)
verifying ("Invalid login", f => true)
)
def index = Action {
Ok(views.html.login("ok"))
}
def authorize = Action {implicit request =>
// get user from request
val user = loginForm.bindFromRequest().get
// query user database
val _user = DB.query[User].whereEqual("login", user.login).whereEqual("password", user.password).fetchOne()
var response = _user match {
case None => "KO"
case _ => "OK"
}
if (response.equals("OK")) {
//send to index page
Redirect(routes.Application.index()).withSession("user" -> user.login)
} else {
Redirect(routes.LoginController.index())
}
}
}
的login.html
:
@(message: String)
@(myForm: Form[User])
@import helper._
@import models.User
@main("This is login") {
@helper.form(routes.LoginController.authorize()) {
<label for="user">username:</label> <input id="user" name="user" type="text">
<label for="password">Password:</label><input id="password" name="password" type="password">
<button>Login</button>
}
}
的问题是,我不能让工作,娱乐不承认键入myForm
,我应该以某种方式发送它,但它期望一个字符串,而不是一个表单。 我尝试了几个例子,但都没有工作。
Compilation error
not found: value myForm
In C:\Users\jlopesde\playprojects\my-first-app\app\views\login.scala.html:2
[email protected](message: String)
[email protected](myForm: Form[User])
[email protected] helper._
[email protected] models.User
5
[email protected]("This is login") {
7
好吧,那些消息是来自游戏模板,我真的不明白是什么意思。我会尝试做修改和测试。非常感谢。 –
我的朋友感谢你,像魅力一样工作! –