Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add link in delete email to auto-recover account

Neeraj Gupta851aed6a7879
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index 940f34459e..aa117c6763 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -519,7 +519,7 @@ func main() {
privateAPI.DELETE("/users/session", userHandler.TerminateSession)
privateAPI.GET("/users/delete-challenge", userHandler.GetDeleteChallenge)
privateAPI.DELETE("/users/delete", userHandler.DeleteUser)
- publicAPI.GET("/users/recover-account", userHandler.RecoveryAccount)
+ publicAPI.GET("/users/recover-account", userHandler.SelfRecoverAccount)
accountsJwtAuthAPI := server.Group("/")
accountsJwtAuthAPI.Use(rateLimiter.GlobalRateLimiter(), authMiddleware.TokenAuthMiddleware(jwt.ACCOUNTS.Ptr()), rateLimiter.APIRateLimitForUserMiddleware(urlSanitizer))
diff --git a/server/mail-templates/account_deleted.html b/server/mail-templates/account_deleted.html
index e9963746f9..830e41a6d0 100644
--- a/server/mail-templates/account_deleted.html
+++ b/server/mail-templates/account_deleted.html
@@ -101,15 +101,17 @@
font-size: 16px; " >
<p>Hey,</p>
- <p>As requested by you, we've deleted your Ente account and scheduled your
- uploaded data for deletion.</p>
+ <p>As requested, we've deleted your Ente account and scheduled your uploaded data for deletion.</p>
- <p>If you accidentally deleted your account, please contact our support
- immediately to try and recover your uploaded data before the next
- scheduled deletion happens.</p>
+ <p>If this was a mistake, please click here to
+ <a href={{.AccountRecoveryLink}} style="color: #37C066; font-weight: bold;">recover your account</a>.</p>
- <p> Thank you for checking out Ente, we wish you a great time ahead!</p>
+ <p>After 7 days, your data will be permanently deleted. If you need help, contact our support team.</p>
+
+ <p>Thank you for trying Ente. We hope to see you again!</p>
</div>
+
+
<br />
<div class="footer" style="text-align: center; font-size: 12px; color:
rgb(136, 136, 136)" >
diff --git a/server/mail-templates/account_deleted_active_sub.html b/server/mail-templates/account_deleted_active_sub.html
index dd6a82bda5..670a1bcf79 100644
--- a/server/mail-templates/account_deleted_active_sub.html
+++ b/server/mail-templates/account_deleted_active_sub.html
@@ -105,9 +105,10 @@
uploaded data for deletion. If you have an App Store subscription for
Ente, please remember to cancel it too.</p>
- <p>If you accidentally deleted your account, please contact our support
- immediately to try and recover your uploaded data before the next
- scheduled deletion happens.</p>
+ <p>If this was a mistake, please click here to
+ <a href={{.AccountRecoveryLink}} style="color: #37C066; font-weight: bold;">recover your account</a>.</p>
+
+ <p>After 7 days, your data will be permanently deleted. If you need help, contact our support team.</p>
<p>Thank you for checking out Ente, we wish you a great time ahead!</p>
</div>
diff --git a/server/pkg/api/user.go b/server/pkg/api/user.go
index f1a11a6b82..119357072e 100644
--- a/server/pkg/api/user.go
+++ b/server/pkg/api/user.go
@@ -540,18 +540,20 @@ func (h *UserHandler) DeleteUser(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
-func (h *UserHandler) RecoveryAccount(c *gin.Context) {
+func (h *UserHandler) SelfRecoverAccount(c *gin.Context) {
token := c.Query("token")
if token == "" {
handler.Error(c, stacktrace.Propagate(ente.NewBadRequestWithMessage("token missing"), "token is required"))
return
}
- response, err := h.UserController.SelfDeleteAccount(c, request)
+ err := h.UserController.HandleSelfAccountRecovery(c, token)
if err != nil {
handler.Error(c, stacktrace.Propagate(err, ""))
return
}
- c.JSON(http.StatusOK, response)
+ c.JSON(http.StatusOK, gin.H{
+ "message": "Account recovery successful",
+ })
}
// GetSRPAttributes returns the SRP attributes for a user
diff --git a/server/pkg/controller/user/user.go b/server/pkg/controller/user/user.go
index 4917b29a0b..f0bd13f1ce 100644
--- a/server/pkg/controller/user/user.go
+++ b/server/pkg/controller/user/user.go
@@ -300,13 +300,34 @@ func (c *UserController) NotifyAccountDeletion(userID int64, userEmail string, i
}
templateData := make(map[string]interface{})
- templateData["RecoverLink"] = fmt.Sprintf("%s/user/recover-account?token=%s", "https://api.ente.io", recoverToken)
+ templateData["AccountRecoveryLink"] = fmt.Sprintf("%s/users/recover-account?token=%s", "https://api.ente.io", recoverToken)
+ logrus.Info("account recovery link: ", templateData["AccountRecoveryLink"])
err := email.SendTemplatedEmail([]string{userEmail}, "ente", "[email protected]",
AccountDeletedEmailSubject, template, templateData, nil)
if err != nil {
logrus.WithError(err).Errorf("Failed to send the account deletion email to %s", userEmail)
}
}
+func (c *UserController) HandleSelfAccountRecovery(ctx *gin.Context, token string) error {
+ jwtToken, err := c.ValidateJWTToken(token, enteJWT.RestoreAccount)
+ if err != nil {
+ return err
+ }
+ if jwtToken.UserID == 0 || jwtToken.Email == "" {
+ return stacktrace.Propagate(ente.NewBadRequestError(&ente.ApiErrorParams{
+ Message: "Invalid token",
+ }), "userID or email is empty")
+ }
+ if jwtToken.ExpiryTime < time.Microseconds() {
+ return stacktrace.Propagate(ente.NewBadRequestError(&ente.ApiErrorParams{
+ Message: "Token expired",
+ }), "")
+ }
+ return c.HandleAccountRecovery(ctx, ente.RecoverAccountRequest{
+ UserID: jwtToken.UserID,
+ EmailID: jwtToken.Email,
+ })
+}
func (c *UserController) HandleAccountRecovery(ctx *gin.Context, req ente.RecoverAccountRequest) error {
logger := logrus.WithFields(logrus.Fields{
@@ -319,7 +340,7 @@ func (c *UserController) HandleAccountRecovery(ctx *gin.Context, req ente.Recove
_, err := c.UserRepo.Get(req.UserID)
if err == nil {
return stacktrace.Propagate(ente.NewBadRequestError(&ente.ApiErrorParams{
- Message: "User ID is linked to an active account account",
+ Message: "Either account already recovered or User ID is linked to an active account account",
}), "")
}
if !errors.Is(err, ente.ErrUserDeleted) {