programs/Application1.scala
author Christian Urban <urbanc@in.tum.de>
Fri, 28 Sep 2012 15:18:44 +0100
changeset 13 2bd3530c30af
permissions -rw-r--r--
added programs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
package controllers
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
import play.api._
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
import play.api.mvc._
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
import play.api.data._
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
import play.api.data.Forms._
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
/*
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
 * Answers a GET-request by sending a simple login form.
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
 *
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
 * Processes the POST-data by just printing the results.
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
 *
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
 */
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
object Application extends Controller {
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  // GET request -> login form
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
  val index = Action { request =>
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
    
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
    val form = """<form method="post"> 
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
                Login: <input type="text" name="login"><br>
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
                Password: <input type="password" name="password"><br>
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
                <input type="submit"></form>"""
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
    Ok(form).as(HTML)
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  }  
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  // POST data: processing the login data
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
  val receive = Action { request =>
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
    
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
    val form_data = Form (tuple ("login" -> text, "password" -> text))
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
    val (login, password) = form_data.bindFromRequest()(request).get 
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
    
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
    Ok("Received login: " + login + " and password: " + password)
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  }
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  
2bd3530c30af added programs
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
}