Webanwendung mit FastCGI und Haskell
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

36 lignes
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