{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverloadedStrings, RecordWildCards, TemplateHaskell, TypeFamilies, TypeSynonymInstances, OverloadedStrings #-} {-# OPTIONS_GHC -F -pgmFhsx2hs #-} module Tiny.PagesAuth ( route ) where import Data.Text (Text) import qualified Data.Text as Text (null, unpack) import qualified Data.Text.Lazy as Lazy (pack, Text) import Data.Time.Clock (getCurrentTime) import HSP (toName) import HSP.XML as HTML (Attribute(MkAttr), pAttrVal, XML(CDATA)) import Happstack.Auth (AuthProfileURL, getUserId, handleAuthProfile, AuthState, ProfileState) import Happstack.Foundation ((++>), (<$>), (<++), Applicative((<*), (<*>)), asContentType, Attr(..), EmbedAsAttr(..), EmbedAsChild(..), errorList, fieldset, form, fromStringLit, Happstack, inputSubmit, inputText, label, li, liftM, method, Method(GET), MonadIO(liftIO), nestURL, notFound, ok, PathInfo(toPathSegments), query, reform, Response, RouteT, seeOtherURL, select, serveFile, showURL, textarea, ToMessage(toResponse), transformEither, transformEitherM, ul, update, whereami, XMLGen(..), XMLGenerator, XMLGenT(XMLGenT), AcidState, HasAcidState(..)) import Text.Blaze.Html (Html) import Text.Blaze.Html.Renderer.Text (renderHtml) import Tiny.Events (GetPasteById(GetPasteById), GetRecentPastes(GetRecentPastes), InsertPaste(InsertPaste)) import Tiny.RouteAuth (App, AppForm, Route(..)) import Tiny.TemplateAuth (appTemplateHSP, appTemplateBlaze) import Tiny.Types (Format(..), Paste(..), PasteId(..), PasteMeta(PasteMeta, format, nickname, pasteId, pasted, title)) ------------------------------------------------------------------------------ -- Pages ------------------------------------------------------------------------------ -- | page handler for 'ViewRecent' viewRecentPage :: App Response viewRecentPage = do method GET recent <- query (GetRecentPastes 20 0) case recent of [] -> appTemplateHSP "Recent Pastes" ()
There are no pastes yet.
_ -> appTemplateHSP "Recent Pastes" () $ <%>| id | title | author | date | format |
|---|
Paste <% pid %> could not be found.
(Just (Paste (PasteMeta{..}) paste)) -> do ok () appTemplateHSP (Lazy.pack $ "Paste " ++ (show $ unPasteId pid)) () $<% txt %>-- | page handler for 'NewPaste' newPastePage :: App Response newPastePage = do here <- whereami acidAuth <- getAcidState acidProfile <- getAcidState mUserId <- getUserId acidAuth acidProfile case mUserId of Nothing -> appTemplateHSP "Add a Paste" () $ <%>