1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 01:54:50 +09:00

Add settings option to disable registration

This commit is contained in:
fr33domlover 2016-04-19 16:03:27 +00:00
parent 5ae09c2ad7
commit 4c3371beda
3 changed files with 40 additions and 28 deletions

View file

@ -41,3 +41,4 @@ database:
repo-dir: repos repo-dir: repos
ssh-port: 5022 ssh-port: 5022
ssh-key-file: config/ssh-host-key ssh-key-file: config/ssh-host-key
registration: false

View file

@ -44,6 +44,9 @@ getPeopleR = do
-- | Create new user -- | Create new user
postPeopleR :: Handler Html postPeopleR :: Handler Html
postPeopleR = do postPeopleR = do
regEnabled <- appRegister . appSettings <$> getYesod
if regEnabled
then do
((result, widget), enctype) <- runFormPost formPersonNew ((result, widget), enctype) <- runFormPost formPersonNew
case result of case result of
FormSuccess pn -> do FormSuccess pn -> do
@ -68,6 +71,7 @@ postPeopleR = do
FormFailure l -> do FormFailure l -> do
setMessage $ toHtml $ intercalate "; " l setMessage $ toHtml $ intercalate "; " l
defaultLayout $(widgetFile "person-new") defaultLayout $(widgetFile "person-new")
else notFound
--TODO NEXT: --TODO NEXT:
-- * Maybe make the form return Form Person and just insert defaults (using -- * Maybe make the form return Form Person and just insert defaults (using
-- 'pure') for the remaining Person fields? Then, maybe the same form can -- 'pure') for the remaining Person fields? Then, maybe the same form can
@ -80,10 +84,14 @@ getPersonNewR = do
if isJust mpid if isJust mpid
then redirect HomeR then redirect HomeR
else do else do
regEnabled <- appRegister . appSettings <$> getYesod
if regEnabled
then do
((_result, widget), enctype) <- runFormPost formPersonNew ((_result, widget), enctype) <- runFormPost formPersonNew
defaultLayout $ do defaultLayout $ do
setTitle "Vervis > People > New" setTitle "Vervis > People > New"
$(widgetFile "person-new") $(widgetFile "person-new")
else notFound
getPersonR :: Text -> Handler Html getPersonR :: Text -> Handler Html
getPersonR ident = do getPersonR ident = do

View file

@ -75,6 +75,8 @@ data AppSettings = AppSettings
, appSshPort :: Int , appSshPort :: Int
-- | Path to the server's SSH private key file -- | Path to the server's SSH private key file
, appSshKeyFile :: FilePath , appSshKeyFile :: FilePath
-- | Whether new user accounts can be created.
, appRegister :: Bool
} }
instance FromJSON AppSettings where instance FromJSON AppSettings where
@ -101,6 +103,7 @@ instance FromJSON AppSettings where
appRepoDir <- o .: "repo-dir" appRepoDir <- o .: "repo-dir"
appSshPort <- o .: "ssh-port" appSshPort <- o .: "ssh-port"
appSshKeyFile <- o .: "ssh-key-file" appSshKeyFile <- o .: "ssh-key-file"
appRegister <- o .: "registration"
return AppSettings {..} return AppSettings {..}