Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Commit

Permalink
Merge branch 'versioning'
Browse files Browse the repository at this point in the history
  • Loading branch information
PatWie committed May 13, 2019
2 parents 1ac041c + 975ed9d commit 4cc6b50
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -126,6 +126,6 @@ services:

---
kind: signature
hmac: bec11f987bcc8b10e923674bbb63e983c274ee5b007d2f2ae9a703f8f6e829cd
hmac: 9b5ce91cb6e211a4489fa641cc548efc75721964c9f92fe97d29eab4a410bf92

...
1 change: 0 additions & 1 deletion .infomark.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ db_debug: false

# email
email_from: [email protected]
email_templates_dir: /var/www/infomark-staging/app/email
sendmail_binary: /usr/sbin/sendmail
email_channel_size: 300

Expand Down
1 change: 0 additions & 1 deletion .infomark.yml.ci
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ db_debug: false

# email
email_from: [email protected]
email_templates_dir: /drone/src/email
sendmail_binary: /usr/sbin/sendmail
email_channel_size: 300

Expand Down
2 changes: 1 addition & 1 deletion api/app/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion api/app/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
12 changes: 0 additions & 12 deletions email/confirm_email.de.txt

This file was deleted.

12 changes: 0 additions & 12 deletions email/confirm_email.en.txt

This file was deleted.

41 changes: 39 additions & 2 deletions email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
17 changes: 0 additions & 17 deletions email/email.py

This file was deleted.

9 changes: 0 additions & 9 deletions email/request_password_token.de.txt

This file was deleted.

9 changes: 0 additions & 9 deletions email/request_password_token.en.txt

This file was deleted.

2 changes: 1 addition & 1 deletion symbol/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 4cc6b50

Please sign in to comment.