From baeef7873ee3c5f106b19c8d73a8a9b4fe417162 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sat, 17 Mar 2018 22:59:40 +0000 Subject: [PATCH] Unverified login and dedicated route for verification email resend form --- src/Vervis/Foundation.hs | 16 +++++++++++----- src/Yesod/Auth/Unverified/Creds.hs | 6 +++++- src/Yesod/Auth/Unverified/Internal.hs | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index cdb0fee..1e65b79 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -30,6 +30,9 @@ import Yesod.Core.Types (Logger) import Yesod.Default.Util (addStaticContentExternal) import Text.Email.Local + +import Yesod.Auth.Unverified +import Yesod.Auth.Unverified.Creds import Yesod.Mail.Send import qualified Yesod.Core.Unsafe as Unsafe @@ -379,6 +382,8 @@ instance YesodAuth App where authHttpManager = getHttpManager + onLogout = clearUnverifiedCreds False + instance YesodAuthPersist App newtype AccountPersistDB' a = AccountPersistDB' @@ -436,13 +441,14 @@ instance AccountSendEmail App where , url ] +instance YesodAuthVerify App where + verificationRoute _ = ResendVerifyEmailR + instance YesodAuthAccount AccountPersistDB' App where runAccountDB = unAccountPersistDB' - --unregisteredLogin u = do - -- set creds unverified - --setUnverifiedCreds True $ Creds "account" (username u) [] - -- redirect to resend form - -- ? + unregisteredLogin u = do + lift $ setUnverifiedCreds True $ Creds "account" (username u) [] + return mempty -- This instance is required to use forms. You can modify renderMessage to -- achieve customized and internationalized form validation messages. diff --git a/src/Yesod/Auth/Unverified/Creds.hs b/src/Yesod/Auth/Unverified/Creds.hs index 04b2054..0e93c83 100644 --- a/src/Yesod/Auth/Unverified/Creds.hs +++ b/src/Yesod/Auth/Unverified/Creds.hs @@ -61,6 +61,10 @@ -- changes from yesod-auth 1.4.13.2, which is in LTS 6.5, to 1.6.2, which is -- the latest release and where I copied from -- * Instead of loginDest and onLogin, use my custom unverified counterparts +-- * Not call onLogout in clearUnverifiedCreds, because I use onLogout to clear +-- these creds, so it would either cause an infinite loop (if not +-- redirecting), or, if redirecting, the regular yesod-auth login session key +-- wouldn't get to be cleared module Yesod.Auth.Unverified.Creds ( setUnverifiedCreds , setUnverifiedCredsRedirect @@ -275,7 +279,7 @@ clearUnverifiedCreds :: YesodAuth master -> HandlerT master IO () clearUnverifiedCreds doRedirects = do y <- getYesod - onLogout + -- onLogout deleteSession credsKey when doRedirects $ do redirectUltDest $ logoutDest y diff --git a/src/Yesod/Auth/Unverified/Internal.hs b/src/Yesod/Auth/Unverified/Internal.hs index 669e681..0befc74 100644 --- a/src/Yesod/Auth/Unverified/Internal.hs +++ b/src/Yesod/Auth/Unverified/Internal.hs @@ -38,9 +38,9 @@ class YesodAuth site => YesodAuthVerify site where verificationRoute :: site -> Route site -- | Default destination on successful unverified login, if no other - -- destination exists. Default: 'loginDest' + -- destination exists. Default: 'verificationRoute' unverifiedLoginDest :: site -> Route site - unverifiedLoginDest = loginDest + unverifiedLoginDest = verificationRoute -- | Called on a successful unverified login. Default: 'onLogin' --onUnverifiedLogin :: (MonadHandler m, site ~ HandlerSite m) => m ()