Webanwendung mit FastCGI und Haskell
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 line
898B

  1. {-# LANGUAGE ExistentialQuantification #-}
  2. module Request (
  3. RequestHandler(..), handlePath
  4. ) where
  5. import Network.URI
  6. import Network.FastCGI
  7. import Text.Regex.PCRE
  8. import Database
  9. import AppMonad
  10. class RequestHandler a where
  11. handle :: a -> App CGIResult
  12. requireLogin :: a -> Bool
  13. requireLogin _ = False
  14. handleRequest :: a -> App CGIResult
  15. handleRequest x = do
  16. status <- isLoggedIn
  17. path <- uriPath <$> requestURI
  18. if not status && requireLogin x
  19. then redirect $ "/login?from=" ++ path
  20. else handle x
  21. data RH = forall h. RequestHandler h => RH h
  22. instance RequestHandler RH where
  23. requireLogin (RH x) = requireLogin x
  24. handle (RH x) = handle x
  25. handlePath :: RequestHandler a => String -> String -> a -> Maybe RH
  26. handlePath path pattern handler
  27. | path =~ pattern = Just (RH handler)
  28. | otherwise = Nothing