implement registration block
This commit is contained in:
parent
e176fdbd10
commit
13fc158a16
3 changed files with 16 additions and 4 deletions
|
@ -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
|
||||
|
|
17
app/Main.hs
17
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 :<|>
|
||||
|
|
|
@ -7,3 +7,4 @@ listen_port: 8000
|
|||
#listen_host: "127.0.0.1"
|
||||
#max_connections_per_client: 10
|
||||
currency: "€"
|
||||
block_registration: false
|
||||
|
|
Loading…
Reference in a new issue