<h3>Cookies</h3>
<p>Cookies don't work quite right in Happstack out of the box. The most common problem
is that google analytics and Happstack session cookies are mutually incompatible.
(There is a thread about what went wrong in the initial implementation in the happs googlegroup.)
<p>Support for cookies will be improved in future Happstack releases.
<p>Meanwhile, there is a workaround in the happstack-helpers package on hackage, which is used by happs-tutorial,
and is built into smartserver.
So cookies do work in happs-tutorial: I use google analytics to track visitors,
along with normal Happstack session cookies.
And if you use happs-tutorial as a template for your apps you should be fine.
<p>Besides the cookies used by google analytics, which are obfuscated by javascript, happs-tutorial
uses cookies to track session state -- the data that corresponds to the current user's session in
<br>
<br>data AppState = AppState {
<br> appsessions :: Sessions SessionData,
<br> appdatastore :: Users
<br>} deriving (Show,Read,Typeable,Data)
<p>When you log in, a cookie is created that expires in an hour
(3600 seconds). And every time a happstack handler needs to check if a user is logged in (for example,
when it needs to decide whether to show the logged-in-user menubar) a check is made to see if a cookie
has been set.
<p>The cookie code is in <a href=/projectroot/src/Misc.hs>ControllerMisc.hs</a>:
<br>
<br>startsess' getLandingpage (RenderGlobals origRq ts _) user = do
<br> let sd = SessionData user
<br> key <- update \$ NewSession sd
<br> addCookie (3600) (mkCookie "sid" (show key))
<br> .....
<br>
<br>getMbSessKey rq = runReaderT (readCookieValue "sid") (rqInputs rq,rqCookies rq)
<p>We've spent a good bit of time now on how happstack-server handles requests,
so we're ready to move on to the major feature of happstack-state,
<a href="/tutorial/introductiontomacid">MACID</a>.