fix setting your account without changing the password

This commit is contained in:
Filip Gralinski 2017-02-26 09:54:05 +01:00
parent 3e3d94a589
commit 9d56f91b00
2 changed files with 7 additions and 2 deletions

View File

@ -40,6 +40,7 @@ passwordConfirmField = Field
updatePassword :: Key User -> Maybe Text -> Handler ()
updatePassword _ Nothing = return ()
updatePassword _ (Just "") = return ()
updatePassword userId (Just password) = do
encodedPassword <- liftIO $ makePassword (encodeUtf8 password) defaultStrength
runDB $ update userId [UserPassword =. Just (decodeUtf8 encodedPassword)]

View File

@ -44,8 +44,9 @@ postYourAccountR = do
$(widgetFile "your-account")
checkPassword :: Maybe Text -> Bool
checkPassword Nothing = True
checkPassword (Just "") = True
checkPassword (Just passwd) = isPasswordAcceptable passwd
checkPassword Nothing = False
yourAccountForm :: Maybe Text -> Maybe Text -> Maybe Text -> Form (Maybe Text, Maybe Text, Maybe Text, Maybe Text, Maybe FileInfo)
yourAccountForm maybeName maybeLocalId maybeSshPubKey = renderBootstrap3 BootstrapBasicForm $ (,,,,)
@ -74,7 +75,10 @@ updateUserAccount userId name maybeLocalId maybePassword maybeSshPubKey maybeAva
updateJustName userId name
updateAvatar userId maybeAvatarFile
updateLocalIdAndPubKey userId maybeLocalId maybeSshPubKey
updatePassword userId maybePassword
case maybePassword of
Nothing -> return ()
Just "" -> return ()
Just p -> updatePassword userId (Just p)
updateAvatar :: Key User -> Maybe FileInfo -> Handler ()
updateAvatar _ Nothing = return ()