note: I am new to Play Framework
Using this video tutorial and playlist, I manage to create a simple webapp.
Problem:
POST
methods in routes file do not seem to execute the required POST code.
Given the routes file below, browsing to localhost:{port}/user/register
requests a GET
, thus rendering and returning the register view
.
Filling in the register view
fields, and clicking submit
, refreshes the page (by clearing the input fields) and does show the expected "registered" text
If method="post"
has been added to the form
in the register view
, an immediate 403 Forbidden page
page is displayed.
Why isn't the "registered" text being shown, what am I missing (doing wrong) ?
Routes file:
GET / controllers.HomeController.index
GET /user controllers.LoginController.index()
GET /user/login controllers.LoginController.login()
POST /user/login controllers.LoginController.doLogin()
GET /user/register controllers.LoginController.register()
POST /user/register controllers.LoginController.doRegister()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
Controllers:
HomeController
LoginController
LoginController methods:
public Result index() { return ok(views.html.user.index.render(User.getAllUsers())) }
public Result login() { return ok(login.render()); }
public Result doLogin() { return ok("registered"); }
public Result register() { return ok(register.render()); }
public Result doRegister() { return ok("registered"); }
Register View:
@()
<html>
<head>
<title>Register new User</title>
</head>
<body>
<h1>Register User</h1>
<br>
<br>
Enter Email Address: <input type="password" name="confirmPassword">
Enter Password: <input type="password" name="confirmPassword">
Confirm Password: <input type="password" name="confirmPassword">
<br>
<br>
<form action="@routes.LoginController.doRegister()">
<input type="submit" value="Register"/>
</form>
</body>
</html>
Console output error:
[warn] p.filters.CSRF - [CSRF] Check failed because no or invalid token found in body
[warn] p.filters.CSRF - [CSRF] Check failed with NoTokenInBody
post
route in one's routes file (for everypost
method one needs bypassing for the CSRF filter. I shall apply your suggested method to include and make use of the CRSF filter, since it was a little vage. Thank you! – Domash