2 Module : Gargantext.Core.Mail
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 module Gargantext.Core.Mail where
14 import Control.Lens (view)
15 import Network.URI.Encode (encodeText)
16 import Data.Text (Text, unlines, splitOn)
17 import Gargantext.Core.Types.Individu
18 import Gargantext.Database.Schema.User (UserLight(..))
19 import Gargantext.Prelude
20 import Gargantext.Prelude.Config (gc_url)
21 import Gargantext.Database.Prelude
22 -- import Gargantext.Prelude.Config (gc_url)
23 import Gargantext.Prelude.Mail (gargMail, GargMail(..))
24 import Gargantext.Prelude.Mail.Types (MailConfig)
25 import qualified Data.List as List
28 -- | Tool to put elsewhere
29 isEmail :: Text -> Bool
30 isEmail = ((==) 2) . List.length . (splitOn "@")
32 ------------------------------------------------------------------------
33 data SendEmail = SendEmail Bool
35 type EmailAddress = Text
37 type ServerAddress = Text
39 data MailModel = Invitation { invitation_user :: NewUser GargPassword }
40 | PassUpdate { passUpdate_user :: NewUser GargPassword }
41 | MailInfo { mailInfo_username :: Name
42 , mailInfo_address :: EmailAddress
44 | ForgotPassword { user :: UserLight }
45 ------------------------------------------------------------------------
46 ------------------------------------------------------------------------
47 mail :: (CmdM env err m) => MailConfig -> MailModel -> m ()
48 mail mailCfg model = do
51 (m,u) = email_to model
52 subject = email_subject model
53 body = emailWith (view gc_url cfg) model
54 liftBase $ gargMail mailCfg (GargMail { gm_to = m
56 , gm_subject = subject
59 ------------------------------------------------------------------------
60 emailWith :: ServerAddress -> MailModel -> Text
61 emailWith server model =
63 <> bodyWith server model
67 ------------------------------------------------------------------------
68 email_to :: MailModel -> (EmailAddress, Name)
69 email_to (Invitation user) = email_to' user
70 email_to (PassUpdate user) = email_to' user
71 email_to (MailInfo { .. }) = (mailInfo_address, mailInfo_username)
72 email_to (ForgotPassword { user = UserLight { .. }}) = (userLight_email, userLight_username)
74 email_to' :: NewUser GargPassword -> (EmailAddress, Name)
75 email_to' (NewUser u m _) = (m,u)
77 ------------------------------------------------------------------------
78 bodyWith :: ServerAddress -> MailModel -> [Text]
79 bodyWith server (Invitation u) = [ "Congratulation, you have been granted a user account to test the"
80 , "new GarganText platform!"
81 ] <> (email_credentials server u)
83 bodyWith server (PassUpdate u) = [ "Your account password have been updated on the GarganText platform!"
84 ] <> (email_credentials server u)
86 bodyWith server (MailInfo _ _) = [ "Your last analysis is over on the server: " <> server]
87 bodyWith _server (ForgotPassword { user = UserLight { userLight_forgot_password_uuid = Nothing }}) =
88 [ "Cannot send you link to forgot password, no UUID" ]
89 bodyWith server (ForgotPassword { user = UserLight { userLight_forgot_password_uuid = Just uuid }}) =
90 [ "Click on this link to restore your password: "
91 , forgot_password_link server uuid ]
93 forgot_password_link :: ServerAddress -> Text -> Text
94 forgot_password_link server uuid = server <> "/#/forgotPassword?uuid=" <> uuid <> "&server=" <> encodeText server
96 ------------------------------------------------------------------------
97 email_subject :: MailModel -> Text
98 email_subject (Invitation _) = "[GarganText] Invitation"
99 email_subject (PassUpdate _) = "[GarganText] Update"
100 email_subject (MailInfo _ _) = "[GarganText] Info"
101 email_subject (ForgotPassword _) = "[GarganText] Forgot Password"
104 email_credentials :: ServerAddress -> NewUser GargPassword -> [Text]
105 email_credentials server (NewUser u _ (GargPassword p)) =
107 , "You can log in to: " <> server
108 , "Your username is: " <> u
109 , "Your password is: " <> p
113 email_disclaimer :: [Text]
116 , "If you log in you agree with the following terms of use:"
117 , " https://gitlab.iscpif.fr/humanities/tofu/tree/master"
120 , "/!\\ Please note that your account is opened for beta tester only. Hence"
121 , "we cannot guarantee neither the perenniality nor the stability of the"
122 , "service at this stage. It is therefore advisable to back up important"
125 , "/!\\ Gargantext is an academic service supported by ISC-PIF partners."
126 , "In case of congestion on this service, access to members of the ISC-PIF"
127 , "partners will be privileged."
129 , "Your feedback will be valuable for further development of the platform,"
130 , "do not hesitate to contact us and to contribute on our forum:"
132 , " https://discourse.iscpif.fr/c/gargantext"
136 email_signature :: [Text]
138 [ "With our best regards,"
140 , "The Gargantext Team (CNRS)"