diff --git a/Handler/AccountReset.hs b/Handler/AccountReset.hs index e88907e..b189f6f 100644 --- a/Handler/AccountReset.hs +++ b/Handler/AccountReset.hs @@ -10,6 +10,8 @@ import Data.Time.Clock (addUTCTime) import Handler.Common (passwordConfirmField, updatePassword, isPasswordAcceptable, tooWeakPasswordMessage) +data AccountStatus = NewlyCreated | PasswordReset + getCreateResetLinkR :: Handler Html getCreateResetLinkR = do (formWidget, formEnctype) <- generateFormPost createResetLinkForm @@ -66,8 +68,17 @@ newVerifyKey = Nonce.nonce128urlT nonceGen getResetPasswordR :: Text -> Handler Html getResetPasswordR key = do - (formWidget, formEnctype) <- generateFormPost changePasswordForm mUserId <- checkVerificationKey key + accountStatus <- case mUserId of + (Just userId) -> do + user <- runDB$ get404 userId + return $ if isJust (userPassword user) + then + PasswordReset + else + NewlyCreated + _ -> return PasswordReset + (formWidget, formEnctype) <- generateFormPost $ changePasswordForm accountStatus master <- getYesod defaultLayout $ do setTitle "Reset password" @@ -75,7 +86,7 @@ getResetPasswordR key = do postResetPasswordR :: Text -> Handler Html postResetPasswordR key = do - ((result, _), _) <- runFormPost changePasswordForm + ((result, _), _) <- runFormPost $ changePasswordForm PasswordReset mUserId <- checkVerificationKey key let mPassword = case result of FormSuccess password -> Just password @@ -120,6 +131,9 @@ checkVerificationKey key = do [Entity k _] -> Just k _ -> Nothing -changePasswordForm :: Form Text -changePasswordForm = renderBootstrap3 BootstrapBasicForm - $ areq passwordConfirmField (bfs MsgPassword) Nothing +changePasswordForm :: AccountStatus -> Form Text +changePasswordForm accountStatus = renderBootstrap3 BootstrapBasicForm + $ areq passwordConfirmField (bfs $ passwordFormHeader accountStatus) Nothing + +passwordFormHeader NewlyCreated = MsgPasswordForNewAccount +passwordFormHeader PasswordReset = MsgPassword diff --git a/Handler/Common.hs b/Handler/Common.hs index b11e5f1..b85cdc2 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -32,7 +32,7 @@ passwordConfirmField = Field , fieldView = \idAttr nameAttr otherAttrs _ _ -> [whamlet| -
confirm new password: +
re-enter the password |] , fieldEnctype = UrlEncoded diff --git a/messages/en.msg b/messages/en.msg index e80a21a..c8efede 100644 --- a/messages/en.msg +++ b/messages/en.msg @@ -26,7 +26,7 @@ CommentText: Write a comment Send: Send Avatar: avatar About: about -Password: new password +Password: enter a new password for your account EMail: e-mail CreateResetLink: create reset link LinkWrongOrExpired: Link wrong or expired, please ask the site admin again @@ -43,3 +43,4 @@ Achievements: achievements AchievementPoints: points WantToBeAnonimised: I want to stay anonymous for other user of Gonito.net YourScore: your score +PasswordForNewAccount: enter a password for your new account diff --git a/templates/reset-link-created.hamlet b/templates/reset-link-created.hamlet index cccfb9b..1b5b172 100644 --- a/templates/reset-link-created.hamlet +++ b/templates/reset-link-created.hamlet @@ -1 +1,3 @@

Reset link created: @{ResetPasswordR key} + +

Now you can send the link to the user.