-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot_password.go
More file actions
43 lines (34 loc) · 1.1 KB
/
Copy pathforgot_password.go
File metadata and controls
43 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) Kopexa GmbH
// SPDX-License-Identifier: BUSL-1.1
package comms
import (
"context"
"fmt"
"html/template"
"github.com/kopexa-grc/comms/v2/driver"
)
// SendForgotPasswordEmail sends a password reset email to a recipient.
// The email contains a one-time code that can be used to reset the password.
func (c *Comms) SendForgotPasswordEmail(ctx context.Context, recipient Recipient, url string) error {
if err := recipient.Validate(); err != nil {
return fmt.Errorf("invalid recipient: %w", err)
}
text, html, err := Render(recipient.Lang(), "forgot-password", map[string]any{
"DisplayName": recipient.Name(),
"URL": template.URL(url), // nolint:gosec
})
if err != nil {
return fmt.Errorf("failed to render forgot password email: %w", err)
}
message := driver.Message{
From: c.config.From,
To: []string{recipient.String()},
Subject: Subject("forgot-password", recipient.Lang()),
Text: text,
HTML: html,
}
if err := c.config.Driver.Send(ctx, message); err != nil {
return fmt.Errorf("failed to send forgot password email: %w", err)
}
return nil
}