From 13fc158a16407f0ed2c2050bf52b88673d068398 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 15 Dec 2019 10:31:41 +0100 Subject: [PATCH] implement registration block --- app/AppTypes/Configuration.hs | 2 ++ app/Main.hs | 17 +++++++++++++---- config.yaml | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/AppTypes/Configuration.hs b/app/AppTypes/Configuration.hs index fcd47b4..7924d64 100644 --- a/app/AppTypes/Configuration.hs +++ b/app/AppTypes/Configuration.hs @@ -17,6 +17,7 @@ data ServerConfig = ServerConfig , configListenPort :: Word , configListenHost :: T.Text , configMaxConnectionsPerClient :: Word + , configBlockRegistration :: Bool } deriving (Show) @@ -31,6 +32,7 @@ instance FromYAML ServerConfig where <*> m .: "listen_port" <*> m .:? "listen_host" .!= "127.0.0.1" <*> m .:? "max_connections_per_client" .!= 10 + <*> m .: "block_registration" newtype Options = Options { optConfigLocation :: T.Text diff --git a/app/Main.hs b/app/Main.hs index 7818add..27bf487 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -60,6 +60,7 @@ main = do lport lhost max_conn_per_client + block_registration ) -> do conn <- connectPostgreSQL ( "host='" <> fromString (T.unpack db_host) <> "' " <> @@ -88,7 +89,7 @@ main = do { rsConnection = conn , rsTicketStore = store } - runSettings settings (app initState) + runSettings settings (app block_registration initState) where opts = info (options <**> helper) ( fullDesc @@ -146,9 +147,9 @@ removeFromTracker tracker saddr = do M.delete laddr tmap writeTVar tracker nmap -app :: ReadState -> Application +app :: Bool -> ReadState -> Application -- app conn = serveWithContext userApi genAuthServerContext (users conn) -app initState = +app block_registration initState = serveWithContext mateApi (genAuthServerContext (rsConnection initState)) $ hoistServerWithContext mateApi @@ -162,7 +163,15 @@ app initState = authManageNewAuth :<|> authManageDeleteAuth :<|> - userNew :<|> + ( + if block_registration + then + const $ throwError $ err406 + { errBody = "User registration is not allowed." + } + else + userNew + ) :<|> userGet :<|> userUpdate :<|> userList :<|> diff --git a/config.yaml b/config.yaml index 8ac35fa..6beb350 100644 --- a/config.yaml +++ b/config.yaml @@ -7,3 +7,4 @@ listen_port: 8000 #listen_host: "127.0.0.1" #max_connections_per_client: 10 currency: "€" +block_registration: false