PLT-7194 Add email when adding user access tokens (#7087)

* Add email when adding user access tokens

* Update en.json

* Update en.json
Этот коммит содержится в:
Joram Wilander
2017-08-03 08:51:52 -04:00
коммит произвёл GitHub
родитель 43c523e839
Коммит 713673c888
3 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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) {

Просмотреть файл

@@ -2419,6 +2419,18 @@
"id": "api.templates.password_change_subject",
"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"
@@ -2835,6 +2847,10 @@
"id": "api.user.send_password_change_email_and_forget.error",
"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 couldnt find an account with that address."