implement registration block

This commit is contained in:
nek0 2019-12-15 10:31:41 +01:00
parent e176fdbd10
commit 13fc158a16
3 changed files with 16 additions and 4 deletions

View File

@ -17,6 +17,7 @@ data ServerConfig = ServerConfig
, configListenPort :: Word , configListenPort :: Word
, configListenHost :: T.Text , configListenHost :: T.Text
, configMaxConnectionsPerClient :: Word , configMaxConnectionsPerClient :: Word
, configBlockRegistration :: Bool
} }
deriving (Show) deriving (Show)
@ -31,6 +32,7 @@ instance FromYAML ServerConfig where
<*> m .: "listen_port" <*> m .: "listen_port"
<*> m .:? "listen_host" .!= "127.0.0.1" <*> m .:? "listen_host" .!= "127.0.0.1"
<*> m .:? "max_connections_per_client" .!= 10 <*> m .:? "max_connections_per_client" .!= 10
<*> m .: "block_registration"
newtype Options = Options newtype Options = Options
{ optConfigLocation :: T.Text { optConfigLocation :: T.Text

View File

@ -60,6 +60,7 @@ main = do
lport lport
lhost lhost
max_conn_per_client max_conn_per_client
block_registration
) -> do ) -> do
conn <- connectPostgreSQL ( conn <- connectPostgreSQL (
"host='" <> fromString (T.unpack db_host) <> "' " <> "host='" <> fromString (T.unpack db_host) <> "' " <>
@ -88,7 +89,7 @@ main = do
{ rsConnection = conn { rsConnection = conn
, rsTicketStore = store , rsTicketStore = store
} }
runSettings settings (app initState) runSettings settings (app block_registration initState)
where where
opts = info (options <**> helper) opts = info (options <**> helper)
( fullDesc ( fullDesc
@ -146,9 +147,9 @@ removeFromTracker tracker saddr = do
M.delete laddr tmap M.delete laddr tmap
writeTVar tracker nmap writeTVar tracker nmap
app :: ReadState -> Application app :: Bool -> ReadState -> Application
-- app conn = serveWithContext userApi genAuthServerContext (users conn) -- app conn = serveWithContext userApi genAuthServerContext (users conn)
app initState = app block_registration initState =
serveWithContext mateApi (genAuthServerContext (rsConnection initState)) $ serveWithContext mateApi (genAuthServerContext (rsConnection initState)) $
hoistServerWithContext hoistServerWithContext
mateApi mateApi
@ -162,7 +163,15 @@ app initState =
authManageNewAuth :<|> authManageNewAuth :<|>
authManageDeleteAuth :<|> authManageDeleteAuth :<|>
userNew :<|> (
if block_registration
then
const $ throwError $ err406
{ errBody = "User registration is not allowed."
}
else
userNew
) :<|>
userGet :<|> userGet :<|>
userUpdate :<|> userUpdate :<|>
userList :<|> userList :<|>

View File

@ -7,3 +7,4 @@ listen_port: 8000
#listen_host: "127.0.0.1" #listen_host: "127.0.0.1"
#max_connections_per_client: 10 #max_connections_per_client: 10
currency: "€" currency: "€"
block_registration: false