yesod/yesod-examples/src/session.lhs
Michael Snoyman 41faf62094 Add 'yesod-examples/' from commit '851f928e55b3646f7790b6cc70968957cca04a4b'
git-subtree-dir: yesod-examples
git-subtree-mainline: 2dc10de435
git-subtree-split: 851f928e55
2011-07-22 08:59:56 +03:00

32 lines
868 B
Plaintext

> {-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, OverloadedStrings #-}
> import Yesod
> import Control.Applicative ((<$>), (<*>))
>
> data Session = Session
> type Handler = GHandler Session Session
> mkYesod "Session" [$parseRoutes|
> / Root GET POST
> |]
> getRoot :: Handler RepHtml
> getRoot = do
> sess <- getSession
> hamletToRepHtml [$hamlet|
> <form method=post
> <input type=text name=key
> <input type=text name=val
> <input type=submit
> <h1>#{show sess}
> |]
>
> postRoot :: Handler ()
> postRoot = do
> (key, val) <- runFormPost' $ (,) <$> stringInput "key" <*> stringInput "val"
> setSession key val
> liftIO $ print (key, val)
> redirect RedirectTemporary Root
>
> instance Yesod Session where
> approot _ = ""
> clientSessionDuration _ = 1
> main = warpDebug 3000 Session