From aad9529f31d9ec6966aaffab1083b6108031a505 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 2 Oct 2015 16:30:21 -0700 Subject: [PATCH 1/4] Initial cosmetic changes to the process of verifying a changed email --- api/templates/email_change_body.html | 3 +- api/templates/email_change_subject.html | 2 +- api/templates/email_change_verify_body.html | 56 +++++++++++++++++++ .../email_change_verify_subject.html | 1 + utils/config.go | 1 + .../user_settings/user_settings_general.jsx | 46 +++++++++++++-- web/sass-files/sass/partials/_settings.scss | 1 + 7 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 api/templates/email_change_verify_body.html create mode 100644 api/templates/email_change_verify_subject.html diff --git a/api/templates/email_change_body.html b/api/templates/email_change_body.html index 0ec4ace2a5..7addb6f35d 100644 --- a/api/templates/email_change_body.html +++ b/api/templates/email_change_body.html @@ -18,7 +18,7 @@

You updated your email

-

You updated your email for {{.Props.TeamDisplayName}} on {{ .Props.TeamURL }}
If this change wasn't initiated by you, please reply to this email and let us know.

+

You email address for {{.Props.TeamDisplayName}} has been changed.
If you did not make this change, please contact the system administrator.

@@ -51,4 +51,3 @@ {{end}} - diff --git a/api/templates/email_change_subject.html b/api/templates/email_change_subject.html index 5690b148a4..962ae868ea 100644 --- a/api/templates/email_change_subject.html +++ b/api/templates/email_change_subject.html @@ -1 +1 @@ -{{define "email_change_subject"}}You updated your email for {{.Props.TeamDisplayName}} on {{ .Props.Domain }}{{end}} +{{define "email_change_subject"}}[{{.ClientProps.SiteName}}] Your email address has changed for {{.Props.TeamDisplayName}}{{end}} diff --git a/api/templates/email_change_verify_body.html b/api/templates/email_change_verify_body.html new file mode 100644 index 0000000000..296a3d9680 --- /dev/null +++ b/api/templates/email_change_verify_body.html @@ -0,0 +1,56 @@ +{{define "verify_new_email_body"}} + + + + + +
+ + + + +
+ + + + + + + + + + +
+ +
+ + + + + + + +
+

You updated your email

+

To finish updating your email address for {{.Props.TeamDisplayName}}, please click the link below to confirm this is the right address.

+

+ Verify Email +

+
+ Any questions at all, mail us any time: {{.ClientProps.FeedbackEmail}}.
+ Best wishes,
+ The {{.ClientProps.SiteName}} Team
+
+
+

+ +

+

+ (c) 2015 SpinPunch, Inc. 855 El Camino Real, 13A-168, Palo Alto, CA, 94301.
+ If you no longer wish to receive these emails, click on the following link: Unsubscribe +

