summaryrefslogtreecommitdiff
path: root/UtilEmail.hs
diff options
context:
space:
mode:
authorClint Adams <clint@softwarefreedom.org>2015-04-24 12:53:02 -0400
committerClint Adams <clint@softwarefreedom.org>2015-04-24 12:53:02 -0400
commit62597317839c7945bfbc4b7a00f55d2db6459ab6 (patch)
tree6ad8c079d5eea66b05326d435e30cc2b1de43266 /UtilEmail.hs
Finally put pfifcontractors into gitHEADmaster
Diffstat (limited to 'UtilEmail.hs')
-rw-r--r--UtilEmail.hs56
1 files changed, 56 insertions, 0 deletions
diff --git a/UtilEmail.hs b/UtilEmail.hs
new file mode 100644
index 0000000..e81949f
--- /dev/null
+++ b/UtilEmail.hs
@@ -0,0 +1,56 @@
+{-# LANGUAGE TupleSections, OverloadedStrings #-}
+module UtilEmail where
+
+import Import
+import qualified Data.Text.Lazy.Encoding
+import Network.Mail.Mime (Part(..), Encoding(..), Address(..), Mail(..), emptyMail, renderSendMail, randomString)
+import Text.Blaze.Renderer.Utf8 (renderHtml)
+import Text.Hamlet (shamlet)
+import Text.Shakespeare.Text (stext)
+
+import qualified Data.Text as T
+import System.Random (newStdGen)
+
+sendVerifyEmail :: Text -> Text -> Text -> Handler ()
+sendVerifyEmail email _ verurl =
+ liftIO $ renderSendMail (emptyMail $ Address (Just "PFIF") "noreply@protocolfreedom.org")
+ { mailTo = [Address Nothing email]
+ , mailHeaders =
+ [ ("Subject", "Verify your email address")
+ ]
+ , mailParts = [[textPart, htmlPart]]
+ }
+ where
+ textPart = Part
+ { partType = "text/plain; charset=utf-8"
+ , partEncoding = None
+ , partFilename = Nothing
+ , partContent = Data.Text.Lazy.Encoding.encodeUtf8 [stext|
+Please confirm your email address by visiting the link below.
+
+( #{verurl} )
+
+Thank you,
+
+PFIF
+|]
+ , partHeaders = []
+ }
+ htmlPart = Part
+ { partType = "text/html; charset=utf-8"
+ , partEncoding = None
+ , partFilename = Nothing
+ , partContent = renderHtml [shamlet|
+<p>Please confirm your email address by clicking on the link below.
+<p>
+ <a href=#{verurl}>#{verurl}
+<p>Thank you
+|]
+ , partHeaders = []
+ }
+
+
+randomKey :: IO Text
+randomKey = do
+ stdgen <- newStdGen
+ return $ T.pack $ fst $ randomString 10 stdgen