Make behavior of registerHelper configurable.

The behavior of `registerHelper` when an email that is already-verified
tries to register is now configurable via the
`emailPreviouslyRegisteredResponse` method of the `YesodAuthEmail`
typeclass.
This commit is contained in:
Steven Leiva 2018-06-08 15:49:30 -05:00
parent 840f8faaaa
commit 8d58a56577
3 changed files with 29 additions and 12 deletions

View File

@ -1,3 +1,7 @@
## 1.6.4
* Make `registerHelper` configurable [#1524](https://github.com/yesodweb/yesod/issues/1524)
## 1.6.3 ## 1.6.3
* Generalize GoogleEmail2.getPerson [#1501](https://github.com/yesodweb/yesod/pull/1501) * Generalize GoogleEmail2.getPerson [#1501](https://github.com/yesodweb/yesod/pull/1501)

View File

@ -299,6 +299,14 @@ class ( YesodAuth site
where where
msg = Msg.ConfirmationEmailSent identifier msg = Msg.ConfirmationEmailSent identifier
-- | If a response is set, it will be used when an already-verified email
-- tries to re-register. Otherwise, `confirmationEmailSentResponse` will be
-- used.
--
-- @since 1.6.4
emailPreviouslyRegisteredResponse :: MonadAuthHandler site m => Text -> Maybe (m TypedContent)
emailPreviouslyRegisteredResponse _ = Nothing
-- | Additional normalization of email addresses, besides standard canonicalization. -- | Additional normalization of email addresses, besides standard canonicalization.
-- --
-- Default: Lower case the email address. -- Default: Lower case the email address.
@ -508,26 +516,31 @@ registerHelper allowUsername dest = do
mecreds <- getEmailCreds identifier mecreds <- getEmailCreds identifier
registerCreds <- registerCreds <-
case mecreds of case mecreds of
Just (EmailCreds lid _ _ (Just key) email) -> return $ Just (lid, key, email) Just (EmailCreds lid _ verStatus (Just key) email) -> return $ Just (lid, verStatus, key, email)
Just (EmailCreds lid _ _ Nothing email) -> do Just (EmailCreds lid _ verStatus Nothing email) -> do
key <- liftIO $ randomKey y key <- liftIO $ randomKey y
setVerifyKey lid key setVerifyKey lid key
return $ Just (lid, key, email) return $ Just (lid, verStatus, key, email)
Nothing Nothing
| allowUsername -> return Nothing | allowUsername -> return Nothing
| otherwise -> do | otherwise -> do
key <- liftIO $ randomKey y key <- liftIO $ randomKey y
lid <- addUnverified identifier key lid <- addUnverified identifier key
return $ Just (lid, key, identifier) return $ Just (lid, False, key, identifier)
case registerCreds of case registerCreds of
Nothing -> loginErrorMessageI dest (Msg.IdentifierNotFound identifier) Nothing -> loginErrorMessageI dest (Msg.IdentifierNotFound identifier)
Just (lid, verKey, email) -> do Just creds@(_, False, _, _) -> sendConfirmationEmail creds
render <- getUrlRender Just creds@(_, True, _, _) -> do
tp <- getRouteToParent case emailPreviouslyRegisteredResponse identifier of
let verUrl = render $ tp $ verifyR (toPathPiece lid) verKey Just response -> response
sendVerifyEmail email verKey verUrl Nothing -> sendConfirmationEmail creds
confirmationEmailSentResponse identifier where sendConfirmationEmail (lid, _, verKey, email) = do
render <- getUrlRender
tp <- getRouteToParent
let verUrl = render $ tp $ verifyR (toPathPiece lid) verKey
sendVerifyEmail email verKey verUrl
confirmationEmailSentResponse identifier
postRegisterR :: YesodAuthEmail master => AuthHandler master TypedContent postRegisterR :: YesodAuthEmail master => AuthHandler master TypedContent
postRegisterR = registerHelper False registerR postRegisterR = registerHelper False registerR

View File

@ -1,5 +1,5 @@
name: yesod-auth name: yesod-auth
version: 1.6.3 version: 1.6.4
license: MIT license: MIT
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman, Patrick Brisbin author: Michael Snoyman, Patrick Brisbin