aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model/SignIn.hs
blob: 0f9c6cee6bf13986456986d82c6a5e2afc080ded (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
module Model.SignIn
  ( createSignInToken
  , getSignInToken
  , signInTokenToUsed
  ) 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] []

signInTokenToUsed :: SignInId -> Persist ()
signInTokenToUsed tokenId =
  update tokenId [SignInIsUsed =. True]