comparison demo/cookieSec.ur @ 779:7394368a5cad

cookieSec demo
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 May 2009 15:38:49 -0400
parents
children 731e6aa6655a
comparison
equal deleted inserted replaced
778:7b47fc964a0f 779:7394368a5cad
1 cookie username : string
2
3 table lastVisit : { User : string, When : time }
4 PRIMARY KEY User
5
6 fun main () =
7 userO <- getCookie username;
8
9 list <- queryX (SELECT * FROM lastVisit)
10 (fn r => <xml><tr><td>{[r.LastVisit.User]}</td> <td>{[r.LastVisit.When]}</td></tr></xml>);
11
12 return <xml><body>
13 Cookie: {[userO]}<br/>
14
15 <table>
16 <tr><th>User</th> <th>Last Visit</th></tr>
17 {list}
18 </table>
19
20 <h2>Set cookie value</h2>
21 <form><textbox{#User}/> <submit action={set}/></form>
22
23 <h2>Record your visit</h2>
24 <form><submit action={imHere}/></form>
25 </body></xml>
26
27 and set r =
28 setCookie username r.User;
29 main ()
30
31 and imHere () =
32 userO <- getCookie username;
33 case userO of
34 None => return <xml>You don't have a cookie set!</xml>
35 | Some user =>
36 dml (DELETE FROM lastVisit WHERE User = {[user]});
37 dml (INSERT INTO lastVisit (User, When) VALUES ({[user]}, CURRENT_TIMESTAMP));
38 main ()
39