diff --git a/yesod-auth/Yesod/Auth/Email.hs b/yesod-auth/Yesod/Auth/Email.hs index 0e5580e4..b9dba026 100644 --- a/yesod-auth/Yesod/Auth/Email.hs +++ b/yesod-auth/Yesod/Auth/Email.hs @@ -107,6 +107,7 @@ data EmailCreds site = EmailCreds , emailCredsEmail :: Email } +data PasswordForm = PasswordForm { passwordCurrent :: Text, passwordNew :: Text, passwordConfirm :: Text } data UserForm = UserForm { email :: Text } data UserLoginForm = UserLoginForm { loginEmail :: Text, loginPassword :: Text } @@ -516,40 +517,77 @@ getPasswordR = do -- Since: 1.2.6 defaultSetPasswordHandler :: YesodAuthEmail master => Bool -> AuthHandler master TypedContent defaultSetPasswordHandler needOld = do - tp <- getRouteToParent - pass0 <- newIdent - pass1 <- newIdent - pass2 <- newIdent - mr <- lift getMessageRender + messageRender <- lift getMessageRender + toParent <- getRouteToParent selectRep $ do - provideJsonMessage $ mr Msg.SetPass - provideRep $ lift $ authLayout $ do - setTitleI Msg.SetPassTitle - [whamlet| -$newline never -

_{Msg.SetPass} -
- - $if needOld - - - - -
- - -
- - -
- - -
- -|] + provideJsonMessage $ messageRender Msg.SetPass + provideRep $ lift $ authLayout $ do + ((_,widget),enctype) <- liftWidgetT $ runFormPost $ setPasswordForm needOld + setTitleI Msg.SetPassTitle + [whamlet| +

_{Msg.SetPass} + + ^{widget} + |] + where + setPasswordForm needOld extra = do + (currentPasswordRes, currentPasswordView) <- mreq passwordField currentPasswordSettings Nothing + (newPasswordRes, newPasswordView) <- mreq passwordField newPasswordSettings Nothing + (confirmPasswordRes, confirmPasswordView) <- mreq passwordField confirmPasswordSettings Nothing + + let passwordFormRes = PasswordForm <$> currentPasswordRes <*> newPasswordRes <*> confirmPasswordRes + let widget = do + [whamlet| + #{extra} + + $if needOld + + + + +
+ ^{fvLabel currentPasswordView} + + ^{fvInput currentPasswordView} +
+ ^{fvLabel newPasswordView} + + ^{fvInput newPasswordView} +
+ ^{fvLabel confirmPasswordView} + + ^{fvInput confirmPasswordView} +
+ + |] + + return (passwordFormRes, widget) + currentPasswordSettings = + FieldSettings { + fsLabel = SomeMessage Msg.CurrentPassword, + fsTooltip = Nothing, + fsId = Just "currentPassword", + fsName = Just "current", + fsAttrs = [("autofocus", "")] + } + newPasswordSettings = + FieldSettings { + fsLabel = SomeMessage Msg.NewPass, + fsTooltip = Nothing, + fsId = Just "newPassword", + fsName = Just "new", + fsAttrs = [("autofocus", ""), (":not", ""), ("needOld:autofocus", "")] + } + confirmPasswordSettings = + FieldSettings { + fsLabel = SomeMessage Msg.ConfirmPass, + fsTooltip = Nothing, + fsId = Just "confirmPassword", + fsName = Just "confirm", + fsAttrs = [("autofocus", "")] + } + + postPasswordR :: YesodAuthEmail master => HandlerT Auth (HandlerT master IO) TypedContent postPasswordR = do diff --git a/yesod-auth/Yesod/Auth/Message.hs b/yesod-auth/Yesod/Auth/Message.hs index 8459bb7f..0ef811ba 100644 --- a/yesod-auth/Yesod/Auth/Message.hs +++ b/yesod-auth/Yesod/Auth/Message.hs @@ -60,6 +60,7 @@ data AuthMessage = | ProvideIdentifier | SendPasswordResetEmail | PasswordResetPrompt + | CurrentPassword | InvalidUsernamePass | Logout | LogoutTitle @@ -78,6 +79,7 @@ englishMessage LoginYahoo = "Login via Yahoo" englishMessage Email = "Email" englishMessage UserName = "User name" englishMessage Password = "Password" +englishMessage CurrentPassword = "Current Password" englishMessage Register = "Register" englishMessage RegisterLong = "Register a new account" englishMessage EnterEmail = "Enter your e-mail address below, and a confirmation e-mail will be sent to you."