2 Module : Gargantext.Database.Action.User
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 module Gargantext.Database.Action.User
17 -- import Data.Maybe (catMaybes)
18 import Data.Text (Text, unlines)
19 import Gargantext.Database.Query.Table.User
20 import Gargantext.Core.Types.Individu
21 import Gargantext.Database.Prelude
22 import Gargantext.Prelude
23 import Gargantext.Prelude.Mail (gargMail, GargMail(..))
24 import Gargantext.Database.Query.Table.Node.Error (HasNodeError(..), nodeError, NodeError(..))
25 import Gargantext.Database.Action.Flow (getOrMkRoot)
27 ------------------------------------------------------------------------
28 mkUser :: HasNodeError err => Text -> NewUser GargPassword -> Cmd err Int64
29 mkUser address u = mkUsers address [u]
31 mkUsers :: HasNodeError err => Text -> [NewUser GargPassword] -> Cmd err Int64
32 mkUsers address us = do
33 us' <- liftBase $ mapM toUserHash us
34 r <- insertUsers $ map toUserWrite us'
35 _ <- mapM getOrMkRoot $ map (\u -> UserName (_nu_username u)) us
36 _ <- liftBase $ mapM (mail Invitation address) us
38 ------------------------------------------------------------------------
39 updateUser :: HasNodeError err => Text -> NewUser GargPassword -> Cmd err Int64
40 updateUser address u = do
41 u' <- liftBase $ toUserHash u
42 n <- updateUserDB $ toUserWrite u'
43 _ <- liftBase $ mail Update address u
46 ------------------------------------------------------------------------
47 data Mail = Invitation
51 -- TODO gargantext.ini config
52 mail :: Mail -> Text -> NewUser GargPassword -> IO ()
53 mail mtype address nu@(NewUser u m _) = gargMail (GargMail m (Just u) subject body)
55 subject = "[Your Garg Account]"
56 body = bodyWith mtype address nu
58 bodyWith :: Mail -> Text -> NewUser GargPassword -> Text
59 bodyWith Invitation add nu = logInstructions add nu
60 bodyWith Update add nu = updateInstructions add nu
63 -- TODO put this in a configurable file (path in gargantext.ini)
64 logInstructions :: Text -> NewUser GargPassword -> Text
65 logInstructions address (NewUser u _ (GargPassword p)) =
67 , "You have been invited to test the new GarganText platform!"
69 , "You can log on to: " <> address
70 , "Your login is: " <> u
71 , "Your password is: " <> p
73 , "Please read the full terms of use on:"
74 , "https://gitlab.iscpif.fr/humanities/tofu/tree/master"
76 , "Your feedback will be valuable for further development"
77 , "of the platform, do not hesitate to contact us and"
78 , "to contribute on our forum:"
79 , " https://discourse.iscpif.fr/c/gargantext"
81 , "With our best regards,"
83 , "The Gargantext Team (CNRS)"
86 updateInstructions :: Text -> NewUser GargPassword -> Text
87 updateInstructions address (NewUser u _ (GargPassword p)) =
89 , "Your account have been updated on the GarganText platform!"
91 , "You can log on to: " <> address
92 , "Your login is: " <> u
93 , "Your password is: " <> p
95 , "As reminder, please read the full terms of use on:"
96 , "https://gitlab.iscpif.fr/humanities/tofu/tree/master"
98 , "Your feedback is always valuable for further development"
99 , "of the platform, do not hesitate to contact us and"
100 , "to contribute on our forum:"
101 , " https://discourse.iscpif.fr/c/gargantext"
103 , "With our best regards,"
105 , "The Gargantext Team (CNRS)"
110 ------------------------------------------------------------------------
111 rmUser :: HasNodeError err => User -> Cmd err Int64
112 rmUser (UserName un) = deleteUsers [un]
113 rmUser _ = nodeError NotImplYet
116 rmUsers :: HasNodeError err => [User] -> Cmd err Int64
118 rmUsers _ = undefined