diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 19 |
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 () |