Now I know that I may not have clean code, but I just want this damn job to work. This gives me the error "Unauthorized. You must be authenticated to access this page."
I have the following controller
package controllers import javax.inject._ import play.api._ import play.api.mvc._ import play.api.data._ import play.api.data.Forms._ import models.UserData import models.Contact import play.api.i18n._ @Singleton class HomeController @Inject()(val messagesApi: MessagesApi)extends Controller with I18nSupport { def index = Action { implicit request => Ok("Got request [" + request + "]") } val userForm = Form(mapping("name"->nonEmptyText, "age"->number(min=0, max=100))(UserData.apply)(UserData.unapply)) def userPost = Action { implicit request => userForm.bindFromRequest.fold( formWithErrors => { BadRequest(views.html.user(formWithErrors)) }, userData => { val newUser = models.UserData(userData.name, userData.age) Redirect(routes.HomeController.home()) }) } def home = Action { implicit request => Ok(views.html.index()) } def user = Action {implicit request => Ok(views.html.user(userForm)) } }
The following user.scala.html file
@(userForm: Form[UserData])(implicit messages: Messages) @helper.form(action = routes.HomeController.userPost()) { @helper.inputText(userForm("name"), 'id -> "name", 'size -> 30) @helper.inputText(userForm("age")) <input type="submit" value="submit"</input> }
and the following routes file:
# Routes
Can someone please help me get past an unauthorized page error. I have no idea why this is happening. I just want to convey a simple form.
Thanks.
source share