-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
537 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ import ( | |
type EmailServiceInterface interface { | ||
SendPasswordResetEmail(name, email, token string) *errors.Error | ||
SendEmailVerification(email, code string) *errors.Error | ||
SendWelcomeEmail(name, email string) *errors.Error | ||
SendPasswordChangedEmail(name, email string) *errors.Error | ||
} | ||
|
||
type EmailService struct { | ||
|
@@ -66,6 +68,48 @@ func (e *EmailService) SendEmailVerification(email, code string) *errors.Error { | |
return nil | ||
} | ||
|
||
func (e *EmailService) SendWelcomeEmail(name, email string) *errors.Error { | ||
template, err := getTemplateString("welcome") | ||
if err != nil { | ||
return &errors.FailedToGetTemplate | ||
} | ||
|
||
params := &resend.SendEmailRequest{ | ||
From: "[email protected]", | ||
To: []string{email}, | ||
Subject: "Welcome to Resend", | ||
Html: fmt.Sprintf(*template, name), | ||
} | ||
|
||
_, err = e.Client.Emails.Send(params) | ||
if err != nil { | ||
return &errors.FailedToSendEmail | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (e *EmailService) SendPasswordChangedEmail(name, email string) *errors.Error { | ||
template, err := getTemplateString("password_change_complete") | ||
if err != nil { | ||
return &errors.FailedToGetTemplate | ||
} | ||
|
||
params := &resend.SendEmailRequest{ | ||
From: "[email protected]", | ||
To: []string{email}, | ||
Subject: "Password Changed", | ||
Html: fmt.Sprintf(*template, name), | ||
} | ||
|
||
_, err = e.Client.Emails.Send(params) | ||
if err != nil { | ||
return &errors.FailedToSendEmail | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func getTemplateString(name string) (*string, error) { | ||
// TODO: use default file location | ||
cwd, err := os.Getwd() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.