diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2015-10-13 00:06:55 -0400 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2015-10-13 00:06:55 -0400 |
commit | 1276bc232e1f1adfafe264130c91658052be8190 (patch) | |
tree | 9d66dba8da5f2d071d81e536214dc02b0b842459 | |
parent | 9aa7f0001830bf6fa2fbb38b9946dc24815fd0e0 (diff) |
Begin integrating Authentication to Main.
-rw-r--r-- | src/Authentication.hs | 2 | ||||
-rw-r--r-- | src/Main.hs | 21 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/Authentication.hs b/src/Authentication.hs index 0a0a49f..bc00863 100644 --- a/src/Authentication.hs +++ b/src/Authentication.hs @@ -4,7 +4,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TemplateHaskell #-} -module Authentication (User, queryUser) where +module Authentication (User, queryUser, isAuthenticated) where import Data.Aeson import Data.Maybe diff --git a/src/Main.hs b/src/Main.hs index 17e3d70..d4c7fd4 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -6,19 +6,21 @@ {-# LANGUAGE TemplateHaskell #-} module Main where +import Control.Concurrent.MVar +import Control.Monad +import Control.Monad.IO.Class +import Control.Monad.Trans.Either import Data.Aeson import GHC.Generics +import HFlags import Network.Wai import Network.Wai.Handler.Warp +import Network.Wai.Middleware.RequestLogger import Servant -import HFlags import System.Exit -import Control.Monad -import Control.Monad.IO.Class -import Control.Monad.Trans.Either -import Network.Wai.Middleware.RequestLogger +import System.IO.Unsafe (unsafePerformIO) -import Authentication +import qualified Authentication import Data import PhotoStore @@ -26,6 +28,7 @@ defineFlag "port" (8081 :: Int) "Port to serve on" defineFlag "host" ("*6" :: String) "Host to serve on (*6 for ipv6 mode)" defineFlag "pending_path" ("" :: String) "Path to pending albums" defineFlag "photos_path" ("" :: String) "Path to permanent albums" +defineFlag "allowed_users" ("" :: String) "Comma separated list of emails" $(return []) -- Somehow forces the flags to be set. instance ToJSON Album @@ -44,6 +47,10 @@ type PhotoApi = :<|> "test" :> Header "X-Token" String :> Get '[JSON] () -- Introduce request header containing auth information. +isAuthenticated = Authentication.isAuthenticated users cache + where users = ["kjetil.orbekk@gmail.com"] + cache = unsafePerformIO (newMVar []) + config = Config { pendingPath = flags_pending_path , photosPath = flags_photos_path @@ -59,7 +66,7 @@ server = albums rename (RenameRequest from to) = liftIO $ runEitherT (renameAlbum config from to) - test (Just token) = liftIO (putStrLn $ "Got token: " ++ token) + test (Just token) = liftIO (putStrLn $ "Is authenticated" ++ token) test _ = left err503 { errBody = "Not authenticated" } photoApi :: Proxy PhotoApi |