1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 18:04:53 +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
ssh-port: 5022
ssh-key-file: config/ssh-host-key
registration: false

View file

@ -44,30 +44,34 @@ getPeopleR = do
-- | Create new user
postPeopleR :: Handler Html
postPeopleR = do
((result, widget), enctype) <- runFormPost formPersonNew
case result of
FormSuccess pn -> do
runDB $ do
let sharer = Sharer
{ sharerIdent = uLogin pn
, sharerName = Nothing
}
sid <- insert sharer
let person = Person
{ personIdent = sid
, personLogin = uLogin pn
, personHash = Nothing
, personEmail = uEmail pn
}
person' <- setPassword (uPass pn) person
insert_ person'
redirectUltDest HomeR
FormMissing -> do
setMessage "Field(s) missing"
defaultLayout $(widgetFile "person-new")
FormFailure l -> do
setMessage $ toHtml $ intercalate "; " l
defaultLayout $(widgetFile "person-new")
regEnabled <- appRegister . appSettings <$> getYesod
if regEnabled
then do
((result, widget), enctype) <- runFormPost formPersonNew
case result of
FormSuccess pn -> do
runDB $ do
let sharer = Sharer
{ sharerIdent = uLogin pn
, sharerName = Nothing
}
sid <- insert sharer
let person = Person
{ personIdent = sid
, personLogin = uLogin pn
, personHash = Nothing
, personEmail = uEmail pn
}
person' <- setPassword (uPass pn) person
insert_ person'
redirectUltDest HomeR
FormMissing -> do
setMessage "Field(s) missing"
defaultLayout $(widgetFile "person-new")
FormFailure l -> do
setMessage $ toHtml $ intercalate "; " l
defaultLayout $(widgetFile "person-new")
else notFound
--TODO NEXT:
-- * Maybe make the form return Form Person and just insert defaults (using
-- 'pure') for the remaining Person fields? Then, maybe the same form can
@ -80,10 +84,14 @@ getPersonNewR = do
if isJust mpid
then redirect HomeR
else do
((_result, widget), enctype) <- runFormPost formPersonNew
defaultLayout $ do
setTitle "Vervis > People > New"
$(widgetFile "person-new")
regEnabled <- appRegister . appSettings <$> getYesod
if regEnabled
then do
((_result, widget), enctype) <- runFormPost formPersonNew
defaultLayout $ do
setTitle "Vervis > People > New"
$(widgetFile "person-new")
else notFound
getPersonR :: Text -> Handler Html
getPersonR ident = do

View file

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