comparison demo/cookie.ur @ 1050:93315ac00394

More fun with cookies
author Adam Chlipala <adamc@hcoop.net>
date Thu, 26 Nov 2009 14:20:00 -0500
parents ddd363e856ff
children
comparison
equal deleted inserted replaced
1049:c2317cfb99ec 1050:93315ac00394
1 cookie c : {A : string, B : float, C : int} 1 cookie c : {A : string, B : float, C : int}
2 2
3 fun set r = 3 fun set r =
4 setCookie c {A = r.A, B = readError r.B, C = readError r.C}; 4 setCookie c {Value = {A = r.A, B = readError r.B, C = readError r.C},
5 Expires = None,
6 Secure = False};
5 return <xml>Cookie set.</xml> 7 return <xml>Cookie set.</xml>
8
9 fun setExp r =
10 setCookie c {Value = {A = r.A, B = readError r.B, C = readError r.C},
11 Expires = Some (readError "2012-11-6 00:00:00"),
12 Secure = False};
13 return <xml>Cookie set robustly.</xml>
14
15 fun delete () =
16 clearCookie c;
17 return <xml>Cookie cleared.</xml>
6 18
7 fun main () = 19 fun main () =
8 ro <- getCookie c; 20 ro <- getCookie c;
9 return <xml><body> 21 return <xml><body>
10 {case ro of 22 {case ro of
11 None => <xml>No cookie set.</xml> 23 None => <xml>No cookie set.</xml>
12 | Some v => <xml>Cookie: A = {[v.A]}, B = {[v.B]}, C = {[v.C]}</xml>} 24 | Some v => <xml>
25 Cookie: A = {[v.A]}, B = {[v.B]}, C = {[v.C]}<br/>
26 <form><submit value="Delete" action={delete}/></form>
27 </xml>}
13 <br/><br/> 28 <br/><br/>
14 29
15 <form> 30 <form>
16 A: <textbox{#A}/><br/> 31 A: <textbox{#A}/><br/>
17 B: <textbox{#B}/><br/> 32 B: <textbox{#B}/><br/>
18 C: <textbox{#C}/><br/> 33 C: <textbox{#C}/><br/>
19 <submit action={set}/> 34 <submit action={set}/>
35 </form><br/>
36
37 <form>
38 <b>Version that expires on November 6, 2012:</b><br/>
39 A: <textbox{#A}/><br/>
40 B: <textbox{#B}/><br/>
41 C: <textbox{#C}/><br/>
42 <submit action={setExp}/>
20 </form> 43 </form>
21 </body></xml> 44 </body></xml>