+
+
+
+ +{{end}} diff --git a/api/templates/email_change_verify_subject.html b/api/templates/email_change_verify_subject.html new file mode 100644 index 0000000000..f1cebd710a --- /dev/null +++ b/api/templates/email_change_verify_subject.html @@ -0,0 +1 @@ +{{define "verify_new_email_subject"}}[{{.ClientProps.SiteName}}] Verify new email address for {{.Props.TeamDisplayName}}{{end}} diff --git a/utils/config.go b/utils/config.go index 44c4c43aff..0a2697e6ca 100644 --- a/utils/config.go +++ b/utils/config.go @@ -189,6 +189,7 @@ func getClientProperties(c *model.Config) map[string]string { props["SendEmailNotifications"] = strconv.FormatBool(c.EmailSettings.SendEmailNotifications) props["EnableSignUpWithEmail"] = strconv.FormatBool(c.EmailSettings.EnableSignUpWithEmail) + props["RequireEmailVerification"] = strconv.FormatBool(c.EmailSettings.RequireEmailVerification) props["FeedbackEmail"] = c.EmailSettings.FeedbackEmail props["EnableSignUpWithGitLab"] = strconv.FormatBool(c.GitLabSettings.Enable) diff --git a/web/react/components/user_settings/user_settings_general.jsx b/web/react/components/user_settings/user_settings_general.jsx index c1d4c4ab52..bd7ed12dbd 100644 --- a/web/react/components/user_settings/user_settings_general.jsx +++ b/web/react/components/user_settings/user_settings_general.jsx @@ -2,6 +2,7 @@ // See License.txt for license information. var UserStore = require('../../stores/user_store.jsx'); +var ErrorStore = require('../../stores/error_store.jsx'); var SettingItemMin = require('../setting_item_min.jsx'); var SettingItemMax = require('../setting_item_max.jsx'); var SettingPicture = require('../setting_picture.jsx'); @@ -108,13 +109,26 @@ export default class UserSettingsGeneralTab extends React.Component { user.email = email; - this.submitUser(user); + if (!this.state.emailEnabled || !this.state.emailVerificationEnabled) { + this.submitUser(user, {emailChangeInProgress: false}); + } else { + this.submitUser(user, {emailChangeInProgress: true}); + } } - submitUser(user) { + submitUser(user, newState) { client.updateUser(user, function updateSuccess() { this.updateSection(''); AsyncClient.getMe(); + + if (newState) { + if (newState.emailChangeInProgress) { + ErrorStore.storeLastError({message: 'Check your email at ' + user.email + ' to verify the address.'}); + ErrorStore.emitChange(); + } + + this.setState(newState); + } }.bind(this), function updateFailure(err) { var state = this.setupInitialState(this.props); @@ -209,8 +223,11 @@ export default class UserSettingsGeneralTab extends React.Component { setupInitialState(props) { var user = props.user; var emailEnabled = global.window.config.SendEmailNotifications === 'true'; + var emailVerificationEnabled = global.window.config.RequireEmailVerification === 'true'; + return {username: user.username, firstName: user.first_name, lastName: user.last_name, nickname: user.nickname, - email: user.email, picture: null, loadingPicture: false, emailEnabled: emailEnabled}; + email: user.email, picture: null, loadingPicture: false, emailEnabled: emailEnabled, + emailVerificationEnabled: emailVerificationEnabled, emailChangeInProgress: false}; } render() { var user = this.props.user; @@ -434,10 +451,17 @@ export default class UserSettingsGeneralTab extends React.Component { } var emailSection; if (this.props.activeSection === 'email') { - let helpText =
Email is used for notifications, and requires verification if changed.
; + let helpText = 'Email is used for notifications, and requires verification if changed.'; if (!this.state.emailEnabled) { helpText =
{'Email has been disabled by your system administrator. No notification emails will be sent until it is enabled.'}
; + } else if (!this.state.emailVerificationEnabled) { + helpText = 'Email is used for notifications.'; + } else if (this.state.emailChangeInProgress) { + const newEmail = UserStore.getCurrentUser().email; + if (newEmail) { + helpText = 'A verification email was sent to ' + newEmail + '.'; + } } inputs.push( @@ -471,10 +495,22 @@ export default class UserSettingsGeneralTab extends React.Component { /> ); } else { + let describe = ''; + if (this.state.emailChangeInProgress) { + const newEmail = UserStore.getCurrentUser().email; + if (newEmail) { + describe = 'New Address: ' + newEmail + '\nCheck your email to verify the above address.'; + } else { + describe = 'Check your email to verify your new address'; + } + } else { + describe = UserStore.getCurrentUser().email; + } + emailSection = ( Date: Mon, 5 Oct 2015 14:18:05 -0700 Subject: [PATCH 2/4] Added better verification when a user changes his or her email --- api/templates/email_change_verify_body.html | 2 +- .../email_change_verify_subject.html | 2 +- api/user.go | 23 ++++++++++++ .../user_settings/user_settings_general.jsx | 37 ++++++++++++++++--- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/api/templates/email_change_verify_body.html b/api/templates/email_change_verify_body.html index 296a3d9680..356f2454c4 100644 --- a/api/templates/email_change_verify_body.html +++ b/api/templates/email_change_verify_body.html @@ -1,4 +1,4 @@ -{{define "verify_new_email_body"}} +{{define "email_change_verify_body"}} diff --git a/api/templates/email_change_verify_subject.html b/api/templates/email_change_verify_subject.html index f1cebd710a..5e2ac1452a 100644 --- a/api/templates/email_change_verify_subject.html +++ b/api/templates/email_change_verify_subject.html @@ -1 +1 @@ -{{define "verify_new_email_subject"}}[{{.ClientProps.SiteName}}] Verify new email address for {{.Props.TeamDisplayName}}{{end}} +{{define "email_change_verify_subject"}}[{{.ClientProps.SiteName}}] Verify new email address for {{.Props.TeamDisplayName}}{{end}} diff --git a/api/user.go b/api/user.go index 2d7dd9ab1a..4baf4f81f8 100644 --- a/api/user.go +++ b/api/user.go @@ -888,6 +888,10 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) { } else { team := tresult.Data.(*model.Team) fireAndForgetEmailChangeEmail(rusers[1].Email, team.DisplayName, c.GetTeamURLFromTeam(team), c.GetSiteURL()) + + if utils.Cfg.EmailSettings.RequireEmailVerification { + fireAndForgetEmailChangeVerifyEmail(rusers[0].Id, rusers[0].Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) + } } } @@ -1340,6 +1344,25 @@ func fireAndForgetEmailChangeEmail(email, teamDisplayName, teamURL, siteURL stri }() } +func fireAndForgetEmailChangeVerifyEmail(userId, newUserEmail, teamName, teamDisplayName, siteURL, teamURL string) { + go func() { + + link := fmt.Sprintf("%s/verify_email?uid=%s&hid=%s&teamname=%s&email=%s", siteURL, userId, model.HashPassword(userId), teamName, newUserEmail) + + subjectPage := NewServerTemplatePage("email_change_verify_subject") + subjectPage.Props["SiteURL"] = siteURL + subjectPage.Props["TeamDisplayName"] = teamDisplayName + bodyPage := NewServerTemplatePage("email_change_verify_body") + bodyPage.Props["SiteURL"] = siteURL + bodyPage.Props["TeamDisplayName"] = teamDisplayName + bodyPage.Props["VerifyUrl"] = link + + if err := utils.SendMail(newUserEmail, subjectPage.Render(), bodyPage.Render()); err != nil { + l4g.Error("Failed to send verification email successfully err=%v", err) + } + }() +} + func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) { props := model.MapFromJson(r.Body) diff --git a/web/react/components/user_settings/user_settings_general.jsx b/web/react/components/user_settings/user_settings_general.jsx index bd7ed12dbd..d2f1117d5b 100644 --- a/web/react/components/user_settings/user_settings_general.jsx +++ b/web/react/components/user_settings/user_settings_general.jsx @@ -28,6 +28,7 @@ export default class UserSettingsGeneralTab extends React.Component { this.updateLastName = this.updateLastName.bind(this); this.updateNickname = this.updateNickname.bind(this); this.updateEmail = this.updateEmail.bind(this); + this.updateConfirmEmail = this.updateConfirmEmail.bind(this); this.updatePicture = this.updatePicture.bind(this); this.updateSection = this.updateSection.bind(this); @@ -97,6 +98,7 @@ export default class UserSettingsGeneralTab extends React.Component { var user = UserStore.getCurrentUser(); var email = this.state.email.trim().toLowerCase(); + var confirmEmail = this.state.confirmEmail.trim().toLowerCase(); if (user.email === email) { return; @@ -107,12 +109,17 @@ export default class UserSettingsGeneralTab extends React.Component { return; } + if (email !== confirmEmail) { + this.setState({emailError: 'The new emails you entered do not match'}); + return; + } + user.email = email; - if (!this.state.emailEnabled || !this.state.emailVerificationEnabled) { - this.submitUser(user, {emailChangeInProgress: false}); - } else { + if (this.state.emailEnabled && this.state.emailVerificationEnabled) { this.submitUser(user, {emailChangeInProgress: true}); + } else { + this.submitUser(user, {emailChangeInProgress: false}); } } submitUser(user, newState) { @@ -191,6 +198,9 @@ export default class UserSettingsGeneralTab extends React.Component { updateEmail(e) { this.setState({email: e.target.value}); } + updateConfirmEmail(e) { + this.setState({confirmEmail: e.target.value}); + } updatePicture(e) { if (e.target.files && e.target.files[0]) { this.setState({picture: e.target.files[0]}); @@ -202,7 +212,8 @@ export default class UserSettingsGeneralTab extends React.Component { } } updateSection(section) { - this.setState(assign({}, this.setupInitialState(this.props), {clientError: '', serverError: '', emailError: ''})); + const emailChangeInProgress = this.state.emailChangeInProgress; + this.setState(assign({}, this.setupInitialState(this.props), {emailChangeInProgress: emailChangeInProgress, clientError: '', serverError: '', emailError: ''})); this.submitActive = false; this.props.updateSection(section); } @@ -226,7 +237,7 @@ export default class UserSettingsGeneralTab extends React.Component { var emailVerificationEnabled = global.window.config.RequireEmailVerification === 'true'; return {username: user.username, firstName: user.first_name, lastName: user.last_name, nickname: user.nickname, - email: user.email, picture: null, loadingPicture: false, emailEnabled: emailEnabled, + email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailEnabled: emailEnabled, emailVerificationEnabled: emailVerificationEnabled, emailChangeInProgress: false}; } render() { @@ -477,6 +488,22 @@ export default class UserSettingsGeneralTab extends React.Component { /> + + ); + + inputs.push( +
+
+ +
+ +
+
{helpText}
); From f85dc7f575a9aad45d7914279300a22e9a6fae8a Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Mon, 5 Oct 2015 14:54:15 -0700 Subject: [PATCH 3/4] Resending the verification email now sends the appropriate version of the email depending on whether it's a change or first signup --- api/user.go | 4 ++-- web/web.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/user.go b/api/user.go index 4baf4f81f8..13292c4344 100644 --- a/api/user.go +++ b/api/user.go @@ -890,7 +890,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) { fireAndForgetEmailChangeEmail(rusers[1].Email, team.DisplayName, c.GetTeamURLFromTeam(team), c.GetSiteURL()) if utils.Cfg.EmailSettings.RequireEmailVerification { - fireAndForgetEmailChangeVerifyEmail(rusers[0].Id, rusers[0].Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) + FireAndForgetEmailChangeVerifyEmail(rusers[0].Id, rusers[0].Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) } } } @@ -1344,7 +1344,7 @@ func fireAndForgetEmailChangeEmail(email, teamDisplayName, teamURL, siteURL stri }() } -func fireAndForgetEmailChangeVerifyEmail(userId, newUserEmail, teamName, teamDisplayName, siteURL, teamURL string) { +func FireAndForgetEmailChangeVerifyEmail(userId, newUserEmail, teamName, teamDisplayName, siteURL, teamURL string) { go func() { link := fmt.Sprintf("%s/verify_email?uid=%s&hid=%s&teamname=%s&email=%s", siteURL, userId, model.HashPassword(userId), teamName, newUserEmail) diff --git a/web/web.go b/web/web.go index a1bbf5a818..4ca60f61a9 100644 --- a/web/web.go +++ b/web/web.go @@ -414,7 +414,12 @@ func verifyEmail(c *api.Context, w http.ResponseWriter, r *http.Request) { return } else { user := result.Data.(*model.User) - api.FireAndForgetVerifyEmail(user.Id, user.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) + + if user.LastActivityAt > 0 { + api.FireAndForgetEmailChangeVerifyEmail(user.Id, user.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) + } else { + api.FireAndForgetVerifyEmail(user.Id, user.Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) + } newAddress := strings.Replace(r.URL.String(), "&resend=true", "&resend_success=true", -1) http.Redirect(w, r, newAddress, http.StatusFound) From c84fe62ca199485dccefc37e00ca2bef45d47c6d Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Tue, 6 Oct 2015 08:58:31 -0700 Subject: [PATCH 4/4] Added new email to email change notification --- api/templates/email_change_body.html | 2 +- api/user.go | 11 ++++--- .../user_settings/user_settings_general.jsx | 32 +++++++------------ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/api/templates/email_change_body.html b/api/templates/email_change_body.html index 7addb6f35d..5c5f6c7779 100644 --- a/api/templates/email_change_body.html +++ b/api/templates/email_change_body.html @@ -18,7 +18,7 @@ diff --git a/api/user.go b/api/user.go index 13292c4344..4d12f0f33d 100644 --- a/api/user.go +++ b/api/user.go @@ -887,7 +887,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) { l4g.Error(tresult.Err.Message) } else { team := tresult.Data.(*model.Team) - fireAndForgetEmailChangeEmail(rusers[1].Email, team.DisplayName, c.GetTeamURLFromTeam(team), c.GetSiteURL()) + fireAndForgetEmailChangeEmail(rusers[1].Email, rusers[0].Email, team.DisplayName, c.GetTeamURLFromTeam(team), c.GetSiteURL()) if utils.Cfg.EmailSettings.RequireEmailVerification { FireAndForgetEmailChangeVerifyEmail(rusers[0].Id, rusers[0].Email, team.Name, team.DisplayName, c.GetSiteURL(), c.GetTeamURLFromTeam(team)) @@ -1326,7 +1326,7 @@ func fireAndForgetPasswordChangeEmail(email, teamDisplayName, teamURL, siteURL, }() } -func fireAndForgetEmailChangeEmail(email, teamDisplayName, teamURL, siteURL string) { +func fireAndForgetEmailChangeEmail(oldEmail, newEmail, teamDisplayName, teamURL, siteURL string) { go func() { subjectPage := NewServerTemplatePage("email_change_subject") @@ -1336,9 +1336,10 @@ func fireAndForgetEmailChangeEmail(email, teamDisplayName, teamURL, siteURL stri bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["TeamDisplayName"] = teamDisplayName bodyPage.Props["TeamURL"] = teamURL + bodyPage.Props["NewEmail"] = newEmail - if err := utils.SendMail(email, subjectPage.Render(), bodyPage.Render()); err != nil { - l4g.Error("Failed to send update password email successfully err=%v", err) + if err := utils.SendMail(oldEmail, subjectPage.Render(), bodyPage.Render()); err != nil { + l4g.Error("Failed to send email change notification email successfully err=%v", err) } }() @@ -1358,7 +1359,7 @@ func FireAndForgetEmailChangeVerifyEmail(userId, newUserEmail, teamName, teamDis bodyPage.Props["VerifyUrl"] = link if err := utils.SendMail(newUserEmail, subjectPage.Render(), bodyPage.Render()); err != nil { - l4g.Error("Failed to send verification email successfully err=%v", err) + l4g.Error("Failed to send email change verification email successfully err=%v", err) } }() } diff --git a/web/react/components/user_settings/user_settings_general.jsx b/web/react/components/user_settings/user_settings_general.jsx index d2f1117d5b..c6c508ad7a 100644 --- a/web/react/components/user_settings/user_settings_general.jsx +++ b/web/react/components/user_settings/user_settings_general.jsx @@ -115,26 +115,19 @@ export default class UserSettingsGeneralTab extends React.Component { } user.email = email; - - if (this.state.emailEnabled && this.state.emailVerificationEnabled) { - this.submitUser(user, {emailChangeInProgress: true}); - } else { - this.submitUser(user, {emailChangeInProgress: false}); - } + this.submitUser(user); } - submitUser(user, newState) { + submitUser(user) { client.updateUser(user, function updateSuccess() { this.updateSection(''); AsyncClient.getMe(); + const verificationEnabled = global.window.config.SendEmailNotifications === 'true' && global.window.config.RequireEmailVerification === 'true'; - if (newState) { - if (newState.emailChangeInProgress) { - ErrorStore.storeLastError({message: 'Check your email at ' + user.email + ' to verify the address.'}); - ErrorStore.emitChange(); - } - - this.setState(newState); + if (verificationEnabled) { + ErrorStore.storeLastError({message: 'Check your email at ' + user.email + ' to verify the address.'}); + ErrorStore.emitChange(); + this.setState({emailChangeInProgress: true}); } }.bind(this), function updateFailure(err) { @@ -233,12 +226,9 @@ export default class UserSettingsGeneralTab extends React.Component { } setupInitialState(props) { var user = props.user; - var emailEnabled = global.window.config.SendEmailNotifications === 'true'; - var emailVerificationEnabled = global.window.config.RequireEmailVerification === 'true'; return {username: user.username, firstName: user.first_name, lastName: user.last_name, nickname: user.nickname, - email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailEnabled: emailEnabled, - emailVerificationEnabled: emailVerificationEnabled, emailChangeInProgress: false}; + email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailChangeInProgress: false}; } render() { var user = this.props.user; @@ -462,11 +452,13 @@ export default class UserSettingsGeneralTab extends React.Component { } var emailSection; if (this.props.activeSection === 'email') { + const emailEnabled = global.window.config.SendEmailNotifications === 'true'; + const emailVerificationEnabled = global.window.config.RequireEmailVerification === 'true'; let helpText = 'Email is used for notifications, and requires verification if changed.'; - if (!this.state.emailEnabled) { + if (!emailEnabled) { helpText =
{'Email has been disabled by your system administrator. No notification emails will be sent until it is enabled.'}
; - } else if (!this.state.emailVerificationEnabled) { + } else if (!emailVerificationEnabled) { helpText = 'Email is used for notifications.'; } else if (this.state.emailChangeInProgress) { const newEmail = UserStore.getCurrentUser().email;

You updated your email

-

You email address for {{.Props.TeamDisplayName}} has been changed.
If you did not make this change, please contact the system administrator.

+

You email address for {{.Props.TeamDisplayName}} has been changed to {{.Props.NewEmail}}.
If you did not make this change, please contact the system administrator.