我想製作play2-auth
標準樣本,不包括授權 - 只是驗證/登錄。製作工作play2-auth標準樣本
我的形式收到以下錯誤在@helper.form
行:
類型不匹配;實測值:play.api.mvc.Action [play.api.mvc.AnyContent] 需要:play.api.mvc.Call
@(form: Form[Option[session2.Account]])(implicit flash: Flash)
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
@helper.form(session2.ManageSession.authenticate) { // <-- here's the error
<h1>Sign in</h1>
@form.globalError.map { error =>
<p class="error">
@error.message
</p>
}
@flash.get("success").map { message =>
<p class="success">
@message
</p>
}
<p>
<input type="email" name="email" placeholder="Email" id="email"
value="@form("email").value">
</p>
<p>
<input type="password" name="password" id="password" placeholder="Password">
</p>
<p>
<button type="submit" id="loginbutton">Login</button>
</p>
}
</body>
</html>
這是ManageSession.scala:
package session2
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import jp.t2v.lab.play2.auth._
object ManageSession extends Controller with LoginLogout with AuthConfigImpl {
val loginForm = Form {
mapping("email" -> text, "password" -> text)(Account.authenticate)
(_.map(u => (u.email, "")))
.verifying("Invalid email or password", result => result.isDefined)
}
def login = Action { implicit request =>
Ok(views.html.login(loginForm))
}
def logout = Action.async { implicit request =>
// do something...
gotoLogoutSucceeded
}
def authenticate = Action.async { implicit request =>
loginForm.bindFromRequest.fold(
formWithErrors => Future.successful(BadRequest(views.html.main())),
user => gotoLoginSucceeded(user.get.email)
)
}
}
感謝。我得到一個錯誤'價值ManageSession不是對象controllers.routes'的成員,任何想法可能是什麼原因? ManageSession是在包控制器 – ps0604
@ ps0604您使用哪個版本的Play? – Mikesname
2.5.2使用eclipse scala ide – ps0604