Alert by email when an account is approved/activated/deactivated

pull/7098/head
Rodrigo Nascimento 8 years ago
parent a9b004c367
commit b2d99d1ea7
No known key found for this signature in database
GPG Key ID: CFCE33B7B01AC335
  1. 6
      packages/rocketchat-i18n/i18n/en.i18n.json
  2. 78
      server/lib/accounts.js
  3. 13
      server/methods/setUserActiveStatus.js

@ -48,6 +48,12 @@
"Accounts_denyUnverifiedEmail": "Deny unverified email",
"Accounts_EmailVerification": "Email Verification",
"Accounts_EmailVerification_Description": "Make sure you have correct SMTP settings to use this feature",
"Accounts_Email_Approved": "[name]<br/><br/><p>Your account was approved.</p>",
"Accounts_Email_Activated": "[name]<br/><br/><p>Your account was activated.</p>",
"Accounts_Email_Deactivated": "[name]<br/><br/><p>Your account was deactivated.</p>",
"Accounts_Email_Approved_Subject": "Account approved",
"Accounts_Email_Activated_Subject": "Account activated",
"Accounts_Email_Deactivated_Subject": "Account deactivated",
"Accounts_Enrollment_Email": "Enrollment Email",
"Accounts_Enrollment_Email_Default": "<h2>Welcome to <h1>[Site_Name]</h1></h2><p>Go to <a href=\"[Site_URL]\"><a href=\"[Site_URL]\">[Site_URL]</a></a> and try the best open source chat solution available today!</p>",
"Accounts_Enrollment_Email_Description": "You may use the following placeholders: <br /><ul><li>[name], [fname], [lname] for the user's full name, first name or last name, respectively.</li><li>[email] for the user's email.</li><li>[Site_Name] and [Site_URL] for the Application Name and URL respectively.</li></ul>",

@ -12,7 +12,53 @@ Accounts.emailTemplates.siteName = RocketChat.settings.get('Site_Name');
Accounts.emailTemplates.from = `${ RocketChat.settings.get('Site_Name') } <${ RocketChat.settings.get('From_Email') }>`;
Accounts.emailTemplates.notifyAdmin = {};
Accounts.emailTemplates.userToActivate = {
subject() {
const subject = TAPi18n.__('Accounts_Admin_Email_Approval_Needed_Subject_Default');
const siteName = RocketChat.settings.get('Site_Name');
return `[${ siteName }] ${ subject }`;
},
html(options = {}) {
const header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
const footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
const email = options.reason ? 'Accounts_Admin_Email_Approval_Needed_With_Reason_Default' : 'Accounts_Admin_Email_Approval_Needed_Default';
const html = RocketChat.placeholders.replace(TAPi18n.__(email), {
name: options.name,
email: options.email,
reason: options.reason
});
return header + html + footer;
}
};
Accounts.emailTemplates.userActivated = {
subject({active, username}) {
const action = active ? (username ? 'Activated' : 'Approved') : 'Deactivated';
const subject = `Accounts_Email_${ action }_Subject`;
const siteName = RocketChat.settings.get('Site_Name');
return `[${ siteName }] ${ TAPi18n.__(subject) }`;
},
html({active, name, username}) {
const header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
const footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
const action = active ? (username ? 'Activated' : 'Approved') : 'Deactivated';
const html = RocketChat.placeholders.replace(TAPi18n.__(`Accounts_Email_${ action }`), {
name
});
return header + html + footer;
}
};
const verifyEmailHtml = Accounts.emailTemplates.verifyEmail.text;
@ -61,28 +107,6 @@ Accounts.emailTemplates.enrollAccount.html = function(user = {}/*, url*/) {
return header + html + footer;
};
Accounts.emailTemplates.notifyAdmin.subject = function() {
const subject = TAPi18n.__('Accounts_Admin_Email_Approval_Needed_Subject_Default');
const siteName = RocketChat.settings.get('Site_Name');
return `[${ siteName }] ${ subject }`;
};
Accounts.emailTemplates.notifyAdmin.html = function(options = {}) {
const header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
const footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
const email = options.reason ? 'Accounts_Admin_Email_Approval_Needed_With_Reason_Default' : 'Accounts_Admin_Email_Approval_Needed_Default';
const html = RocketChat.placeholders.replace(TAPi18n.__(email), {
name: options.name,
email: options.email,
reason: options.reason
});
return header + html + footer;
};
Accounts.onCreateUser(function(options, user = {}) {
RocketChat.callbacks.run('beforeCreateUser', options, user);
@ -123,8 +147,8 @@ Accounts.onCreateUser(function(options, user = {}) {
RocketChat.models.Roles.findUsersInRole('admin').forEach(adminUser => {
if (Array.isArray(adminUser.emails)) {
adminUser.emails.forEach(address => {
destinations.push(`${ adminUser.name }<${ address }>`);
adminUser.emails.forEach(email => {
destinations.push(`${ adminUser.name }<${ email.address }>`);
});
}
});
@ -132,8 +156,8 @@ Accounts.onCreateUser(function(options, user = {}) {
const email = {
to: destinations,
from: RocketChat.settings.get('From_Email'),
subject: Accounts.emailTemplates.notifyAdmin.subject(),
html: Accounts.emailTemplates.notifyAdmin.html(options)
subject: Accounts.emailTemplates.userToActivate.subject(),
html: Accounts.emailTemplates.userToActivate.html(options)
};
Meteor.defer(() => Email.send(email));

@ -30,6 +30,19 @@ Meteor.methods({
RocketChat.models.Users.unsetReason(userId);
}
const destinations = Array.isArray(user.emails) && user.emails.map(email => `${ user.name || user.username }<${ email.address }>`);
if (destinations) {
const email = {
to: destinations,
from: RocketChat.settings.get('From_Email'),
subject: Accounts.emailTemplates.userActivated.subject({active}),
html: Accounts.emailTemplates.userActivated.html({active, name: user.name, username: user.username})
};
Meteor.defer(() => Email.send(email));
}
return true;
}

Loading…
Cancel
Save