diff options
author | Thomas Balthazar <tbalthazar@users.noreply.github.com> | 2016-05-18 13:54:33 +0200 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-05-18 07:54:33 -0400 |
commit | 99b8eef7e373a000f35016415ba2148f939c1155 (patch) | |
tree | 53ff88b061410fbfed3cf2c59808f9db47bd83a6 /api | |
parent | 9d5e7478f9131f10a44d07f8b5b899e7f3b991f7 (diff) | |
download | chat-99b8eef7e373a000f35016415ba2148f939c1155.tar.gz chat-99b8eef7e373a000f35016415ba2148f939c1155.tar.bz2 chat-99b8eef7e373a000f35016415ba2148f939c1155.zip |
Send email notification when username changed (#3022)
Diffstat (limited to 'api')
-rw-r--r-- | api/user.go | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/api/user.go b/api/user.go index 559cda076..da94a0ff5 100644 --- a/api/user.go +++ b/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) |