Skip to content

Commit

Permalink
feat: send verification email
Browse files Browse the repository at this point in the history
  • Loading branch information
ayaanqui committed Apr 28, 2024
1 parent a259cb2 commit 07cff92
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
11 changes: 8 additions & 3 deletions graph/resolver/user.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions services/email_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package services

import (
"github.com/sendgrid/rest"
"github.com/sendgrid/sendgrid-go/helpers/mail"
"github.com/stadio-app/stadio-backend/database/jet/postgres/public/model"
"github.com/stadio-app/stadio-backend/graph/gmodel"
)

func (service Service) SendTemplateEmail(
to *mail.Email,
subject string,
template_id string,
template_data map[string]any,
) (*rest.Response, error) {
from := mail.NewEmail("Stadio", "[email protected]")
email := mail.NewV3MailInit(from, subject, to)
email.SetTemplateID(template_id)

personalization := mail.NewPersonalization()
personalization.AddTos(to)
for key, val := range template_data {
personalization.SetDynamicTemplateData(key, val)
}
email.AddPersonalizations(personalization)
return service.Sendgrid.Send(email)
}

func (service Service) SendEmailVerification(user gmodel.User, email_verification model.EmailVerification) (*rest.Response, error) {
to := mail.NewEmail(user.Name, user.Email)
data := map[string]any{
"user": map[string]any{
"id": user.ID,
"name": user.Name,
"email": user.Email,
},
"code": email_verification.Code,
}
return service.SendTemplateEmail(
to,
"Stadio: Email verification code",
service.Tokens.SendGrid.Templates.EmailVerification,
data,
)
}

0 comments on commit 07cff92

Please sign in to comment.