mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Send email notification when username changed (#3022)
This commit is contained in:
committed by
Joram Wilander
parent
9d5e7478f9
commit
99b8eef7e3
44
api/user.go
44
api/user.go
@@ -6,15 +6,6 @@ package api
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/golang/freetype"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
"hash/fnv"
|
||||
"html/template"
|
||||
"image"
|
||||
@@ -30,6 +21,16 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/golang/freetype"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
)
|
||||
|
||||
func InitUser() {
|
||||
@@ -1291,6 +1292,10 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if rusers[0].Username != rusers[1].Username {
|
||||
sendEmailChangeUsernameAndForget(c, rusers[1].Username, rusers[0].Username, rusers[0].Email, c.GetSiteURL())
|
||||
}
|
||||
|
||||
rusers[0].Password = ""
|
||||
rusers[0].AuthData = new(string)
|
||||
*rusers[0].AuthData = ""
|
||||
@@ -1832,6 +1837,27 @@ func SendEmailChangeVerifyEmailAndForget(c *Context, userId, newUserEmail, siteU
|
||||
}()
|
||||
}
|
||||
|
||||
func sendEmailChangeUsernameAndForget(c *Context, oldUsername, newUsername, email, siteURL string) {
|
||||
go func() {
|
||||
|
||||
subjectPage := utils.NewHTMLTemplate("username_change_subject", c.Locale)
|
||||
subjectPage.Props["Subject"] = c.T("api.templates.username_change_subject",
|
||||
map[string]interface{}{"TeamDisplayName": utils.Cfg.TeamSettings.SiteName})
|
||||
subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName
|
||||
|
||||
bodyPage := utils.NewHTMLTemplate("email_change_body", c.Locale)
|
||||
bodyPage.Props["SiteURL"] = siteURL
|
||||
bodyPage.Props["Title"] = c.T("api.templates.username_change_body.title")
|
||||
bodyPage.Html["Info"] = template.HTML(c.T("api.templates.username_change_body.info",
|
||||
map[string]interface{}{"TeamDisplayName": utils.Cfg.TeamSettings.SiteName, "NewUsername": newUsername}))
|
||||
|
||||
if err := utils.SendMail(email, subjectPage.Render(), bodyPage.Render()); err != nil {
|
||||
l4g.Error(utils.T("api.user.send_email_change_username_and_forget.error"), err)
|
||||
}
|
||||
|
||||
}()
|
||||
}
|
||||
|
||||
func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
|
||||
|
||||
16
i18n/en.json
16
i18n/en.json
@@ -1203,6 +1203,18 @@
|
||||
"id": "api.templates.email_change_subject",
|
||||
"translation": "Your email address has changed for {{.TeamDisplayName}}"
|
||||
},
|
||||
{
|
||||
"id": "api.templates.username_change_body.info",
|
||||
"translation": "Your username for {{.TeamDisplayName}} has been changed to {{.NewUsername}}.<br>If you did not make this change, please contact the system administrator."
|
||||
},
|
||||
{
|
||||
"id": "api.templates.username_change_body.title",
|
||||
"translation": "You updated your username"
|
||||
},
|
||||
{
|
||||
"id": "api.templates.username_change_subject",
|
||||
"translation": "Your username has changed for {{.TeamDisplayName}}"
|
||||
},
|
||||
{
|
||||
"id": "api.templates.email_change_verify_body.button",
|
||||
"translation": "Verify Email"
|
||||
@@ -1639,6 +1651,10 @@
|
||||
"id": "api.user.send_email_change_email_and_forget.error",
|
||||
"translation": "Failed to send email change notification email successfully err=%v"
|
||||
},
|
||||
{
|
||||
"id": "api.user.send_email_change_username_and_forget.error",
|
||||
"translation": "Failed to send username change notification email successfully err=%v"
|
||||
},
|
||||
{
|
||||
"id": "api.user.send_email_change_verify_email_and_forget.error",
|
||||
"translation": "Failed to send email change verification email successfully err=%v"
|
||||
|
||||
16
i18n/fr.json
16
i18n/fr.json
@@ -1103,6 +1103,18 @@
|
||||
"id": "api.templates.email_change_subject",
|
||||
"translation": "Votre adresse électronique a été modifiée pour {{.TeamDisplayName}}"
|
||||
},
|
||||
{
|
||||
"id": "api.templates.username_change_body.info",
|
||||
"translation": "Votre nom d'utilisateur pour {{.TeamDisplayName}} a été modifiée en {{.NewUsername}}.<br>Si vous n'êtes pas à l'origine de cette action, veuillez contacter votre administrateur système."
|
||||
},
|
||||
{
|
||||
"id": "api.templates.username_change_body.title",
|
||||
"translation": "Vous avez mis à jour votre nom d'utilisateur."
|
||||
},
|
||||
{
|
||||
"id": "api.templates.username_change_subject",
|
||||
"translation": "Votre nom d'utilisateur a été modifiée pour {{.TeamDisplayName}}"
|
||||
},
|
||||
{
|
||||
"id": "api.templates.email_change_verify_body.button",
|
||||
"translation": "Vérifier votre adresse électronique"
|
||||
@@ -1495,6 +1507,10 @@
|
||||
"id": "api.user.send_email_change_email_and_forget.error",
|
||||
"translation": "Impossible d'envoyer le courriel de changement d'adresse électronique err=%v"
|
||||
},
|
||||
{
|
||||
"id": "api.user.send_email_change_username_and_forget.error",
|
||||
"translation": "Impossible d'envoyer le courriel de changement de nom d'utilisateur err=%v"
|
||||
},
|
||||
{
|
||||
"id": "api.user.send_email_change_verify_email_and_forget.error",
|
||||
"translation": "Impossible d'envoyer le courriel de changement d'adresse électronique err=%v"
|
||||
|
||||
41
templates/username_change_body.html
Normal file
41
templates/username_change_body.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{{define "username_change_body"}}
|
||||
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-top: 20px; line-height: 1.7; color: #555;">
|
||||
<tr>
|
||||
<td>
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 660px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; background: #FFF;">
|
||||
<tr>
|
||||
<td style="border: 1px solid #ddd;">
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;">
|
||||
<tr>
|
||||
<td style="padding: 20px 20px 10px; text-align:left;">
|
||||
<img src="{{.Props.SiteURL}}/static/images/logo-email.png" width="130px" style="opacity: 0.5" alt="">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0" style="padding: 20px 50px 0; text-align: center; margin: 0 auto">
|
||||
<tr>
|
||||
<td style="border-bottom: 1px solid #ddd; padding: 0 0 20px;">
|
||||
<h2 style="font-weight: normal; margin-top: 10px;">{{.Props.Title}}</h2>
|
||||
<p>{{.Html.Info}}</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
{{template "email_info" . }}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
{{template "email_footer" . }}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{{end}}
|
||||
1
templates/username_change_subject.html
Normal file
1
templates/username_change_subject.html
Normal file
@@ -0,0 +1 @@
|
||||
{{define "username_change_subject"}}[{{.Props.SiteName}}] {{.Props.Subject}}{{end}}
|
||||
Reference in New Issue
Block a user