author | cu |
Sun, 08 Oct 2017 23:49:40 +0100 | |
changeset 546 | 3d1f65e43065 |
parent 198 | 2ce98ee39990 |
permissions | -rw-r--r-- |
103
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
package controllers |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
import play.api._ |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
import play.api.mvc._ |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
import play.api.data._ |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
import play.api.data.Forms._ |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
/* |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
* Answers a GET-request by sending a simple login form. |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
* |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
* Processes the POST-data by just printing the results. |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
* |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
*/ |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
object Application extends Controller { |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
// GET request -> login form |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
val index = Action { request => |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
val form = """ |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
<form method="post"> |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
Login: <input type="text" name="login"><br> |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
Password: <input type="password" name="password"><br> |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
<input type="submit"></form>""" |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
Ok(form).as(HTML) |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
} |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
// POST data: processing the login data |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
val receive = Action { request => |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
val form_data = Form(tuple ("login" -> text, "password" -> text)) |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
val (login, password) = form_data.bindFromRequest()(request).get |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
Ok(s"Received login: $login and password: $password") |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
} |
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
|
bd6e45c7aa8d
added applications
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
} |