Attic/programs/Application1.scala
changeset 198 2ce98ee39990
parent 13 2bd3530c30af
equal deleted inserted replaced
197:9c968d0de9a0 198:2ce98ee39990
       
     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 = """<form method="post"> 
       
    21                 Login: <input type="text" name="login"><br>
       
    22                 Password: <input type="password" name="password"><br>
       
    23                 <input type="submit"></form>"""
       
    24 
       
    25     Ok(form).as(HTML)
       
    26   }  
       
    27 
       
    28   
       
    29   // POST data: processing the login data
       
    30   val receive = Action { request =>
       
    31     
       
    32     val form_data = Form (tuple ("login" -> text, "password" -> text))
       
    33     val (login, password) = form_data.bindFromRequest()(request).get 
       
    34     
       
    35     Ok("Received login: " + login + " and password: " + password)
       
    36   }
       
    37   
       
    38 }