Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Say hello to paid customers

vishnukvmdc0ceb68dc689
diff --git a/server/pkg/controller/email/email_notification.go b/server/pkg/controller/email/email_notification.go
index 328a094ce4..a825f61b12 100644
--- a/server/pkg/controller/email/email_notification.go
+++ b/server/pkg/controller/email/email_notification.go
@@ -18,6 +18,11 @@ const (
MobileAppFirstUploadTemplate = "mobile_app_first_upload.html"
FirstUploadEmailSubject = "Congratulations! πŸŽ‰"
+ CustomerHelloMailLock = "customer_hello_mail_lock"
+ CustomerHelloSubject = "Hello from Ente"
+ CustomerHelloTemplate = "customer_hello.html"
+ CustomerHelloTemplateID = "customer_hello"
+
StorageLimitExceededMailLock = "storage_limit_exceeded_mail_lock"
StorageLimitExceededTemplateID = "storage_limit_exceeded"
StorageLimitExceededTemplate = "storage_limit_exceeded.html"
@@ -158,6 +163,45 @@ func (c *EmailNotificationController) OnSubscriptionCancelled(userID int64) {
}
}
+// SayHelloToCustomers sends an email to check in with customers who upgraded 7
+// days ago.
+func (c *EmailNotificationController) SayHelloToCustomers() {
+ log.Info("Running SayHelloToCustomers")
+ lockStatus := c.LockController.TryLock(CustomerHelloMailLock, time.MicrosecondsAfterHours(24))
+ if !lockStatus {
+ log.Error("Could not acquire lock to send customer hellos")
+ return
+ }
+ defer c.LockController.ReleaseLock(CustomerHelloMailLock)
+
+ users, err := c.UserRepo.GetUsersWhoUpgradedNDaysAgo(7)
+ if err != nil {
+ log.Error("Error while fetching users", err)
+ return
+ }
+ for _, u := range users {
+ lastNotificationTime, err := c.NotificationHistoryRepo.GetLastNotificationTime(u.ID, CustomerHelloTemplateID)
+ logger := log.WithFields(log.Fields{
+ "user_id": u.ID,
+ "email": u.Email,
+ })
+ if err != nil {
+ logger.Error("Could not fetch last notification time", err)
+ continue
+ }
+ if lastNotificationTime > 0 {
+ continue
+ }
+ logger.Info("Sending hello email to customer")
+ err = email.SendTemplatedEmail([]string{u.Email}, "[email protected]", "[email protected]", CustomerHelloSubject, CustomerHelloTemplate, nil, nil)
+ if err != nil {
+ logger.Info("Error notifying", err)
+ continue
+ }
+ c.NotificationHistoryRepo.SetLastNotificationTimeToNow(u.ID, CustomerHelloTemplateID)
+ }
+}
+
func (c *EmailNotificationController) SendStorageLimitExceededMails() {
if c.isSendingStorageLimitExceededMails {
log.Info("Skipping sending storage limit exceeded mails as another instance is still running")
diff --git a/server/pkg/repo/user.go b/server/pkg/repo/user.go
index aa7d6145d5..bac3aaf2f1 100644
--- a/server/pkg/repo/user.go
+++ b/server/pkg/repo/user.go
@@ -332,6 +332,35 @@ func (repo *UserRepository) GetUsersWithIndividualPlanWhoHaveExceededStorageQuot
return users, nil
}
+func (repo *UserRepository) GetUsersWhoUpgradedNDaysAgo(days int) ([]ente.User, error) {
+ rows, err := repo.DB.Query(`
+ SELECT u.user_id, u.encrypted_email, u.email_decryption_nonce, u.email_hash, u.creation_time
+ FROM users u
+ INNER JOIN subscriptions s ON u.user_id = s.user_id
+ WHERE s.upgraded_at >= $1 AND s.upgraded_at < $2 AND u.encrypted_email IS NOT NULL`,
+ time.MicrosecondsBeforeDays(days+1), time.MicrosecondsBeforeDays(days))
+ if err != nil {
+ return nil, stacktrace.Propagate(err, "")
+ }
+ defer rows.Close()
+ users := make([]ente.User, 0)
+ for rows.Next() {
+ var user ente.User
+ var encryptedEmail, nonce []byte
+ err := rows.Scan(&user.ID, &encryptedEmail, &nonce, &user.Hash, &user.CreationTime)
+ if err != nil {
+ return nil, stacktrace.Propagate(err, "")
+ }
+ email, err := crypto.Decrypt(encryptedEmail, repo.SecretEncryptionKey, nonce)
+ if err != nil {
+ return nil, stacktrace.Propagate(err, "")
+ }
+ user.Email = email
+ users = append(users, user)
+ }
+ return users, nil
+}
+
// SetTwoFactorSecret sets the two factor secret for a user
func (repo *UserRepository) SetTwoFactorSecret(userID int64, secret ente.EncryptionResult, secretHash string, recoveryEncryptedTwoFactorSecret string, recoveryTwoFactorSecretDecryptionNonce string) error {
_, err := repo.DB.Exec(`INSERT INTO two_factor(user_id,encrypted_two_factor_secret,two_factor_secret_decryption_nonce,two_factor_secret_hash,recovery_encrypted_two_factor_secret,recovery_two_factor_secret_decryption_nonce)