diff --git a/.drone.yml b/.drone.yml index 3641467..a58d584 100644 --- a/.drone.yml +++ b/.drone.yml @@ -89,7 +89,7 @@ steps: pull: default image: patwie/tar commands: - - tar -czvf infomark-backend.tar.gz api.yaml infomark README.md LICENSE .infomark.example.yml docker-compose.example.yml database/schema.sql email/*.txt files/uploads/ files/generated_files/ files/common/ database/migrations + - tar -czvf infomark-backend.tar.gz api.yaml infomark README.md LICENSE .infomark.example.yml docker-compose.example.yml database/schema.sql files/uploads/ files/generated_files/ files/common/ database/migrations - name: publish_release image: plugins/github-release @@ -126,6 +126,6 @@ services: --- kind: signature -hmac: 79461cde6a81a50bc7e6ad292872f4a10b9126d206196430cd4accaa4f6a61b9 +hmac: 9b5ce91cb6e211a4489fa641cc548efc75721964c9f92fe97d29eab4a410bf92 ... diff --git a/.infomark.example.yml b/.infomark.example.yml index 348c956..a1b64dc 100644 --- a/.infomark.example.yml +++ b/.infomark.example.yml @@ -29,7 +29,6 @@ db_debug: false # email email_from: no-reply@info2.informatik.uni-tuebingen.de -email_templates_dir: /var/www/infomark-staging/app/email sendmail_binary: /usr/sbin/sendmail email_channel_size: 300 diff --git a/.infomark.yml.ci b/.infomark.yml.ci index 141cac2..b1ecd3e 100644 --- a/.infomark.yml.ci +++ b/.infomark.yml.ci @@ -28,7 +28,6 @@ db_debug: false # email email_from: no-reply@info2.informatik.uni-tuebingen.de -email_templates_dir: /drone/src/email sendmail_binary: /usr/sbin/sendmail email_channel_size: 300 diff --git a/api/app/account.go b/api/app/account.go index 82efc14..518c256 100644 --- a/api/app/account.go +++ b/api/app/account.go @@ -113,7 +113,7 @@ func sendConfirmEmailForUser(user *model.User) error { msg, err := email.NewEmailFromTemplate( user.Email, "Confirm Account Instructions", - "confirm_email.en.txt", + email.ConfirmEmailTemplateEN, map[string]string{ "first_name": user.FirstName, "last_name": user.LastName, diff --git a/api/app/auth.go b/api/app/auth.go index e9afa38..a2a8a8c 100644 --- a/api/app/auth.go +++ b/api/app/auth.go @@ -276,7 +276,7 @@ func (rs *AuthResource) RequestPasswordResetHandler(w http.ResponseWriter, r *ht msg, err := email.NewEmailFromTemplate( user.Email, "Password Reset Instructions", - "request_password_token.en.txt", + email.RequestPasswordTokenTemailTemplateEN, map[string]string{ "first_name": user.FirstName, "last_name": user.LastName, diff --git a/cmd/root.go b/cmd/root.go index c363af9..8aaba45 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -91,13 +91,4 @@ func InitConfig() { if err := viper.ReadInConfig(); err != nil { panic(err) } - - // test if config is correct - // verify path to email templates - rootDir := viper.GetString("email_templates_dir") - filename := fmt.Sprintf("%s/%s", rootDir, "request_password_token.en.txt") - if _, err := os.Stat(filename); os.IsNotExist(err) { - fmt.Println("Path from config file .infomark.yml to email templates is wrong!") - panic(err) - } } diff --git a/email/confirm_email.de.txt b/email/confirm_email.de.txt deleted file mode 100644 index ffab436..0000000 --- a/email/confirm_email.de.txt +++ /dev/null @@ -1,12 +0,0 @@ -Hi {{.first_name}} {{.last_name}}! - - -Sie müssen nun Ihre E-Mail-Adresse bestätigen: - - Um sich in unser System einzuloggen und die Lösungen zu den Übungsblättern hochzuladen. - - Passwort zurücksetzen - - Account-Warnungen erhalten - -Bitte verwende den folgenden Link, um deine E-Mail-Adresse zu bestätigen: - -{{.confirm_email_url}}/{{.confirm_email_address}}/{{.confirm_email_token}} - diff --git a/email/confirm_email.en.txt b/email/confirm_email.en.txt deleted file mode 100644 index 35665c6..0000000 --- a/email/confirm_email.en.txt +++ /dev/null @@ -1,12 +0,0 @@ -Hi {{.first_name}} {{.last_name}}! - - -You must now confirm your email address to: - - Log into our system and upload your homework solutions - - Reset your password - - Receive account alerts - -Please use the following link to confirm your email address: - -{{.confirm_email_url}}/{{.confirm_email_address}}/{{.confirm_email_token}} - diff --git a/email/email.go b/email/email.go index f530285..e6dd5fb 100644 --- a/email/email.go +++ b/email/email.go @@ -63,8 +63,8 @@ func NewEmailFromUser(toEmail string, subject string, body string, user *model.U } // NewEmailFromTemplate creates a new email structure filling a template file -func NewEmailFromTemplate(toEmail string, subject string, file string, data map[string]string) (*Email, error) { - body, err := LoadAndFillTemplate(file, data) +func NewEmailFromTemplate(toEmail string, subject string, tpl *template.Template, data map[string]string) (*Email, error) { + body, err := FillTemplate(tpl, data) if err != nil { return nil, err } @@ -190,3 +190,40 @@ func LoadAndFillTemplate(file string, data map[string]string) (string, error) { err = t.Execute(&tpl, data) return tpl.String(), err } + +// FillTemplate loads a template and fills out the placeholders. +func FillTemplate(t *template.Template, data map[string]string) (string, error) { + var tpl bytes.Buffer + err := t.Execute(&tpl, data) + return tpl.String(), err +} + +const ( + confirmEmailTemplateSrcEN = `Hi {{.first_name}} {{.last_name}}! + +You must now confirm your email address to: + - Log into our system and upload your homework solutions + - Reset your password + - Receive account alerts + +Please use the following link to confirm your email address: + +{{.confirm_email_url}}/{{.confirm_email_address}}/{{.confirm_email_token}} + +` + + requestPasswordTokenTemailTemplateSrcEN = `Hi {{.first_name}} {{.last_name}}! + +We got a request to change your password. You can change your password using the following link. + +{{.reset_password_url}}/{{.email_address}}/{{.reset_password_token}} + +If you have not requested the change, you can ignore this mail. + +Your password can only be changed manually by you. + +` +) + +var ConfirmEmailTemplateEN *template.Template = template.Must(template.New("confirmEmailTemplateSrcEN").Parse(confirmEmailTemplateSrcEN)) +var RequestPasswordTokenTemailTemplateEN *template.Template = template.Must(template.New("requestPasswordTokenTemailTemplateSrcEN").Parse(requestPasswordTokenTemailTemplateSrcEN)) diff --git a/email/email.py b/email/email.py deleted file mode 100644 index fa22115..0000000 --- a/email/email.py +++ /dev/null @@ -1,17 +0,0 @@ -import os - - -def sendMail(): - sendmail_location = "/usr/sbin/sendmail" # sendmail location - p = os.popen("%s -t" % sendmail_location, "w") - p.write("From: %s\n" % "no-reply@info2.informatik.uni-tuebingen.de") - p.write("To: %s\n" % "patrick.wieschollek@uni-tuebingen.de") - p.write("Subject: TestSubject\n") - p.write("\n") # blank line separating headers from body - p.write("body of the mail") - status = p.close() - if status != 0: - print("Sendmail exit status", status) - - -sendMail() \ No newline at end of file diff --git a/email/request_password_token.de.txt b/email/request_password_token.de.txt deleted file mode 100644 index 5b55793..0000000 --- a/email/request_password_token.de.txt +++ /dev/null @@ -1,9 +0,0 @@ -Hallo {{.first_name}} {{.last_name}}! - -Es gab eine Anfrage dein Passwort zu ändern. Du kannst dies mittels Klick auf folgendne Link durchführen. - -{{.reset_password_url}}/{{.email_address}}/{{.reset_password_token}} - -Wenn du die Änderung nicht angefragt hast, kannst du diese Mail ruhig ignorieren. - -Dein Passwort kann nur durch dich manuell geändert werden. diff --git a/email/request_password_token.en.txt b/email/request_password_token.en.txt deleted file mode 100644 index 892b79e..0000000 --- a/email/request_password_token.en.txt +++ /dev/null @@ -1,9 +0,0 @@ -Hi {{.first_name}} {{.last_name}}! - -We got a request to change your password. You can change your password using the following link. - -{{.reset_password_url}}/{{.email_address}}/{{.reset_password_token}} - -If you have not requested the change, you can ignore this mail. - -Your password can only be changed manually by you. diff --git a/symbol/version.go b/symbol/version.go index e848417..0eeb1e9 100644 --- a/symbol/version.go +++ b/symbol/version.go @@ -32,7 +32,7 @@ var ( // VersionPatch is for backwards-compatible bug fixes. VersionPatch int64 = 1 // VersionPre indicates prerelease. - VersionPre = "beta" + VersionPre = "beta-1" // VersionDev indicates development branch. Releases will be empty string. VersionDev string )