progs/app1.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 26 Nov 2013 13:36:39 +0000
changeset 140 4affecdbc1a9
parent 98 3d585e603927
permissions -rw-r--r--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
object Application extends Controller {
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
6
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     3
  // GET request -> present login form
5
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
  val index = Action { request =>
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
    
6
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     6
    val form = 
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     7
       """<form method="post"> 
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     8
          Login: <input type="text" name="login"><br>
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
     9
          Password: <input type="password" name="password"><br>
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
    10
          <input type="submit"></form>"""
5
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
    Ok(form).as(HTML)
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  }  
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
6
4c40d4b2d01c new slides
Christian Urban <urbanc@in.tum.de>
parents: 5
diff changeset
    15
  // POST data: processing the login data
5
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  val receive = Action { request =>
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
    
98
3d585e603927 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    18
    val form_data = Form(tuple ("login" -> text, "password" -> text))
3d585e603927 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    19
    def (login, passwd) = form_data.bindFromRequest()(request).get
5
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
    
98
3d585e603927 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    21
    Ok(s"Received login: $login and password: $passwd")
5
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  }
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
1280309e6bfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26