1. new in this version
  2. build a web 2.0 app in happstack
  3. why happstack is cool
  4. getting started with happstack
  5. prerequisites
  6. cabal install me
  7. first shot at happstack
  8. url handling
  9. basic HTML inclusion
  10. templates
  11. stringtemplate basics
  12. debugging
  13. form data: get and post
  14. form data: file uploads
  15. cookies
  16. introduction to macid
  17. first steps with macid
  18. scaling with multimaster
  19. using macid safely
  20. macid dummy data
  21. changing the data model
  22. macid stress test
  23. limitations of macid
  24. foreign characters
  25. IxSets
  26. cron jobs
  27. thanks
  28. appendix (floundering in ghci)

Cookies

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

data AppState = AppState {
appsessions :: Sessions SessionData,
appdatastore :: Users
} deriving (Show,Read,Typeable,Data)

When you log in, a cookie is created that expires in an hour (3600 seconds). 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.

The cookie code is in ControllerMisc.hs:

startsess' getLandingpage (RenderGlobals origRq ts _) user = do
let sd = SessionData user
key <- update $ NewSession sd
addCookie (3600) (mkCookie "sid" (show key))
.....

getMbSessKey rq = runReaderT (readCookieValue "sid") (rqInputs rq,rqCookies rq)

As you can see, the basic use of cookies is surprisingly simple with the two functions addCookie and mkCookie

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, MACID.