From 6236c7132ed7e1c03ae3c6560927a788cd34fa19 Mon Sep 17 00:00:00 2001 From: Irae Hueck Costa Date: Sun, 24 Mar 2024 14:43:59 +0000 Subject: [PATCH] Survey --- backend/endpoints/register.go | 2 ++ backend/models/user.go | 47 ++++++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/backend/endpoints/register.go b/backend/endpoints/register.go index 654a6bd6..bd3b1d66 100644 --- a/backend/endpoints/register.go +++ b/backend/endpoints/register.go @@ -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() diff --git a/backend/models/user.go b/backend/models/user.go index 91443f93..fcd0be34 100644 --- a/backend/models/user.go +++ b/backend/models/user.go @@ -17,6 +17,24 @@ import ( ) +var surveySender string = "hey@counter.dev" +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 = "hey@counter.dev" +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. @@ -34,10 +52,6 @@ Cheers, The counter.dev team` -var passwordRecoverySender string = "hey@counter.dev" -var passwordRecoverSubject string = "Forgot your password?" - - var uuid2id = map[string]string{} type User struct { @@ -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)