From 9d56f91b008935fa151fe75d46da6e910dcfce96 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sun, 26 Feb 2017 09:54:05 +0100 Subject: [PATCH] fix setting your account without changing the password --- Handler/Common.hs | 1 + Handler/YourAccount.hs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Handler/Common.hs b/Handler/Common.hs index f104fd1..8de20ec 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -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)] diff --git a/Handler/YourAccount.hs b/Handler/YourAccount.hs index 5815db2..57ecd9e 100644 --- a/Handler/YourAccount.hs +++ b/Handler/YourAccount.hs @@ -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 ()