app1.scala
changeset 6 4c40d4b2d01c
parent 5 1280309e6bfc
equal deleted inserted replaced
5:1280309e6bfc 6:4c40d4b2d01c
     1 object Application extends Controller {
     1 object Application extends Controller {
     2 
     2 
     3   // presenting login form
     3   // GET request -> present login form
     4   val index = Action { request =>
     4   val index = Action { request =>
     5     
     5     
     6     val form = """<form method="post"> 
     6     val form = 
     7                 Login: <input type="text" name="login"><br>
     7        """<form method="post"> 
     8                 Password: <input type="password" name="password"><br>
     8           Login: <input type="text" name="login"><br>
     9                 <input type="submit"></form>"""
     9           Password: <input type="password" name="password"><br>
       
    10           <input type="submit"></form>"""
    10 
    11 
    11     Ok(form).as(HTML)
    12     Ok(form).as(HTML)
    12   }  
    13   }  
    13 
    14 
    14   
    15   // POST data: processing the login data
    15   // processing the received login data
       
    16   val receive = Action { request =>
    16   val receive = Action { request =>
    17     
    17     
    18     val form_data = Form (tuple ("login" -> text, "password" -> text))
    18     val form_data = Form (tuple ("login" -> text, "password" -> text))
    19 
    19 
    20     val (login, password) = form_data.bindFromRequest()(request).get 
    20     val (login, password) = form_data.bindFromRequest()(request).get 
    21     
    21     
    22     Ok("Received login: " + login + " and password: " + password)
    22     Ok("Received login: " + login + " and password: " + password)
    23   }
    23   }
    24   
       
    25 }
    24 }
    26 
    25 
    27 
    26 
    28 
    27