π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix lint (?)
mngshmf34624e0d2dd
diff --git a/server/mail-templates/on_login.html b/server/mail-templates/on_login.htmlnew file mode 100644index 0000000000..9f7baf9071--- /dev/null+++ b/server/mail-templates/on_login.html@@ -0,0 +1,141 @@+<!DOCTYPE html>+<html>+ <meta content="text/html; charset=utf-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1,+ minimum-scale=1" />+ <style>+ body {+ background-color: #f0f1f3;+ font-family: "Helvetica Neue", "Segoe UI", Helvetica, sans-serif;+ font-size: 16px;+ line-height: 27px;+ margin: 0;+ color: #444;+ }++ pre {+ background: #f4f4f4f4;+ padding: 2px;+ }++ table {+ width: 100%;+ border: 1px solid #ddd;+ }++ table td {+ border-color: #ddd;+ padding: 5px;+ }++ .wrap {+ background-color: #fff;+ padding: 30px;+ max-width: 525px;+ margin: 0 auto;+ border-radius: 5px;+ }++ .button {+ background: #0055d4;+ border-radius: 3px;+ text-decoration: none !important;+ color: #fff !important;+ font-weight: bold;+ padding: 10px 30px;+ display: inline-block;+ }++ .button:hover {+ background: #111;+ }++ .footer {+ text-align: center;+ font-size: 12px;+ color: #888;+ }++ .footer a {+ color: #888;+ margin-right: 5px;+ }++ .gutter {+ padding: 30px;+ }++ img {+ max-width: 100%;+ height: auto;+ }++ a {+ color: #0055d4;+ }++ a:hover {+ color: #111;+ }++ @media screen and (max-width: 600px) {+ .wrap {+ max-width: auto;+ }++ .gutter {+ padding: 10px;+ }+ }++ .footer-icons {+ padding: 4px !important;+ width: 24px !important;+ }+ </style>++ <body>+ <div class="gutter" style="padding: 4px"> </div>+ <div class="wrap" style=" background-color: rgb(255, 255, 255); padding: 2px+ 30px 30px 30px; max-width: 525px; margin: 0 auto; border-radius: 5px;+ font-size: 16px; " >+ <p>Hi,</p>+ <p>+ We detected a new login to your Ente account at {{ .Date }} UTC.+ <br>+ <br>+ If this is not you, please reset your password. For any assistance or questions, please reply to this email.+ </p>+ </div>+ <br />+ <div class="footer" style="text-align: center; font-size: 12px; color:+ rgb(136, 136, 136)" >+ <div>+ <a href="https://ente.io" target="_blank" ><img+ src="https://email-assets.ente.io/ente-green.png" style="width: 100px;+ padding: 24px" title="Ente" alt="Ente" /></a>+ </div>+ <div>+ <a href="https://fosstodon.org/@ente" target="_blank" ><img+ src="https://email-assets.ente.io/mastodon-icon.png"+ class="footer-icons" style="width: 24px; padding: 4px" title="Mastodon"+ alt="Mastodon" /></a>+ <a href="https://twitter.com/enteio" target="_blank" ><img+ src="https://email-assets.ente.io/twitter-icon.png" class="footer-icons"+ style="width: 24px; padding: 4px" title="Twitter" alt="Twitter" /></a>+ <a href="https://discord.ente.io" target="_blank" ><img+ src="https://email-assets.ente.io/discord-icon.png" class="footer-icons"+ style="width: 24px; padding: 4px" title="Discord" alt="Discord" /></a>+ <a href="https://github.com/ente-io" target="_blank" ><img+ src="https://email-assets.ente.io/github-icon.png" class="footer-icons"+ style="width: 24px; padding: 4px" title="GitHub" alt="GitHub" /></a>+ </div>+ <p>+ Ente Technologies, Inc.+ <br /> 1111B S Governors Ave 6032 Dover, DE 19904+ </p>+ <br />+ </div>+ </body>+</html>+diff --git a/server/pkg/controller/email/email_notification.go b/server/pkg/controller/email/email_notification.goindex 6f4048d603..1fc918747b 100644--- a/server/pkg/controller/email/email_notification.go+++ b/server/pkg/controller/email/email_notification.go@@ -16,20 +16,29 @@ const (WebAppFirstUploadTemplate = "web_app_first_upload.html"MobileAppFirstUploadTemplate = "mobile_app_first_upload.html"FirstUploadEmailSubject = "Congratulations! π"- StorageLimitExceededMailLock = "storage_limit_exceeded_mail_lock"++ StorageLimitExceededMailLock = "storage_limit_exceeded_mail_lock"StorageLimitExceededTemplateID = "storage_limit_exceeded"StorageLimitExceededTemplate = "storage_limit_exceeded.html"- FilesCollectedTemplate = "files_collected.html"++ FilesCollectedTemplate = "files_collected.html"FilesCollectedTemplateID = "files_collected"FilesCollectedSubject = "You've got photos!"+ FilesCollectedMuteDurationInMinutes = 10+SubscriptionUpgradedTemplate = "subscription_upgraded.html"SubscriptionUpgradedSubject = "Thank you for choosing Ente!"+SubscriptionCancelledSubject = "Good bye (?) from Ente"SubscriptionCancelledTemplate = "subscription_cancelled.html"FilesCollectedMuteDurationInMinutes = 10- StorageLimitExceededSubject = "[Alert] You have exceeded your storage limit"++ StorageLimitExceededSubject = "[Alert] You have exceeded your storage limit"ReferralSuccessfulTemplate = "successful_referral.html"ReferralSuccessfulSubject = "You've earned 10 GB on Ente! π"++ LoginSuccessSubject = "New login to your Ente account"+ LoginSuccessTemplate = "on_login.html")type EmailNotificationController struct {diff --git a/server/pkg/controller/user/twofactor.go b/server/pkg/controller/user/twofactor.goindex d788b66fd5..388887ea50 100644--- a/server/pkg/controller/user/twofactor.go+++ b/server/pkg/controller/user/twofactor.go@@ -187,7 +187,7 @@ func (c *UserController) GetKeyAttributeAndToken(context *gin.Context, userID inif err != nil {return ente.TwoFactorAuthorizationResponse{}, stacktrace.Propagate(err, "")}- err = c.UserAuthRepo.AddToken(userID, auth.GetApp(context),+ err = c.AddTokenAndNotify(userID, auth.GetApp(context),token, network.GetClientIP(context), context.Request.UserAgent())if err != nil {return ente.TwoFactorAuthorizationResponse{}, stacktrace.Propagate(err, "")diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.goindex 86828d1cee..e7934b8c6a 100644--- a/server/pkg/controller/user/userauth.go+++ b/server/pkg/controller/user/userauth.go@@ -6,6 +6,7 @@ import ("errors""fmt""strings"+ t "time""github.com/ente-io/museum/pkg/utils/random"@@ -15,11 +16,13 @@ import ("github.com/spf13/viper""github.com/ente-io/museum/ente"+ emailCtrl "github.com/ente-io/museum/pkg/controller/email""github.com/ente-io/museum/pkg/utils/auth""github.com/ente-io/museum/pkg/utils/crypto"emailUtil "github.com/ente-io/museum/pkg/utils/email""github.com/ente-io/museum/pkg/utils/time""github.com/ente-io/stacktrace"+"github.com/gin-gonic/gin"log "github.com/sirupsen/logrus")@@ -93,9 +96,7 @@ func (c *UserController) SendEmailOTT(context *gin.Context, email string, purposif isComplete && purpose == ente.SignUpOTTPurpose {return stacktrace.Propagate(ente.ErrUserAlreadyRegistered, "user has already completed sign up process")}- if purpose == ente.SignUpOTTPurpose && viper.GetBool("internal.disable-registration") {- return stacktrace.Propagate(ente.ErrPermissionDenied, "registration is disabled")- }+if !isComplete && purpose == ente.LoginOTTPurpose {return stacktrace.Propagate(ente.ErrUserNotRegistered, "user has not completed sign up process")}@@ -332,6 +333,28 @@ func (c *UserController) GetActiveSessions(context *gin.Context, userID int64) (return tokens, nil}+func (c *UserController) AddTokenAndNotify(userID int64, app ente.App, token string, ip string, userAgent string) error {+ err := c.UserAuthRepo.AddToken(userID, app, token, ip, userAgent)+ if err != nil {+ return stacktrace.Propagate(err, "failed to insert token")+ }++ go func() {+ user, userErr := c.UserRepo.GetUserByIDInternal(userID)+ if userErr != nil {+ log.WithError(userErr).Error("Failed to get user")+ return+ }+ emailSendErr := emailUtil.SendTemplatedEmail([]string{user.Email}, "Ente", "[email protected]", emailCtrl.LoginSuccessSubject, emailCtrl.LoginSuccessTemplate, map[string]interface{}{+ "Date": t.Now().UTC().Format("02 Jan, 2006 15:04"),+ }, nil)+ if emailSendErr != nil {+ log.WithError(emailSendErr).Error("Failed to send email")+ }+ }()+ return nil+}+// TerminateSession removes the token for a user from cache and databasefunc (c *UserController) TerminateSession(userID int64, token string) error {c.Cache.Delete(fmt.Sprintf("%s:%s", ente.Photos, token))@@ -365,7 +388,6 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strinuserID, err := c.UserRepo.GetUserIDWithEmail(email)if err != nil {if errors.Is(err, sql.ErrNoRows) {- // Keep this check as users can still trigger ott via other means that can lead to this code pathif viper.GetBool("internal.disable-registration") {return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(ente.ErrPermissionDenied, "")} else {@@ -425,6 +447,8 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strinkeyAttributes, err := c.UserRepo.GetKeyAttributes(userID)if err != nil {if errors.Is(err, sql.ErrNoRows) {+ // user creation is pending on key attributes set based on the password.+ // No need to send login notificationerr = c.UserAuthRepo.AddToken(userID, auth.GetApp(context), token,network.GetClientIP(context), context.Request.UserAgent())if err != nil {@@ -439,7 +463,7 @@ func (c *UserController) onVerificationSuccess(context *gin.Context, email strinif err != nil {return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")}- err = c.UserAuthRepo.AddToken(userID, auth.GetApp(context), token,+ err = c.AddTokenAndNotify(userID, auth.GetApp(context), token,network.GetClientIP(context), context.Request.UserAgent())if err != nil {return ente.EmailAuthorizationResponse{}, stacktrace.Propagate(err, "")