aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorLia Lenckowski <lialenck@protonmail.com>2023-08-29 00:01:45 +0200
committerLia Lenckowski <lialenck@protonmail.com>2023-08-29 00:01:45 +0200
commit2f12a917b9f156e012c9dd6cae382bdc36fae7c7 (patch)
tree7060ded82988dd5ead8483e014edfa74dc930e39 /src/Main.hs
parent6ea0264d32d5337c033d3865e16f6f35dfbe47f0 (diff)
downloadfastbangs-2f12a917b9f156e012c9dd6cae382bdc36fae7c7.tar
fastbangs-2f12a917b9f156e012c9dd6cae382bdc36fae7c7.tar.bz2
fastbangs-2f12a917b9f156e012c9dd6cae382bdc36fae7c7.tar.zst
pending bang verdict notifications
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 049e709..91da385 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -9,6 +9,7 @@ import Control.Monad.Logger (runStdoutLoggingT)
import Control.Monad.Trans.Resource (runResourceT)
import Control.Monad (when, unless)
import Database.Persist.Sqlite
+import Data.Bool (bool)
import Data.Function ((&))
import Network.Wai.Handler.Warp hiding (getPort, getHost)
import Yesod
@@ -98,7 +99,8 @@ getOpenSearchR = do
postVerdictR :: Bool -> Handler ()
postVerdictR b = do
- ensureAuth . config =<< getYesod
+ cfg <- config <$> getYesod
+ ensureAuth cfg
(PendingBang n u dp mayEm) <- requireCheckJsonBody
-- NOTE: known race condition: the bang bang may be deleted from the database
@@ -106,8 +108,21 @@ postVerdictR b = do
-- a pending bang on very specific crash timing.
st <- bangState <$> getYesod
when b $ liftIO $ addBang n u dp st
- --sendEmail mayEm $ "your bang was " <> bool b "rejected" "accepted" -- TODO
runDB $ deleteWhere [PendingBangBang ==. n]
+
+ case mayEm of
+ Nothing -> return ()
+ Just em -> do
+ let e = T.unpack em
+ sendEmail cfg e ("Your bang was " <> bool "rejected" "accepted!" b) $
+ "Hello,\n" <>
+ "\n" <>
+ "We're " <> bool "sorry" "happy" b <> " to announce that your" <>
+ " submitted bang \"" <> T.unpack dp <> "\" (\"!" <> T.unpack n <>
+ "\", leading to " <> T.unpack u <> ") has been " <>
+ bool "rejected" "accepted" b <>
+ " by an administrator. Good look with your future banging!\n"
+
return ()
postAcceptR, postRejectR :: Handler ()