From 641b75e66373962798928c5afdc199c5a653df61 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Mon, 17 Jun 2019 15:39:10 -0400 Subject: [PATCH] Add setExpiringCookie function this lets us set cookie that expire after the time indicated --- frontend/Rhyolite/Frontend/Cookie.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/Rhyolite/Frontend/Cookie.hs b/frontend/Rhyolite/Frontend/Cookie.hs index 72907061..3ed968af 100644 --- a/frontend/Rhyolite/Frontend/Cookie.hs +++ b/frontend/Rhyolite/Frontend/Cookie.hs @@ -26,6 +26,14 @@ setPermanentCookie :: (MonadJSM m, HasJSContext m) => DOM.Document -> SetCookie setPermanentCookie doc cookie = do DOM.setCookie doc $ decodeUtf8 $ LBS.toStrict $ toLazyByteString $ renderSetCookie cookie +-- | Set or clear the given cookie with given expiration date +-- +-- Example: +-- > setExpiringCookie time doc =<< defaultCookie "key" (Just "value") +setExpiringCookie :: (MonadJSM m, HasJSContext m) => UTCTime -> DOM.Document -> SetCookie -> m () +setExpiringCookie timestamp doc cookie = do + DOM.setCookie doc $ decodeUtf8 $ LBS.toStrict $ toLazyByteString $ renderSetCookie cookie {setCookieExpires = Just timestamp} + -- | Make a cookie with sensible defaults defaultCookie :: (MonadJSM m, HasJSContext m) -- TODO: verify