Most recent attempt etc changes
This commit is contained in:
parent
4262ffb38f
commit
3a7c803744
@ -23,11 +23,10 @@ module Web.Restful.Application
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Web.Encodings
|
import Web.Encodings
|
||||||
import Data.Object
|
|
||||||
import Data.Object.Text
|
import Data.Object.Text
|
||||||
|
import Data.Object.String
|
||||||
import Data.Enumerable
|
import Data.Enumerable
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import qualified Data.Text.Lazy as LT
|
|
||||||
|
|
||||||
import qualified Hack
|
import qualified Hack
|
||||||
import Hack.Middleware.CleanPath
|
import Hack.Middleware.CleanPath
|
||||||
@ -61,15 +60,16 @@ class ResourceName a => RestfulApp a where
|
|||||||
|
|
||||||
-- | Output error response pages.
|
-- | Output error response pages.
|
||||||
errorHandler :: Monad m => a -> RawRequest -> ErrorResult -> [RepT m] -- FIXME better type sig?
|
errorHandler :: Monad m => a -> RawRequest -> ErrorResult -> [RepT m] -- FIXME better type sig?
|
||||||
errorHandler _ rr NotFound = reps $ toTextObject $ "Not found: " ++ show rr
|
errorHandler _ rr NotFound = reps $ toTextObject $
|
||||||
|
"Not found: " ++ show rr
|
||||||
errorHandler _ _ (Redirect url) =
|
errorHandler _ _ (Redirect url) =
|
||||||
reps $ toTextObject $ "Redirect to: " ++ url
|
reps $ toTextObject $ "Redirect to: " ++ url
|
||||||
errorHandler _ _ (InternalError e) =
|
errorHandler _ _ (InternalError e) =
|
||||||
reps $ toTextObject $ "Internal server error: " ++ e
|
reps $ toTextObject $ "Internal server error: " ++ e
|
||||||
errorHandler _ _ (InvalidArgs ia) =
|
errorHandler _ _ (InvalidArgs ia) =
|
||||||
reps $ Mapping
|
reps $ toTextObject $ toStringObject
|
||||||
[ (LT.pack "errorMsg", toTextObject "Invalid arguments")
|
[ ("errorMsg", toStringObject "Invalid arguments")
|
||||||
, (LT.pack "messages", toTextObject ia)
|
, ("messages", toStringObject ia)
|
||||||
]
|
]
|
||||||
errorHandler _ _ PermissionDenied =
|
errorHandler _ _ PermissionDenied =
|
||||||
reps $ toTextObject "Permission denied"
|
reps $ toTextObject "Permission denied"
|
||||||
|
|||||||
@ -89,8 +89,8 @@ runHandler h rr cts = do
|
|||||||
takeAllExceptions :: IO (Attempt x) -> IO (Attempt x)
|
takeAllExceptions :: IO (Attempt x) -> IO (Attempt x)
|
||||||
takeAllExceptions ioa =
|
takeAllExceptions ioa =
|
||||||
Control.Exception.catch ioa (return . someFailure)
|
Control.Exception.catch ioa (return . someFailure)
|
||||||
someFailure :: Control.Exception.SomeException -> Attempt v
|
someFailure :: Control.Exception.SomeException -> Attempt v -- FIXME
|
||||||
someFailure = Failure
|
someFailure = failure
|
||||||
toErrorResult :: Exception e => e -> ErrorResult
|
toErrorResult :: Exception e => e -> ErrorResult
|
||||||
toErrorResult e =
|
toErrorResult e =
|
||||||
case cast e of
|
case cast e of
|
||||||
|
|||||||
@ -107,23 +107,23 @@ authOpenidForward = do
|
|||||||
show (Hack.serverPort env) ++
|
show (Hack.serverPort env) ++
|
||||||
"/auth/openid/complete/"
|
"/auth/openid/complete/"
|
||||||
res <- runAttemptT $ OpenId.getForwardUrl oid complete
|
res <- runAttemptT $ OpenId.getForwardUrl oid complete
|
||||||
case res of
|
attempt
|
||||||
Failure err -> redirect $ "/auth/openid/?message="
|
(\err -> redirect $ "/auth/openid/?message=" ++ encodeUrl (show err))
|
||||||
++ encodeUrl (show err)
|
redirect
|
||||||
Success url -> redirect url
|
res
|
||||||
|
|
||||||
authOpenidComplete :: Handler
|
authOpenidComplete :: Handler
|
||||||
authOpenidComplete = do
|
authOpenidComplete = do
|
||||||
gets' <- rawGetParams <$> askRawRequest
|
gets' <- rawGetParams <$> askRawRequest
|
||||||
dest <- cookieParam "DEST"
|
dest <- cookieParam "DEST"
|
||||||
res <- runAttemptT $ OpenId.authenticate gets'
|
res <- runAttemptT $ OpenId.authenticate gets'
|
||||||
case res of
|
let onFailure err = redirect $ "/auth/openid/?message="
|
||||||
Failure err -> redirect $ "/auth/openid/?message="
|
|
||||||
++ encodeUrl (show err)
|
++ encodeUrl (show err)
|
||||||
Success (OpenId.Identifier ident) -> do
|
let onSuccess (OpenId.Identifier ident) = do
|
||||||
deleteCookie "DEST"
|
deleteCookie "DEST"
|
||||||
header authCookieName ident
|
header authCookieName ident
|
||||||
redirect $ fromMaybe "/" dest
|
redirect $ fromMaybe "/" dest
|
||||||
|
attempt onFailure onSuccess res
|
||||||
|
|
||||||
-- | token dest
|
-- | token dest
|
||||||
data RpxnowRequest = RpxnowRequest String (Maybe String)
|
data RpxnowRequest = RpxnowRequest String (Maybe String)
|
||||||
|
|||||||
@ -46,7 +46,7 @@ getStatic fl = do
|
|||||||
content <- liftIO $ fl fp
|
content <- liftIO $ fl fp
|
||||||
case content of
|
case content of
|
||||||
Nothing -> notFound
|
Nothing -> notFound
|
||||||
Just bs -> return $ genResponse (mimeType $ ext fp) bs
|
Just bs -> return [(mimeType $ ext fp, return $ toContent bs)]
|
||||||
|
|
||||||
mimeType :: String -> String
|
mimeType :: String -> String
|
||||||
mimeType "jpg" = "image/jpeg"
|
mimeType "jpg" = "image/jpeg"
|
||||||
|
|||||||
@ -48,6 +48,7 @@ import Data.Object
|
|||||||
import Data.Object.Text
|
import Data.Object.Text
|
||||||
import Data.Object.Translate
|
import Data.Object.Translate
|
||||||
import Data.Object.Instances
|
import Data.Object.Instances
|
||||||
|
import qualified Data.ByteString as SBS
|
||||||
import qualified Data.ByteString.Lazy as LBS
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
import qualified Data.Text.Lazy as LT
|
import qualified Data.Text.Lazy as LT
|
||||||
import qualified Data.Text.Lazy.Encoding as LTE
|
import qualified Data.Text.Lazy.Encoding as LTE
|
||||||
@ -78,6 +79,8 @@ runContent ls (TransText t) = LTE.encodeUtf8 $ t ls
|
|||||||
|
|
||||||
class ToContent a where
|
class ToContent a where
|
||||||
toContent :: a -> Content
|
toContent :: a -> Content
|
||||||
|
instance ToContent SBS.ByteString where
|
||||||
|
toContent = ByteString . convertSuccess
|
||||||
instance ToContent LBS.ByteString where
|
instance ToContent LBS.ByteString where
|
||||||
toContent = ByteString
|
toContent = ByteString
|
||||||
instance ToContent String where
|
instance ToContent String where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user