Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthEmail: Fix forgot-password endpoint #1537

Merged
merged 2 commits into from Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions yesod-auth/ChangeLog.md
@@ -1,5 +1,8 @@
# ChangeLog for yesod-auth

## 1.6.4.1
* Email: Fix forgot-password endpoint [#1537](https://github.com/yesodweb/yesod/pull/1537)

## 1.6.4

* Make `registerHelper` configurable [#1524](https://github.com/yesodweb/yesod/issues/1524)
Expand Down
19 changes: 10 additions & 9 deletions yesod-auth/Yesod/Auth/Email.hs
Expand Up @@ -516,10 +516,10 @@ parseRegister = withObject "email" (\obj -> do

registerHelper :: YesodAuthEmail master
=> Bool -- ^ allow usernames?
-> Bool -- ^ allow password?
-> Bool -- ^ forgot password?
-> Route Auth
-> AuthHandler master TypedContent
registerHelper allowUsername allowPassword dest = do
registerHelper allowUsername forgotPassword dest = do
y <- getYesod
checkCsrfHeaderOrParam defaultCsrfHeaderName defaultCsrfParamName
result <- runInputPostResult $ (,)
Expand All @@ -542,8 +542,8 @@ registerHelper allowUsername allowPassword dest = do
| allowUsername -> Right $ TS.strip x
| otherwise -> Left Msg.InvalidEmailAddress

let mpass = case (allowPassword, creds) of
(True, Just (_, mp)) -> mp
let mpass = case (forgotPassword, creds) of
(False, Just (_, mp)) -> mp
_ -> Nothing

case eidentifier of
Expand Down Expand Up @@ -571,9 +571,10 @@ registerHelper allowUsername allowPassword dest = do
Nothing -> loginErrorMessageI dest (Msg.IdentifierNotFound identifier)
Just creds@(_, False, _, _) -> sendConfirmationEmail creds
Just creds@(_, True, _, _) -> do
case emailPreviouslyRegisteredResponse identifier of
Just response -> response
Nothing -> sendConfirmationEmail creds
if forgotPassword then sendConfirmationEmail creds
else case emailPreviouslyRegisteredResponse identifier of
Just response -> response
Nothing -> sendConfirmationEmail creds
where sendConfirmationEmail (lid, _, verKey, email) = do
render <- getUrlRender
tp <- getRouteToParent
Expand All @@ -583,7 +584,7 @@ registerHelper allowUsername allowPassword dest = do


postRegisterR :: YesodAuthEmail master => AuthHandler master TypedContent
postRegisterR = registerHelper False True registerR
postRegisterR = registerHelper False False registerR

getForgotPasswordR :: YesodAuthEmail master => AuthHandler master Html
getForgotPasswordR = forgotPasswordHandler
Expand Down Expand Up @@ -627,7 +628,7 @@ defaultForgotPasswordHandler = do
}

postForgotPasswordR :: YesodAuthEmail master => AuthHandler master TypedContent
postForgotPasswordR = registerHelper True False forgotPasswordR
postForgotPasswordR = registerHelper True True forgotPasswordR

getVerifyR :: YesodAuthEmail site
=> AuthEmailId site
Expand Down
2 changes: 1 addition & 1 deletion yesod-auth/yesod-auth.cabal
@@ -1,5 +1,5 @@
name: yesod-auth
version: 1.6.4
version: 1.6.4.1
license: MIT
license-file: LICENSE
author: Michael Snoyman, Patrick Brisbin
Expand Down