Email tokens expire within 1 day

This commit is contained in:
fr33domlover 2018-04-01 03:02:35 +00:00
parent 282ed32fe6
commit 7c2faa7faa
5 changed files with 42 additions and 18 deletions

View file

@ -30,7 +30,9 @@ Person
email EmailAddress email EmailAddress
verified Bool verified Bool
verifiedKey Text verifiedKey Text
resetPassphraseKey Text verifiedKeyCreated UTCTime
resetPassKey Text
resetPassKeyCreated UTCTime
UniquePersonIdent ident UniquePersonIdent ident
UniquePersonLogin login UniquePersonLogin login

View file

@ -19,6 +19,8 @@ import Prelude (init, last)
import Control.Monad.Logger (logWarn) import Control.Monad.Logger (logWarn)
import Control.Monad.Trans.Maybe import Control.Monad.Trans.Maybe
import Data.Time.Interval (fromTimeUnit)
import Data.Time.Units (Day)
import Database.Persist.Sql (ConnectionPool, runSqlPool) import Database.Persist.Sql (ConnectionPool, runSqlPool)
import Text.Shakespeare.Text (textFile) import Text.Shakespeare.Text (textFile)
import Text.Hamlet (hamletFile) import Text.Hamlet (hamletFile)
@ -41,7 +43,7 @@ import Data.Text as T (pack, intercalate, concat)
--import qualified Data.Text.Encoding as TE --import qualified Data.Text.Encoding as TE
import Text.Jasmine.Local (discardm) import Text.Jasmine.Local (discardm)
import Vervis.Import.NoFoundation hiding (last) import Vervis.Import.NoFoundation hiding (Day, last)
import Vervis.Model.Group import Vervis.Model.Group
import Vervis.Model.Ident import Vervis.Model.Ident
import Vervis.Model.Role import Vervis.Model.Role
@ -458,7 +460,8 @@ instance AccountDB AccountPersistDB' where
mr <- getMessageRender mr <- getMessageRender
return $ Left $ mr $ MsgUsernameExists name return $ Left $ mr $ MsgUsernameExists name
Right sid -> do Right sid -> do
let person = Person sid name pwd email False key "" let defTime = UTCTime (ModifiedJulianDay 0) 0
person = Person sid name pwd email False key now "" defTime
pid <- insert person pid <- insert person
return $ Right $ Entity pid person return $ Right $ Entity pid person
@ -493,6 +496,8 @@ instance YesodAuthVerify App where
verificationRoute _ = ResendVerifyEmailR verificationRoute _ = ResendVerifyEmailR
instance YesodAuthAccount AccountPersistDB' App where instance YesodAuthAccount AccountPersistDB' App where
emailVerifyKeyDuration _ = Just $ fromTimeUnit (1 :: Day)
passphraseResetKeyDuration _ = Just $ fromTimeUnit (1 :: Day)
runAccountDB = unAccountPersistDB' runAccountDB = unAccountPersistDB'
unregisteredLogin u = do unregisteredLogin u = do
lift $ setUnverifiedCreds True $ Creds "account" (username u) [] lift $ setUnverifiedCreds True $ Creds "account" (username u) []

View file

@ -29,6 +29,7 @@ import Data.Foldable (traverse_, for_)
import Data.Maybe (fromMaybe, listToMaybe) import Data.Maybe (fromMaybe, listToMaybe)
import Data.Proxy import Data.Proxy
import Data.Text (Text) import Data.Text (Text)
import Data.Time.Clock (UTCTime)
import Database.Persist import Database.Persist
import Database.Persist.BackendDataType (backendDataType) import Database.Persist.BackendDataType (backendDataType)
import Database.Persist.Migration import Database.Persist.Migration
@ -125,6 +126,18 @@ changes =
} }
-- 17 -- 17
, renameField "Person" "hash" "passphraseHash" , renameField "Person" "hash" "passphraseHash"
-- 18
, renameField "Person" "resetPassphraseKey" "resetPassKey"
-- 19
, addField "Person" (Just "'1970-01-01 00:00:00'") $ Field
"verifiedKeyCreated"
(FTPrim $ backendDataType (Proxy :: Proxy UTCTime))
FieldRequired
-- 20
, addField "Person" (Just "'1970-01-01 00:00:00'") $ Field
"resetPassKeyCreated"
(FTPrim $ backendDataType (Proxy :: Proxy UTCTime))
FieldRequired
] ]
migrateDB :: MonadIO m => ReaderT SqlBackend m (Either Text (Int, Int)) migrateDB :: MonadIO m => ReaderT SqlBackend m (Either Text (Int, Int))

View file

@ -44,7 +44,9 @@ instance PersistUserCredentials Person where
userEmailF = PersonEmail userEmailF = PersonEmail
userEmailVerifiedF = PersonVerified userEmailVerifiedF = PersonVerified
userEmailVerifyKeyF = PersonVerifiedKey userEmailVerifyKeyF = PersonVerifiedKey
userResetPwdKeyF = PersonResetPassphraseKey userEmailVerifyKeyCreatedF = Just PersonVerifiedKeyCreated
userResetPwdKeyF = PersonResetPassKey
userResetPwdKeyCreatedF = Just PersonResetPassKeyCreated
uniqueUsername = UniquePersonLogin uniqueUsername = UniquePersonLogin
-- 'Person' contains a sharer ID, so we can't let yesod-auth-account use -- 'Person' contains a sharer ID, so we can't let yesod-auth-account use
-- 'userCreate' to create a new user. Instead, override the default -- 'userCreate' to create a new user. Instead, override the default

View file

@ -298,6 +298,8 @@ library
, template-haskell , template-haskell
, text , text
, time , time
, time-interval
, time-units
, transformers , transformers
-- probably should be replaced with lenses once I learn -- probably should be replaced with lenses once I learn
, tuple , tuple