Added new email to email change notification

Этот коммит содержится в:
Reed Garmsen
2015-10-06 08:58:31 -07:00
родитель f85dc7f575
Коммит c84fe62ca1
3 изменённых файлов: 19 добавлений и 26 удалений

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

@@ -18,7 +18,7 @@
<tr> <tr>
<td style="border-bottom: 1px solid #ddd; padding: 0 0 20px;"> <td style="border-bottom: 1px solid #ddd; padding: 0 0 20px;">
<h2 style="font-weight: normal; margin-top: 10px;">You updated your email</h2> <h2 style="font-weight: normal; margin-top: 10px;">You updated your email</h2>
<p>You email address for {{.Props.TeamDisplayName}} has been changed.<br>If you did not make this change, please contact the system administrator.</p> <p>You email address for {{.Props.TeamDisplayName}} has been changed to {{.Props.NewEmail}}.<br>If you did not make this change, please contact the system administrator.</p>
</td> </td>
</tr> </tr>
<tr> <tr>

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

@@ -887,7 +887,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
l4g.Error(tresult.Err.Message) l4g.Error(tresult.Err.Message)
} else { } else {
team := tresult.Data.(*model.Team) 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 { 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))
@@ -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() { go func() {
subjectPage := NewServerTemplatePage("email_change_subject") subjectPage := NewServerTemplatePage("email_change_subject")
@@ -1336,9 +1336,10 @@ func fireAndForgetEmailChangeEmail(email, teamDisplayName, teamURL, siteURL stri
bodyPage.Props["SiteURL"] = siteURL bodyPage.Props["SiteURL"] = siteURL
bodyPage.Props["TeamDisplayName"] = teamDisplayName bodyPage.Props["TeamDisplayName"] = teamDisplayName
bodyPage.Props["TeamURL"] = teamURL bodyPage.Props["TeamURL"] = teamURL
bodyPage.Props["NewEmail"] = newEmail
if err := utils.SendMail(email, subjectPage.Render(), bodyPage.Render()); err != nil { if err := utils.SendMail(oldEmail, subjectPage.Render(), bodyPage.Render()); err != nil {
l4g.Error("Failed to send update password email successfully err=%v", err) 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 bodyPage.Props["VerifyUrl"] = link
if err := utils.SendMail(newUserEmail, subjectPage.Render(), bodyPage.Render()); err != nil { 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)
} }
}() }()
} }

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

@@ -115,26 +115,19 @@ export default class UserSettingsGeneralTab extends React.Component {
} }
user.email = email; user.email = email;
this.submitUser(user);
if (this.state.emailEnabled && this.state.emailVerificationEnabled) {
this.submitUser(user, {emailChangeInProgress: true});
} else {
this.submitUser(user, {emailChangeInProgress: false});
}
} }
submitUser(user, newState) { submitUser(user) {
client.updateUser(user, client.updateUser(user,
function updateSuccess() { function updateSuccess() {
this.updateSection(''); this.updateSection('');
AsyncClient.getMe(); AsyncClient.getMe();
const verificationEnabled = global.window.config.SendEmailNotifications === 'true' && global.window.config.RequireEmailVerification === 'true';
if (newState) { if (verificationEnabled) {
if (newState.emailChangeInProgress) { ErrorStore.storeLastError({message: 'Check your email at ' + user.email + ' to verify the address.'});
ErrorStore.storeLastError({message: 'Check your email at ' + user.email + ' to verify the address.'}); ErrorStore.emitChange();
ErrorStore.emitChange(); this.setState({emailChangeInProgress: true});
}
this.setState(newState);
} }
}.bind(this), }.bind(this),
function updateFailure(err) { function updateFailure(err) {
@@ -233,12 +226,9 @@ export default class UserSettingsGeneralTab extends React.Component {
} }
setupInitialState(props) { setupInitialState(props) {
var user = props.user; 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, 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, email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailChangeInProgress: false};
emailVerificationEnabled: emailVerificationEnabled, emailChangeInProgress: false};
} }
render() { render() {
var user = this.props.user; var user = this.props.user;
@@ -462,11 +452,13 @@ export default class UserSettingsGeneralTab extends React.Component {
} }
var emailSection; var emailSection;
if (this.props.activeSection === 'email') { 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.'; let helpText = 'Email is used for notifications, and requires verification if changed.';
if (!this.state.emailEnabled) { if (!emailEnabled) {
helpText = <div className='setting-list__hint text-danger'>{'Email has been disabled by your system administrator. No notification emails will be sent until it is enabled.'}</div>; helpText = <div className='setting-list__hint text-danger'>{'Email has been disabled by your system administrator. No notification emails will be sent until it is enabled.'}</div>;
} else if (!this.state.emailVerificationEnabled) { } else if (!emailVerificationEnabled) {
helpText = 'Email is used for notifications.'; helpText = 'Email is used for notifications.';
} else if (this.state.emailChangeInProgress) { } else if (this.state.emailChangeInProgress) {
const newEmail = UserStore.getCurrentUser().email; const newEmail = UserStore.getCurrentUser().email;