Skip to content

Commit

Permalink
Survey
Browse files Browse the repository at this point in the history
  • Loading branch information
Irae Hueck Costa committed Mar 24, 2024
1 parent a3e0774 commit 6236c71
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 2 additions & 0 deletions backend/endpoints/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func init() {
err := user.SetPref("mail", mail)
ctx.CatchError(err)
}

user.SendSurvey(ctx.App.Config.MailgunSecretApiKey)
ctx.SetSessionUser(userId)
ctx.ReturnUser()

Expand Down
47 changes: 43 additions & 4 deletions backend/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ import (
)


var surveySender string = "[email protected]"
var surveySubject string = "Is counter.dev useful?"
var surveyText string = `Hello %s,
you registered to https://counter.dev/ some days ago. In order to improve the service we would like to ask you three very short questions: https://forms.gle/EFZaq5zKv6YGdPro9
Feel free to write anything that might be in your mind as a reply to this email as well.
Thank you. Your feedback is appreciated!
Your counter.dev team`




var passwordRecoverySender string = "[email protected]"
var passwordRecoverSubject string = "Forgot your password?"
var passwordRecoveryContent string = `Hello %s,
You - or possibly someone else - requested to recover your account. Therefore we created an alternative temporary password.
Expand All @@ -34,10 +52,6 @@ Cheers,
The counter.dev team`


var passwordRecoverySender string = "[email protected]"
var passwordRecoverSubject string = "Forgot your password?"


var uuid2id = map[string]string{}

type User struct {
Expand Down Expand Up @@ -412,6 +426,31 @@ func (user User) PasswordRecovery(mailgunSecretApiKey string) error {
return nil
}

func (user User) SendSurvey(mailgunSecretApiKey string) error {
mail, err := user.GetPref("mail")
if err != nil {
return err
}
if mail == "" {
return nil
}
mg := mailgun.NewMailgun("counter.dev", mailgunSecretApiKey)

body := fmt.Sprintf(surveyText, user.Id)
message := mg.NewMessage(surveySender, surveySubject, body, mail)
message.SetDeliveryTime(time.Now().Add(24 * 2 * time.Second))

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

_, _, err = mg.Send(ctx, message)

if err != nil {
return err
}
return nil
}


func (user User) RegisterSubscriptionID(subscriptionID string) error{
_, err := user.redis.Do("HSET", "subscription", user.Id, subscriptionID)
Expand Down

0 comments on commit 6236c71

Please sign in to comment.