improvements for notifyer microservice
This commit is contained in:
parent
16260ecedb
commit
2e70087f63
@ -14,7 +14,7 @@ const MSG_TEXT = `
|
||||
<body>
|
||||
<p>{{.Text}}</p>
|
||||
{{if .Link}}
|
||||
<a href="{{.Link}}">Click</a>link</p>
|
||||
<a href="{{.Link}}">link</a>
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
||||
@ -34,7 +34,7 @@ func NewEmailer(conf ConfigSMTP) (*Emailer, error) {
|
||||
}
|
||||
defer closer.Close()
|
||||
|
||||
htmlTemplate, err := template.New("verify-email").Parse(MSG_TEXT)
|
||||
htmlTemplate, err := template.New("email").Parse(MSG_TEXT)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -52,22 +52,23 @@ type Emailer struct {
|
||||
dialer *gomail.Dialer
|
||||
}
|
||||
|
||||
func (e *Emailer) SendRestorePassword(email, token string) error {
|
||||
func (e *Emailer) SendRestorePassword(email, link string) error {
|
||||
return e.sendEmail("Restore your password", email, MailContent{
|
||||
Text: "Token: " + token,
|
||||
Text: "You received this message do request of password change. Use this link to change your password:",
|
||||
Link: link,
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Emailer) SendVerifyUser(email, link string) error {
|
||||
return e.sendEmail("Verify your email", email, MailContent{
|
||||
Text: "You recieved this message due to registration of account. Use this link to verify email:",
|
||||
Text: "You received this message due to registration of account. Use this link to verify email:",
|
||||
Link: link,
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Emailer) SendPasswordChanged(email string) error {
|
||||
return e.sendEmail("Password changed", email, MailContent{
|
||||
Text: "You recieved this message due to password change",
|
||||
Text: "Your password was successfully changed",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,8 @@ func (e *EventHandler) handleEvent(ctx context.Context, msg kafka.Message) error
|
||||
// TODO: add context somehow
|
||||
switch string(msg.Key) {
|
||||
case "email_forgot_password":
|
||||
return e.emailer.SendRestorePassword(event.Email, event.Token)
|
||||
link := fmt.Sprintf("%s/restore-password?token=%s", e.config.App.ServiceUrl, event.Token)
|
||||
return e.emailer.SendRestorePassword(event.Email, link)
|
||||
case "email_password_changed":
|
||||
return e.emailer.SendPasswordChanged(event.Email)
|
||||
case "email_verify_user":
|
||||
|
||||
@ -35,7 +35,7 @@ func (e *EventRepo) sendEmail(ctx context.Context, email, actionToken, eventType
|
||||
return err
|
||||
}
|
||||
|
||||
return e.kafka.SendMessage(ctx, eventType, valueBytes)
|
||||
return e.kafka.PushMessage(ctx, eventType, valueBytes)
|
||||
}
|
||||
|
||||
func (e *EventRepo) SendEmailPasswordChanged(ctx context.Context, email string) error {
|
||||
|
||||
@ -26,7 +26,7 @@ func NewKafka(addr, topic string) *Kafka {
|
||||
}
|
||||
}
|
||||
|
||||
func (k *Kafka) SendMessage(ctx context.Context, key string, value []byte) error {
|
||||
func (k *Kafka) PushMessage(ctx context.Context, key string, value []byte) error {
|
||||
return k.writer.WriteMessages(
|
||||
context.Background(),
|
||||
kafka.Message{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user