diff --git a/.gitignore b/.gitignore index ed18e73..b7df8f3 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ go.work !*.go !*.html +!*.tmpl !*.css !go.sum !go.mod diff --git a/configs/config.template.json b/configs/config.template.json index 0dc9e8d..41b6866 100644 --- a/configs/config.template.json +++ b/configs/config.template.json @@ -1,5 +1,7 @@ { + "WebsiteTitle": "My Carsharing Site", "BaseURL": "https://domain.de", + "Environment": "dev", "db": { "Path": "data/db.sqlite3" }, @@ -8,13 +10,13 @@ "User": "username", "Password": "password", "Port": 465, - "Mailtype": "html", "AdminEmail": "admin@server.com" }, "templates": { "MailPath": "templates/email", "HTMLPath": "templates/html", - "StaticPath": "templates/css" + "StaticPath": "templates/css", + "LogoURI": "/images/LOGO.png" }, "auth": { "APIKey": "" diff --git a/internal/config/config.go b/internal/config/config.go index 157ca33..62c6adb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -33,7 +33,6 @@ type SMTPConfig struct { Host string `json:"Host" envconfig:"SMTP_HOST"` User string `json:"User" envconfig:"SMTP_USER"` Password string `json:"Password" envconfig:"SMTP_PASS"` - Mailtype string `json:"Mailtype" default:"html" envconfig:"MAIL_TYPE"` AdminEmail string `json:"AdminEmail" envconfig:"ADMIN_MAIL"` Port int `json:"Port" default:"465" envconfig:"SMTP_PORT"` } @@ -42,6 +41,7 @@ type TemplateConfig struct { MailPath string `json:"MailPath" default:"templates/email" envconfig:"TEMPLATE_MAIL_PATH"` HTMLPath string `json:"HTMLPath" default:"templates/html" envconfig:"TEMPLATE_HTML_PATH"` StaticPath string `json:"StaticPath" default:"templates/css" envconfig:"TEMPLATE_STATIC_PATH"` + LogoURI string `json:"LogoURI" envconfig:"LOGO_URI"` } type RecipientsConfig struct { @@ -60,6 +60,7 @@ type Config struct { Templates TemplateConfig `json:"templates"` Recipients RecipientsConfig `json:"recipients"` ConfigFilePath string `json:"config_file_path" envconfig:"CONFIG_FILE_PATH"` + WebsiteTitle string `json:"WebsiteTitle" envconfig:"WEBSITE_TITLE"` BaseURL string `json:"BaseUrl" envconfig:"BASE_URL"` Env string `json:"Environment" default:"development" envconfig:"ENV"` DB DatabaseConfig `json:"db"` @@ -68,16 +69,17 @@ type Config struct { } var ( - BaseURL string - CFGPath string - CFG Config - Auth AuthenticationConfig - DB DatabaseConfig - Templates TemplateConfig - SMTP SMTPConfig - Recipients RecipientsConfig - Env string - Security SecurityConfig + BaseURL string + WebsiteTitle string + CFGPath string + CFG Config + Auth AuthenticationConfig + DB DatabaseConfig + Templates TemplateConfig + SMTP SMTPConfig + Recipients RecipientsConfig + Env string + Security SecurityConfig ) var environmentOptions map[string]bool = map[string]bool{ "development": true, @@ -117,6 +119,7 @@ func LoadConfig() { Recipients = CFG.Recipients Security = CFG.Security Env = CFG.Env + WebsiteTitle = CFG.WebsiteTitle logger.Info.Printf("Config loaded: %#v", CFG) } diff --git a/internal/controllers/user_controller_test.go b/internal/controllers/user_controller_test.go index d3116f6..2acdf11 100644 --- a/internal/controllers/user_controller_test.go +++ b/internal/controllers/user_controller_test.go @@ -128,6 +128,12 @@ func checkWelcomeMail(message *utils.Email, user *models.User) error { if !strings.Contains(message.Body, config.BaseURL) { return fmt.Errorf("Base Url (%v) has not been rendered in registration mail.", config.BaseURL) } + if !strings.Contains(message.Body, config.BaseURL+config.Templates.LogoURI) { + return fmt.Errorf("Logo Url (%v) has not been rendered in registration mail.", config.BaseURL+config.WebsiteTitle) + } + if !strings.Contains(message.Body, config.WebsiteTitle) { + return fmt.Errorf("Website title (%v) has not been rendered in registration mail.", config.WebsiteTitle) + } return nil } diff --git a/internal/services/email_service.go b/internal/services/email_service.go index 1b7797a..f78b0ee 100644 --- a/internal/services/email_service.go +++ b/internal/services/email_service.go @@ -74,7 +74,7 @@ func (s *EmailService) SendVerificationEmail(user *models.User, token *string) e } subject := constants.MailVerificationSubject - body, err := ParseTemplate("mail_verification.html", data) + body, err := ParseTemplate("mail_verification.tmpl", data) if err != nil { logger.Error.Print("Couldn't send verification mail") return err @@ -92,6 +92,8 @@ func (s *EmailService) SendWelcomeEmail(user *models.User) error { BASEURL string MembershipID int64 MembershipFee float32 + Logo string + WebsiteTitle string RentalFee float32 }{ Company: user.Company, @@ -101,10 +103,12 @@ func (s *EmailService) SendWelcomeEmail(user *models.User) error { MembershipFee: float32(user.Membership.SubscriptionModel.MonthlyFee), RentalFee: float32(user.Membership.SubscriptionModel.HourlyRate), BASEURL: config.BaseURL, + WebsiteTitle: config.WebsiteTitle, + Logo: config.Templates.LogoURI, } subject := constants.MailWelcomeSubject - body, err := ParseTemplate("mail_welcome.html", data) + body, err := ParseTemplate("mail_welcome.tmpl", data) if err != nil { logger.Error.Print("Couldn't send welcome mail") return err @@ -130,6 +134,8 @@ func (s *EmailService) SendRegistrationNotification(user *models.User) error { MembershipID int64 RentalFee float32 MembershipFee float32 + Logo string + WebsiteTitle string }{ Company: user.Company, FirstName: user.FirstName, @@ -146,10 +152,12 @@ func (s *EmailService) SendRegistrationNotification(user *models.User) error { Phone: user.Phone, IBAN: user.BankAccount.IBAN, BASEURL: config.BaseURL, + Logo: config.Templates.LogoURI, + WebsiteTitle: config.WebsiteTitle, } subject := constants.MailRegistrationSubject - body, err := ParseTemplate("mail_registration.html", data) + body, err := ParseTemplate("mail_registration.tmpl", data) if err != nil { logger.Error.Print("Couldn't send admin notification mail") return err @@ -159,16 +167,20 @@ func (s *EmailService) SendRegistrationNotification(user *models.User) error { func (s *EmailService) RelayContactFormMessage(sender string, name string, message string) error { data := struct { - Message string - Name string - BASEURL string + Message string + Name string + BASEURL string + Logo string + WebsiteTitle string }{ - Message: message, - Name: name, - BASEURL: config.BaseURL, + Message: message, + Name: name, + BASEURL: config.BaseURL, + Logo: config.Templates.LogoURI, + WebsiteTitle: config.WebsiteTitle, } subject := constants.MailContactSubject - body, err := ParseTemplate("mail_contact_form.html", data) + body, err := ParseTemplate("mail_contact_form.tmpl", data) if err != nil { logger.Error.Print("Couldn't send contact form message mail") return err diff --git a/templates/email/mail_contact_form.html b/templates/email/mail_contact_form.html deleted file mode 100644 index 7b12d21..0000000 --- a/templates/email/mail_contact_form.html +++ /dev/null @@ -1,89 +0,0 @@ - - -
-|
-
-
- Moin Du Vorstand 👋,
-
-
-
- Eine neue Kontaktanfrage
- Hier ist die Nachricht:
-
-
-
- {{.Message}} -
-
- -
-
- Mit freundlichen Grüßen, -Dein untertänigster Wolkenrechner - |
-
|
+
+
+ Moin Du Vorstand 👋,
+
+
+
+
+ Eine neue Kontaktanfrage
+ Hier ist die Nachricht:
+
+
+
+ {{.Message}} +
+
+ +
+
+ Mit freundlichen Grüßen, +Dein untertänigster Wolkenrechner + |
+

