PLT-7194 Add email when adding user access tokens (#7087)
* Add email when adding user access tokens * Update en.json * Update en.json
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
43c523e839
Коммит
713673c888
18
app/email.go
18
app/email.go
@@ -179,6 +179,24 @@ func SendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppEr
|
|||||||
return nil
|
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) {
|
func SendPasswordResetEmail(email string, token *model.Token, locale, siteURL string) (bool, *model.AppError) {
|
||||||
|
|
||||||
T := utils.GetUserTranslations(locale)
|
T := utils.GetUserTranslations(locale)
|
||||||
|
|||||||
@@ -219,11 +219,25 @@ func CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken
|
|||||||
|
|
||||||
token.Token = model.NewId()
|
token.Token = model.NewId()
|
||||||
|
|
||||||
|
uchan := Srv.Store.User().Get(token.UserId)
|
||||||
|
|
||||||
if result := <-Srv.Store.UserAccessToken().Save(token); result.Err != nil {
|
if result := <-Srv.Store.UserAccessToken().Save(token); result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
} 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) {
|
func createSessionForUserAccessToken(tokenString string) (*model.Session, *model.AppError) {
|
||||||
|
|||||||
16
i18n/en.json
16
i18n/en.json
@@ -2419,6 +2419,18 @@
|
|||||||
"id": "api.templates.password_change_subject",
|
"id": "api.templates.password_change_subject",
|
||||||
"translation": "[{{ .SiteName }}] Your password has been updated"
|
"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",
|
"id": "api.templates.post_body.button",
|
||||||
"translation": "Go To Post"
|
"translation": "Go To Post"
|
||||||
@@ -2835,6 +2847,10 @@
|
|||||||
"id": "api.user.send_password_change_email_and_forget.error",
|
"id": "api.user.send_password_change_email_and_forget.error",
|
||||||
"translation": "Failed to send update password email successfully"
|
"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",
|
"id": "api.user.send_password_reset.find.app_error",
|
||||||
"translation": "We couldn’t find an account with that address."
|
"translation": "We couldn’t find an account with that address."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user