aboutsummaryrefslogtreecommitdiff
path: root/src/server/View/Mail/SignIn.hs
blob: 5eb181bc8d9d7bfeef11c27b0932212a8b72e753 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE OverloadedStrings #-}

module View.Mail.SignIn
  ( getMail
  ) where

import Data.Text (Text)
import qualified Data.Text.Lazy as LT
import Data.Text.Lazy.Builder (toLazyText, fromText)

import Text.Blaze.Html
import Text.Blaze.Html5
import Text.Blaze.Html.Renderer.Text (renderHtml)

import Model.Database (User(..))
import qualified Model.Mail as M
import Model.Message.Key
import Model.Message

getMail :: User -> Text -> [Text] -> M.Mail
getMail user url to =
  M.Mail
    { M.from = (getMessage NoReplyMail)
    , M.to = to
    , M.subject = (getMessage SignInMailTitle)
    , M.plainBody = plainBody user url
    , M.htmlBody = htmlBody user url
    }

plainBody :: User -> Text -> LT.Text
plainBody user url =
  LT.intercalate
    "\n"
    [ strictToLazy (getVarMessage [userName user] HiMail)
    , ""
    , strictToLazy (getMessage SignInLinkMail)
    , strictToLazy url
    ]

htmlBody :: User -> Text -> LT.Text
htmlBody user url =
  renderHtml . docTypeHtml . body $ do
    toHtml $ strictToLazy (getVarMessage [userName user] HiMail)
    br
    br
    toHtml $ strictToLazy (getMessage SignInLinkMail)
    br
    toHtml url

strictToLazy :: Text -> LT.Text
strictToLazy = toLazyText . fromText