moved stuff to helper

This commit is contained in:
nek0 2014-09-04 01:15:27 +02:00
parent eb22685597
commit 06c55cc449
2 changed files with 25 additions and 29 deletions

View file

@ -56,35 +56,6 @@ postSignupR = do
setMessage "This user already exists"
redirect $ SignupR
--signupForm :: Form User
--signupForm = renderDivs $ User
-- <$> areq textField "Username" Nothing
-- <*> areq emailField "Email" Nothing
-- <*> areq passwordField "Password" Nothing
-- <*> pure ("" :: ByteString)
-- <*> pure []
validateLen :: Text -> Bool
validateLen a =
(T.length a) > 3
generateString :: IO T.Text
generateString = (toHex . B.pack . I.take 16 . randoms) <$> newStdGen
sendMail :: MonadIO m => Text -> Text -> Html -> m ()
sendMail toEmail subject body =
liftIO $ renderSendMail
Mail
{ mailFrom = Address Nothing "noreply" -- TODO: set sender Address
, mailTo = [Address Nothing toEmail]
, mailCc = []
, mailBcc = []
, mailHeaders = [("Subject", subject)]
, mailParts = [[Part
{ partType = "text/html; charset=utf-8"
, partEncoding = None
, partFilename = Nothing
, partHeaders = []
, partContent = renderHtml body
}]]
}

View file

@ -8,6 +8,8 @@ module Helper
, makeRandomToken
, generateSalt
, tagField
, sendMail
, generateString
)
where
@ -29,6 +31,8 @@ import Yesod.Persist.Core
import Yesod.Core.Types
import Yesod
import Numeric (readHex, showHex)
import Network.Mail.Mime
import Text.Blaze.Html.Renderer.Utf8
getUserIdFromText :: T.Text -> UserId
getUserIdFromText tempUserId =
@ -83,3 +87,24 @@ tagField = Field
[whamlet|<input id=#{idAttr} type="text" name=#{nameAttr} value=#{either id (T.intercalate " ") eResult}>|]
, fieldEnctype = UrlEncoded
}
sendMail :: MonadIO m => T.Text -> T.Text -> Html -> m ()
sendMail toEmail subject body =
liftIO $ renderSendMail
Mail
{ mailFrom = Address Nothing "noreply" -- TODO: set sender Address
, mailTo = [Address Nothing toEmail]
, mailCc = []
, mailBcc = []
, mailHeaders = [("Subject", subject)]
, mailParts = [[Part
{ partType = "text/html; charset=utf-8"
, partEncoding = None
, partFilename = Nothing
, partHeaders = []
, partContent = renderHtml body
}]]
}
generateString :: IO T.Text
generateString = (toHex . B.pack . take 16 . randoms) <$> newStdGen