Beispiel #1
0
func TestRenderTemplate(t *testing.T) {
	templateString := "Hello, {{.Value}}!"
	templateValues := struct{ Value string }{"world"}

	actual, err := util.RenderTemplate(templateString, templateValues)

	assert.Nil(t, err)
	assert.Equal(t, "Hello, world!", actual)
}
Beispiel #2
0
func (self authImpl) sendResetPaswordEmail(resetKeyToken privateResetToken) (resetTokenStr string, err error) {
	resetTokenStr, err = resetKeyToken.toString(self.cfg.JwtKey)
	if err != nil {
		return
	}

	templateValues := struct{ ResetTokenStr string }{resetTokenStr}
	body, err := util.RenderTemplate(self.cfg.ResetPasswordEmail[resetKeyToken.lang].Body, templateValues)
	if err != nil {
		return
	}

	mail := mailer.Mail{
		From:    self.cfg.FromEmail,
		To:      []string{resetKeyToken.email},
		Subject: self.cfg.ResetPasswordEmail[resetKeyToken.lang].Subject,
		Body:    body,
	}

	return resetTokenStr, self.mailer.Send(mail)
}
Beispiel #3
0
func (self authImpl) sendConfirmationEmail(email, lang, confirmationKey string) (confirmationTokenStr string, err error) {
	confirmationToken := privateConfirmationToken{email, lang, confirmationKey}
	confirmationTokenStr, err = confirmationToken.toString(self.cfg.JwtKey)
	if err != nil {
		return
	}

	templateValues := struct{ ConfirmationTokenStr string }{confirmationTokenStr}
	body, err := util.RenderTemplate(self.cfg.ConfirmationEmail[lang].Body, templateValues)
	if err != nil {
		return
	}

	mail := mailer.Mail{
		From:    self.cfg.FromEmail,
		To:      []string{email},
		Subject: self.cfg.ConfirmationEmail[lang].Subject,
		Body:    body,
	}

	return confirmationTokenStr, self.mailer.Send(mail)
}