added new user sign in
parent
4adb4606b6
commit
d0037a41fb
|
@ -3,6 +3,7 @@ package rabbitmq
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"clickandjoin.app/emailserver/mailer"
|
||||
"clickandjoin.app/emailserver/modules/config"
|
||||
|
@ -74,8 +75,15 @@ func Init() {
|
|||
continue
|
||||
}
|
||||
|
||||
logrus.Println(mailMessage.UserMail, strings.HasSuffix(mailMessage.UserMail, "@roese.dev"), strings.HasSuffix(mailMessage.UserMail, "@umbach.dev"))
|
||||
|
||||
// only for testing
|
||||
if !strings.HasSuffix(mailMessage.UserMail, "@roese.dev") && !strings.HasSuffix(mailMessage.UserMail, "@umbach.dev") {
|
||||
mailMessage.UserMail = "info@clickandjoin.de"
|
||||
}
|
||||
|
||||
err = mailer.NewMail(structs.Mail{
|
||||
To: []string{"info@clickandjoin.de"},
|
||||
To: []string{mailMessage.UserMail},
|
||||
TemplateId: mailMessage.TemplateId,
|
||||
LanguageId: mailMessage.LanguageId,
|
||||
BodyData: mailMessage.BodyData})
|
||||
|
|
|
@ -35,7 +35,7 @@ func (m *Mail) Send(body string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
logrus.Debugln("send mail", msg)
|
||||
logrus.Debugln("SEND MAIL", msg)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -43,57 +43,44 @@ func (m *Mail) RenderTemplate() (string, error) {
|
|||
body := cache.BodyTemplates[m.TemplateId]
|
||||
|
||||
for templateName, templateData := range cache.Templates.Templates {
|
||||
// Skipping templates if the template ID is not the expected one
|
||||
if templateName != m.TemplateId {
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Debugln("RENDER TEMPLATE", templateName, templateData)
|
||||
|
||||
m.Subject = templateData["mailSubject"][m.LanguageId]
|
||||
|
||||
// occurs if the requested language code does not exist
|
||||
if m.Subject == "" {
|
||||
m.Subject = templateData["mailSubject"][config.Cfg.DefaultLanguageCode]
|
||||
}
|
||||
|
||||
// replace body %values% with values in templates config
|
||||
for key, value := range templateData {
|
||||
logrus.Debugln("key", key, "value", value)
|
||||
|
||||
if key == "mailSubject" {
|
||||
continue
|
||||
}
|
||||
|
||||
body = []byte(strings.Replace(string(body), "%"+key+"%", value[m.LanguageId], -1))
|
||||
v := value[m.LanguageId]
|
||||
|
||||
// occurs if the requested language code does not exist
|
||||
if v == "" {
|
||||
v = value[config.Cfg.DefaultLanguageCode]
|
||||
}
|
||||
|
||||
body = []byte(strings.Replace(string(body), "%"+key+"%", v, -1))
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Println("body", string(body))
|
||||
|
||||
t := template.Must(template.New("").Parse(string(body)))
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
logrus.Println("bodyData", m.BodyData)
|
||||
|
||||
if err := t.Execute(buf, m.BodyData); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// define subject from config
|
||||
/*
|
||||
m.Subject = templates.Templates[m.TemplateId].Languages[m.LanguageId].Subject
|
||||
|
||||
body := templates.Templates[m.TemplateId].Body
|
||||
|
||||
// replace body %values% with values in templates config
|
||||
for key, value := range templates.Templates[m.TemplateId].Languages[m.LanguageId].Texts {
|
||||
strKey := fmt.Sprintf("%v", key)
|
||||
strValue := fmt.Sprintf("%v", value)
|
||||
|
||||
logrus.Infoln("a", strKey, strValue)
|
||||
|
||||
body = strings.Replace(body, "%"+strKey+"%", strValue, -1)
|
||||
}
|
||||
|
||||
t := template.Must(template.New("").Parse(body))
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
if err := t.Execute(buf, m.BodyData); err != nil {
|
||||
logrus.Fatalln("Error executing body data", err)
|
||||
} */
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html>
|
||||
<body>
|
||||
<h1>%header%</h1>
|
||||
<p>%informationText%</p>
|
||||
</body>
|
||||
</html>
|
|
@ -21,6 +21,20 @@
|
|||
"en": "Alternatively you can click on the link here",
|
||||
"de": "Alternativ kannst du auch hier auf den Link klicken"
|
||||
}
|
||||
},
|
||||
"newUserSignIn": {
|
||||
"mailSubject": {
|
||||
"en": "A new sign-in was detected",
|
||||
"de": "Neue Anmeldung wurde festgestellt"
|
||||
},
|
||||
"header": {
|
||||
"en": "Good day,",
|
||||
"de": "Guten Tag,"
|
||||
},
|
||||
"informationText": {
|
||||
"en": "a new sign-in on <b>{{.device}}</b> was detected",
|
||||
"de": "eine neue Anmeldung auf <b>{{.device}}</b> wurde festgestellt"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue