on master help sign in
Merge pull request #106 from ilyakooo0/develop
e5b7feeiko
denis/src/Server/Auth/Mail.hs+7−5
@@ -10,6 +10,7 @@
10 UndecidableInstances,
10 UndecidableInstances,
11 DeriveAnyClass,
11 DeriveAnyClass,
12 RecordWildCards #-}
12 RecordWildCards #-}
13+{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
13
14
14module Server.Auth.Mail (
15module Server.Auth.Mail (
15 sendTokenVerificationEmail
16 sendTokenVerificationEmail
@@ -20,9 +21,8 @@ import Server.App
20import Server.Auth.Token
21import Server.Auth.Token
21import Control.Monad.IO.Class
22import Control.Monad.IO.Class
22import Network.Mail.Mime (Mail, Part)
23import Network.Mail.Mime (Mail, Part)
23−import Data.Text (Text, pack)
24+import Data.Text (Text)
24import qualified Data.Text.Lazy as TL
25import qualified Data.Text.Lazy as TL
25−import Data.Text.Lazy (fromStrict)
26
26
27sendTokenVerificationEmail :: TokenVerificationCode -> Text -> App ()
27sendTokenVerificationEmail :: TokenVerificationCode -> Text -> App ()
28sendTokenVerificationEmail code email = do
28sendTokenVerificationEmail code email = do
@@ -31,12 +31,14 @@ sendTokenVerificationEmail code email = do
31 (Address (Just "HSE Social Network") "noreply@hse.ru")
31 (Address (Just "HSE Social Network") "noreply@hse.ru")
32 [Address Nothing email] [] []
32 [Address Nothing email] [] []
33 "HSE Social Network Verification Code"
33 "HSE Social Network Verification Code"
34− [genMail . show $ code]
34+ [genMail code]
35 sendMailWithConfig mailCfg mail
35 sendMailWithConfig mailCfg mail
36
36
37sendMailWithConfig :: (MonadIO m) => MailConfig -> Mail -> m ()
37sendMailWithConfig :: (MonadIO m) => MailConfig -> Mail -> m ()
38sendMailWithConfig (MailConfig host port user pass) =
38sendMailWithConfig (MailConfig host port user pass) =
39 liftIO . sendMailWithLogin' host (fromIntegral port) user pass
39 liftIO . sendMailWithLogin' host (fromIntegral port) user pass
40
40
41−genMail :: String -> Part
41+genMail :: TokenVerificationCode -> Part
42−genMail [a, b, c, d, e, f] = htmlPart $ "<html><body style=\"font-family: sans-serif;\"> <h1> <div align=\"center\" style=\"margin-top: 20vh;\"> <a href=\"#\" style=\"font-size: 34px; font-weight: bold; display: inline-block; padding: 7px 13px 7px 13px; margin-bottom: 89px; text-decoration: underline; font-family: sans-serif; color: #555;\"> Log in </a> <br/> <div style=\"font-size: 55px; font-weight: bold; border-radius: 10px; background-color: #eee; display: inline-block; padding: 7px 13px 7px 13px; box-shadow: 0px 5px 21px #bbb; background-image: linear-gradient(#f9f9f9, #eee);\">" <> TL.pack [a, b] <> "<div style=\"display: inline-block; width: 10px;\"></div>" <> TL.pack [c, d] <> "<div style=\"display: inline-block; width: 10px;\"></div>" <> TL.pack [e, f] <> "</div></div><div align=\"center\" style=\"margin-top: 233px;\"> <a href=\"#\" style=\"text-decoration: underline; font-family: sans-serif; color: #555;font-size: 13px;\">Revoke access</a> </div></body></html>"
42+genMail code = htmlPart $ "<html><body style=\"font-family: sans-serif;\"> <h1> <div align=\"center\" style=\"margin-top: 20vh;\"> <a href=\"#\" style=\"font-size: 34px; font-weight: bold; display: inline-block; padding: 7px 13px 7px 13px; margin-bottom: 89px; text-decoration: underline; font-family: sans-serif; color: #555;\"> Log in </a> <br/> <div style=\"font-size: 55px; font-weight: bold; border-radius: 10px; background-color: #eee; display: inline-block; padding: 7px 13px 7px 13px; box-shadow: 0px 5px 21px #bbb; background-image: linear-gradient(#f9f9f9, #eee);\">" <> TL.pack [a, b] <> "<div style=\"display: inline-block; width: 10px;\"></div>" <> TL.pack [c, d] <> "<div style=\"display: inline-block; width: 10px;\"></div>" <> TL.pack [e, f] <> "</div></div><div align=\"center\" style=\"margin-top: 233px;\"> <a href=\"#\" style=\"text-decoration: underline; font-family: sans-serif; color: #555;font-size: 13px;\">Revoke access</a> </div></body></html>"
43+ where
44+ [a, b, c, d, e, f] = reverse . take 6 . (++ repeat '0') . reverse . show $ code