Created
September 25, 2012 14:20
-
-
Save adinapoli/3782217 to your computer and use it in GitHub Desktop.
MusicStore snaplet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Blackbox.MusicStoreSnaplet where | |
------------------------------------------------------------------------------ | |
import Control.Applicative | |
import qualified Data.ByteString.Char8 as B | |
import Data.Lens.Lazy | |
import Data.Lens.Template | |
------------------------------------------------------------------------------ | |
import Heist | |
import Heist.Interpreted | |
import Snap.Core | |
import Snap.Snaplet | |
import Snap.Snaplet.Auth | |
import Snap.Snaplet.Auth.Backends.JsonFile | |
import Snap.Snaplet.Heist | |
import Snap.Snaplet.Session | |
import Snap.Snaplet.Session.Backends.CookieSession | |
------------------------------------------------------------------------------ | |
-- Being an App composed by reusable pieces (aka Snaplets), we | |
-- can compose our application with pre-existing snaplets shipped | |
-- with Snap. | |
data MusicStoreApp = MusicStoreApp | |
{ _heist :: Snaplet (Heist MusicStoreApp) | |
-- ^ we want template support. | |
, _sess :: Snaplet SessionManager | |
-- ^ mandatory to use authentication. | |
, _auth :: Snaplet (AuthManager MusicStoreApp) | |
-- ^ we want authentication functionality. | |
} | |
makeLenses [''MusicStoreApp] | |
musicStoreInit :: SnapletInit MusicStoreApp MusicStoreApp | |
musicStoreInit = makeSnaplet "musicstore" "Best shop in town" Nothing $ do | |
hs <- nestSnaplet "heist" heist $ heistInit "templates" | |
s <- nestSnaplet "sess" sess $ | |
initCookieSessionManager "site_key.txt" "sess" (Just 3600) | |
a <- nestSnaplet "auth" auth $ | |
initJsonFileAuthManager defAuthSettings sess "users.json" | |
addRoutes [ ("/about", writeText "We sell music online") ] | |
return $ MusicStoreApp hs s a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment