implement signup block
This commit is contained in:
parent
92a71e518f
commit
ddb26faf5c
2 changed files with 27 additions and 17 deletions
|
@ -34,24 +34,31 @@ userNew
|
||||||
:: UserSubmit
|
:: UserSubmit
|
||||||
-> MateHandler Int
|
-> MateHandler Int
|
||||||
userNew (UserSubmit ident email pass) = do
|
userNew (UserSubmit ident email pass) = do
|
||||||
now <- liftIO getCurrentTime
|
|
||||||
conn <- asks rsConnection
|
conn <- asks rsConnection
|
||||||
uid <- insertUser ident email (utctDay now) conn
|
block <- selectSignupBlocked conn
|
||||||
salt <- liftIO randomString
|
if block
|
||||||
let mpasshash = argon2 salt (encodeUtf8 pass)
|
then
|
||||||
case mpasshash of
|
throwError $ err401
|
||||||
CryptoPassed passhash -> do
|
{ errBody = "User registration has been disabled"
|
||||||
liftIO $ print passhash
|
}
|
||||||
void $ putUserAuthInfo uid PrimaryPass "Initial password" salt passhash conn
|
else do
|
||||||
CryptoFailed err ->
|
now <- liftIO getCurrentTime
|
||||||
throwError $ err500
|
uid <- insertUser ident email (utctDay now) conn
|
||||||
{ errBody = "Crypto error: " <> fromString (show err)
|
salt <- liftIO randomString
|
||||||
}
|
let mpasshash = argon2 salt (encodeUtf8 pass)
|
||||||
baseRoleId <- queryRoleIdByCapabilities
|
case mpasshash of
|
||||||
(False, False, False, False, False, False, False, False, False, False)
|
CryptoPassed passhash -> do
|
||||||
conn
|
liftIO $ print passhash
|
||||||
void $ associateUserToRole uid baseRoleId conn
|
void $ putUserAuthInfo uid PrimaryPass "Initial password" salt passhash conn
|
||||||
return uid
|
CryptoFailed err ->
|
||||||
|
throwError $ err500
|
||||||
|
{ errBody = "Crypto error: " <> fromString (show err)
|
||||||
|
}
|
||||||
|
baseRoleId <- queryRoleIdByCapabilities
|
||||||
|
(False, False, False, False, False, False, False, False, False, False)
|
||||||
|
conn
|
||||||
|
void $ associateUserToRole uid baseRoleId conn
|
||||||
|
return uid
|
||||||
|
|
||||||
userGet
|
userGet
|
||||||
:: Maybe (Int, AuthMethod)
|
:: Maybe (Int, AuthMethod)
|
||||||
|
|
|
@ -59,6 +59,9 @@ selectSettings conn = liftIO $ do
|
||||||
selectIdleTime :: PGS.Connection -> MateHandler Int
|
selectIdleTime :: PGS.Connection -> MateHandler Int
|
||||||
selectIdleTime conn = settingsIdleTime <$> selectSettings conn
|
selectIdleTime conn = settingsIdleTime <$> selectSettings conn
|
||||||
|
|
||||||
|
selectSignupBlocked :: PGS.Connection -> MateHandler Bool
|
||||||
|
selectSignupBlocked conn = settingsBlockRegistration <$> selectSettings conn
|
||||||
|
|
||||||
updateSettings :: Settings -> PGS.Connection -> MateHandler ()
|
updateSettings :: Settings -> PGS.Connection -> MateHandler ()
|
||||||
updateSettings (Settings block imprint idleTime) conn = do
|
updateSettings (Settings block imprint idleTime) conn = do
|
||||||
void $ liftIO $ runUpdate_ conn $ Update
|
void $ liftIO $ runUpdate_ conn $ Update
|
||||||
|
|
Loading…
Reference in a new issue