Email applicants when resolving their applications
This commit is contained in:
parent
8cda69d30d
commit
49536ad05b
|
@ -31,7 +31,7 @@ import Database.Persist (Entity, entityVal, entityKey, get, (=.))
|
|||
import Datarekisteri.Core.Types
|
||||
import Datarekisteri.Backend.DB
|
||||
import Datarekisteri.Backend.DB.Queries
|
||||
import Datarekisteri.Backend.Email (sendVerificationEmail)
|
||||
import Datarekisteri.Backend.Email (sendVerificationEmail, sendApplicationAcceptedEmail, sendApplicationRejectedEmail)
|
||||
import Datarekisteri.Backend.Types
|
||||
import Datarekisteri.Backend.Utils
|
||||
import qualified "base64" Data.ByteString.Base64 as B64 (encodeBase64)
|
||||
|
@ -193,15 +193,25 @@ makeNewKey (KeyData {..}) user = do
|
|||
, dBKeyIsPrimaryEncryptionKey = True
|
||||
}
|
||||
|
||||
acceptApplication :: (MonadDB m, MonadTime m) => UserID -> m Unit
|
||||
acceptApplication :: (MonadDB m, MonadTime m, MonadError GQLError m, MonadEmail m) => UserID -> m Unit
|
||||
acceptApplication user = void $ do
|
||||
maybeEmail <- getUserEmail user
|
||||
case maybeEmail of
|
||||
Nothing -> throwError $ "No valid application for " <> show user <> "!"
|
||||
Just email -> do
|
||||
time <- currentTime
|
||||
markAsAccepted user time
|
||||
void $ sendApplicationAcceptedEmail $ dBEmailEmail $ entityVal email
|
||||
|
||||
rejectApplication :: (MonadDB m, MonadTime m) => UserID -> m Unit
|
||||
rejectApplication :: (MonadDB m, MonadTime m, MonadError GQLError m, MonadEmail m) => UserID -> m Unit
|
||||
rejectApplication user = void $ do
|
||||
maybeEmail <- getUserEmail user
|
||||
case maybeEmail of
|
||||
Nothing -> throwError $ "No valid application for " <> show user <> "!"
|
||||
Just email -> do
|
||||
time <- currentTime
|
||||
markAsRejected user time
|
||||
void $ sendApplicationRejectedEmail $ dBEmailEmail $ entityVal email
|
||||
|
||||
resolveQuery :: (MonadRequest m, MonadDB m, MonadError GQLError m, MonadPermissions m) => Query m
|
||||
resolveQuery = Query
|
||||
|
|
|
@ -8,11 +8,22 @@ import Data.Text.Lazy (fromStrict)
|
|||
import Datarekisteri.Core.Types
|
||||
import Network.Mail.Mime
|
||||
|
||||
sendVerificationEmail :: MonadEmail m => Email -> Text -> m ()
|
||||
sendVerificationEmail to secret = do
|
||||
sendDatarekisteriEmail :: MonadEmail m => Email -> Text -> Text -> m ()
|
||||
sendDatarekisteriEmail to subject content = do
|
||||
from <- fromAddress
|
||||
sendEmail $ simpleMail' (Address Nothing $ renderEmail to) from
|
||||
"Sähköpostin vahvistuskoodi" $ fromStrict $
|
||||
sendEmail $ simpleMail' (Address Nothing $ renderEmail to) from subject $ fromStrict content
|
||||
|
||||
sendVerificationEmail :: MonadEmail m => Email -> Text -> m ()
|
||||
sendVerificationEmail to secret = sendDatarekisteriEmail to "Sähköpostin vahvistuskoodi" $
|
||||
"Vahvista sähköpostisi syöttämällä alla oleva koodi rekisteriin:\n\n"
|
||||
<> secret <> "\n\n"
|
||||
<> "Mikäli et odottanut tätä viestiä, voit jättää sen turvallisesti huomiotta."
|
||||
|
||||
sendApplicationAcceptedEmail :: MonadEmail m => Email -> m ()
|
||||
sendApplicationAcceptedEmail to = sendDatarekisteriEmail to "Jäsenhakemus hyväksytty" $
|
||||
"Jäsenhakemuksesi Datat RY:lle on hyväksytty. Olet nyt yhdistyksen jäsen."
|
||||
|
||||
sendApplicationRejectedEmail :: MonadEmail m => Email -> m ()
|
||||
sendApplicationRejectedEmail to = sendDatarekisteriEmail to "Jäsenhakemus hylätty" $
|
||||
"Jäsenhakemuksesi Datat RY:lle on hylätty. Voit halutessasi kysyä hakemuksen"
|
||||
<> " hylkäämisen syistä yhdistyksen hallitukselta <hallitus@datat.fi>."
|
||||
|
|
Loading…
Reference in New Issue