equal
deleted
inserted
replaced
|
1 package controllers |
|
2 |
|
3 import play.api._ |
|
4 import play.api.mvc._ |
|
5 import play.api.data._ |
|
6 import play.api.data.Forms._ |
|
7 |
|
8 /* |
|
9 * Answers a GET-request by sending a simple login form. |
|
10 * |
|
11 * Processes the POST-data by just printing the results. |
|
12 * |
|
13 */ |
|
14 |
|
15 object Application extends Controller { |
|
16 |
|
17 // GET request -> login form |
|
18 val index = Action { request => |
|
19 |
|
20 val form = """ |
|
21 <form method="post"> |
|
22 Login: <input type="text" name="login"><br> |
|
23 Password: <input type="password" name="password"><br> |
|
24 <input type="submit"></form>""" |
|
25 |
|
26 Ok(form).as(HTML) |
|
27 } |
|
28 |
|
29 |
|
30 // POST data: processing the login data |
|
31 val receive = Action { request => |
|
32 |
|
33 val form_data = Form(tuple ("login" -> text, "password" -> text)) |
|
34 val (login, password) = form_data.bindFromRequest()(request).get |
|
35 |
|
36 Ok(s"Received login: $login and password: $password") |
|
37 } |
|
38 |
|
39 } |