Skip to content

Commit

Permalink
Splitted Lockable.isLocked into an IO and a pure function
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed May 21, 2022
1 parent af5a4cf commit eb5e0ec
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions IHP/AuthSupport/Lockable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ lockDuration = let timeInSecs = 60 * 60 in secondsToNominalDiffTime timeInSecs
isLocked :: forall user. (HasField "lockedAt" user (Maybe UTCTime)) => user -> IO Bool
isLocked user = do
now <- getCurrentTime
let currentLockedAt :: Maybe UTCTime = getField @"lockedAt" user
pure $! case currentLockedAt of
pure (isLocked' now user)

isLocked' :: forall user. (HasField "lockedAt" user (Maybe UTCTime)) => UTCTime -> user -> Bool
isLocked' now user =
case getField @"lockedAt" user of
Just lockedAt ->
let diff = diffUTCTime now lockedAt
in diff < lockDuration
Expand Down

0 comments on commit eb5e0ec

Please sign in to comment.