diff options
-rw-r--r-- | app/email.go | 18 | ||||
-rw-r--r-- | app/session.go | 16 | ||||
-rw-r--r-- | i18n/en.json | 16 |
3 files changed, 49 insertions, 1 deletions
diff --git a/app/email.go b/app/email.go index cd3cb3b4f..309c58f3b 100644 --- a/app/email.go +++ b/app/email.go @@ -179,6 +179,24 @@ func SendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppEr return nil } +func SendUserAccessTokenAddedEmail(email, locale string) *model.AppError { + T := utils.GetUserTranslations(locale) + + subject := T("api.templates.user_access_token_subject", + map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"]}) + + bodyPage := utils.NewHTMLTemplate("password_change_body", locale) + bodyPage.Props["Title"] = T("api.templates.user_access_token_body.title") + bodyPage.Html["Info"] = template.HTML(T("api.templates.user_access_token_body.info", + map[string]interface{}{"SiteName": utils.ClientCfg["SiteName"], "SiteURL": utils.GetSiteURL()})) + + if err := utils.SendMail(email, subject, bodyPage.Render()); err != nil { + return model.NewLocAppError("SendUserAccessTokenAddedEmail", "api.user.send_user_access_token.error", nil, err.Error()) + } + + return nil +} + func SendPasswordResetEmail(email string, token *model.Token, locale, siteURL string) (bool, *model.AppError) { T := utils.GetUserTranslations(locale) diff --git a/app/session.go b/app/session.go index 07f5c6e0a..78b8ee46a 100644 --- a/app/session.go +++ b/app/session.go @@ -219,11 +219,25 @@ func CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken token.Token = model.NewId() + uchan := Srv.Store.User().Get(token.UserId) + if result := <-Srv.Store.UserAccessToken().Save(token); result.Err != nil { return nil, result.Err } else { - return result.Data.(*model.UserAccessToken), nil + token = result.Data.(*model.UserAccessToken) + } + + if result := <-uchan; result.Err != nil { + l4g.Error(result.Err.Error()) + } else { + user := result.Data.(*model.User) + if err := SendUserAccessTokenAddedEmail(user.Email, user.Locale); err != nil { + l4g.Error(err.Error()) + } } + + return token, nil + } func createSessionForUserAccessToken(tokenString string) (*model.Session, *model.AppError) { diff --git a/i18n/en.json b/i18n/en.json index 2d4581ad8..c4bc9652a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2420,6 +2420,18 @@ "translation": "[{{ .SiteName }}] Your password has been updated" }, { + "id": "api.templates.user_access_token_body.info", + "translation": "A user access token was added to your account on {{ .SiteURL }}. They can be used to access {{.SiteName}} with your account.<br>If this change wasn't initiated by you, please contact your system administrator." + }, + { + "id": "api.templates.user_access_token_body.title", + "translation": "User access token added to your account" + }, + { + "id": "api.templates.user_access_token_subject", + "translation": "[{{ .SiteName }}] User access token added to your account" + }, + { "id": "api.templates.post_body.button", "translation": "Go To Post" }, @@ -2836,6 +2848,10 @@ "translation": "Failed to send update password email successfully" }, { + "id": "api.user.send_user_access_token.error", + "translation": "Failed to send user access token added email successfully" + }, + { "id": "api.user.send_password_reset.find.app_error", "translation": "We couldn’t find an account with that address." }, |