From d49b5d678c4888002e71bd2d26af516e48024847 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Wed, 11 Apr 2018 11:09:42 +0000 Subject: [PATCH] Allow login using email address --- config/models | 1 + src/Vervis/Foundation.hs | 1 + src/Vervis/Migration.hs | 2 ++ src/Vervis/Model.hs | 1 + stack.yaml | 2 +- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/models b/config/models index 883722e..e070482 100644 --- a/config/models +++ b/config/models @@ -36,6 +36,7 @@ Person UniquePersonIdent ident UniquePersonLogin login + UniquePersonEmail email SshKey ident KyIdent diff --git a/src/Vervis/Foundation.hs b/src/Vervis/Foundation.hs index 53de4d9..c9bc67c 100644 --- a/src/Vervis/Foundation.hs +++ b/src/Vervis/Foundation.hs @@ -498,6 +498,7 @@ instance YesodAuthVerify App where instance YesodAuthAccount AccountPersistDB' App where emailVerifyKeyDuration _ = Just $ fromTimeUnit (1 :: Day) passphraseResetKeyDuration _ = Just $ fromTimeUnit (1 :: Day) + allowLoginByEmailAddress _ = True runAccountDB = unAccountPersistDB' unregisteredLogin u = do lift $ setUnverifiedCreds True $ Creds "account" (username u) [] diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 3ba06d8..c8aeee3 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -126,6 +126,8 @@ changes = , addFieldPrimRequired "Person" defaultTime "verifiedKeyCreated" -- 21 , addFieldPrimRequired "Person" defaultTime "resetPassKeyCreated" + -- 22 + , addUnique "Person" $ Unique "UniquePersonEmail" ["email"] ] migrateDB :: MonadIO m => ReaderT SqlBackend m (Either Text (Int, Int)) diff --git a/src/Vervis/Model.hs b/src/Vervis/Model.hs index 70996e3..fd277b1 100644 --- a/src/Vervis/Model.hs +++ b/src/Vervis/Model.hs @@ -48,6 +48,7 @@ instance PersistUserCredentials Person where userResetPwdKeyF = PersonResetPassKey userResetPwdKeyCreatedF = Just PersonResetPassKeyCreated uniqueUsername = UniquePersonLogin + uniqueEmail = Just UniquePersonEmail -- 'Person' contains a sharer ID, so we can't let yesod-auth-account use -- 'userCreate' to create a new user. Instead, override the default -- implementation, where we can make sure to create a 'Sharer' and then a diff --git a/stack.yaml b/stack.yaml index 5220534..55e3bf2 100644 --- a/stack.yaml +++ b/stack.yaml @@ -18,7 +18,7 @@ packages: # - '../yesod-auth-account' - location: git: https://dev.seek-together.space/s/fr33domlover/r/yesod-auth-account - commit: 31f8467d598d06d06d43917f42c035e53c2f3b46 + commit: d44b85e979b52baaba346b236250a4a84dbd5c7f extra-dep: true - '../yesod-mail-send'