blob: c447416aeaa3136e34eeac8d861d969e2c18d2e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
module Model.SignIn
( createSignInToken
, getSignInToken
, signInTokenIsUsed
) where
import Data.Text (Text)
import Data.Time.Clock (getCurrentTime)
import Control.Monad.IO.Class (liftIO)
import Database.Persist
import Model.Database
import Model.UUID (generateUUID)
createSignInToken :: Text -> Persist Text
createSignInToken email = do
now <- liftIO getCurrentTime
token <- liftIO generateUUID
_ <- insert $ SignIn token now email False
return token
getSignInToken :: Text -> Persist (Maybe (Entity SignIn))
getSignInToken token =
selectFirst
[ SignInToken ==. token
, SignInIsUsed ==. False
]
[]
signInTokenIsUsed :: SignInId -> Persist ()
signInTokenIsUsed tokenId =
update tokenId [SignInIsUsed =. True]
|