Permalink
Browse files

handle expired cookie sessions in the example

  • Loading branch information...
1 parent 082f043 commit 247036790e0ceaae460529a8014c353aa0b2aca4 @klacke committed Dec 6, 2009
Showing with 33 additions and 12 deletions.
  1. +33 −12 www/session1.yaws
View
@@ -19,19 +19,40 @@ out(A) ->
CO = yaws_api:setcookie("baz",Cookie,"/"),
[Data, CO];
Cookie ->
- {ok, OP} = yaws_api:cookieval_to_opaque(Cookie),
- OP2 = OP#myopaque{times = OP#myopaque.times + 1},
- yaws_api:replace_cookie_session(Cookie, OP2),
- Data = {ehtml,
- {html,[],
- [
- "Click ",
- {a, [{href,"session1.yaws"}], " here "},
- "to revisit",
- {p, [], f("You have been here ~p times", [OP2#myopaque.times])},
- {p, [], f("Your cookie is ~s", [Cookie])}]}},
- Data
+ case yaws_api:cookieval_to_opaque(Cookie) of
+ {ok, OP} ->
+ OP2 = OP#myopaque{times = OP#myopaque.times + 1},
+ yaws_api:replace_cookie_session(Cookie, OP2),
+ Data = {ehtml,
+ {html,[],
+ [
+ "Click ",
+ {a, [{href,"session1.yaws"}], " here "},
+ "to revisit",
+ {p, [], f("You have been here ~p times",
+ [OP2#myopaque.times])},
+ {p, [], f("Your cookie is ~s", [Cookie])}]}},
+ Data;
+ {error, no_session} ->
+ new_session()
+ end
end.
+
+new_session() ->
+ M = #myopaque{},
+ Cookie = yaws_api:new_cookie_session(M),
+
+ Data = {ehtml,
+ {html,[],
+ ["I just set your cookie to ", Cookie, "Click ",
+ {a, [{href,"session1.yaws"}], " here "},
+
+ "to revisit"]}},
+ CO = yaws_api:setcookie("baz",Cookie,"/"),
+ [Data, CO].
+
+
+
</erl>

0 comments on commit 2470367

Please sign in to comment.