From cf59abd2b8072eaad961e57a414830237bf10cd9 Mon Sep 17 00:00:00 2001 From: Arian van Putten Date: Fri, 2 Oct 2015 14:12:16 +0200 Subject: [PATCH] Fix compiler errors in servant-examples. --- servant-examples/digest-auth/digest-auth.hs | 33 +++++++++++++++++++++ servant-examples/tutorial/T9.hs | 9 +++--- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 servant-examples/digest-auth/digest-auth.hs diff --git a/servant-examples/digest-auth/digest-auth.hs b/servant-examples/digest-auth/digest-auth.hs new file mode 100644 index 00000000..ff36c6da --- /dev/null +++ b/servant-examples/digest-auth/digest-auth.hs @@ -0,0 +1,33 @@ +{-#LANGUAGE DataKinds, TypeOperators, OverloadedStrings #-} +module Main where + +import Data.Text +import Data.ByteString (ByteString) +import Data.Proxy +import Servant.API +import Servant.API.Authentication +import Servant.Server +import Servant.Server.Internal.Authentication +import Network.Wai.Handler.Warp + + +data User = User + { username :: ByteString + , ha1 :: ByteString -- ^ MD5(username:realm:password) + } + + +-- | A table with just one user. namely "username:foo:password" +table = [("username", User "username" "22f93fe54b9edf660a2f85310adc8a56")] + +type API = AuthProtect (DigestAuth "foo") User 'Strict :> "foo" :> Get '[JSON] Text + +api :: Server API +api = digestAuthStrict ha1 lookupUser (const . return $ "hello") + +lookupUser :: DigestAuth "foo" -> IO (Maybe User) +lookupUser authData = return . lookup (daUsername authData) $ table + + +main :: IO () +main = run 8080 (serve (Proxy :: Proxy API) api) diff --git a/servant-examples/tutorial/T9.hs b/servant-examples/tutorial/T9.hs index 365f6e54..75dd0630 100644 --- a/servant-examples/tutorial/T9.hs +++ b/servant-examples/tutorial/T9.hs @@ -16,6 +16,7 @@ import Servant.JS import System.Random import qualified Data.Text as T +import qualified Data.Text.IO as TIO import qualified Language.Javascript.JQuery as JQ data Point = Point @@ -91,14 +92,14 @@ server' :: Server API' server' = server :<|> serveDirectory "tutorial/t9" -apiJS :: String +apiJS :: Text apiJS = jsForAPI api jquery writeJSFiles :: IO () writeJSFiles = do - writeFile "tutorial/t9/api.js" apiJS - jq <- readFile =<< JQ.file - writeFile "tutorial/t9/jq.js" jq + TIO.writeFile "tutorial/t9/api.js" apiJS + jq <- TIO.readFile =<< JQ.file + TIO.writeFile "tutorial/t9/jq.js" jq app :: Application app = serve api' server'