Commit 78911973 by GD-A-150752

email-migration

parent 3b23497b
...@@ -22,3 +22,4 @@ accounts-password ...@@ -22,3 +22,4 @@ accounts-password
dburles:collection-helpers dburles:collection-helpers
ostrio:files ostrio:files
tunguska:reactive-aggregate tunguska:reactive-aggregate
percolate:migrations
...@@ -56,6 +56,7 @@ npm-mongo@3.1.2 ...@@ -56,6 +56,7 @@ npm-mongo@3.1.2
ordered-dict@1.1.0 ordered-dict@1.1.0
ostrio:cookies@2.4.1 ostrio:cookies@2.4.1
ostrio:files@1.12.2 ostrio:files@1.12.2
percolate:migrations@1.0.2
promise@0.11.2 promise@0.11.2
random@1.1.0 random@1.1.0
rate-limit@1.0.9 rate-limit@1.0.9
......
import { MongoObservable } from 'meteor-rxjs';
export const settingsCollection = new MongoObservable.Collection('setting');
export const emailEnum = {
REGISTER_HEADING: (platform: string) => {
return `Welcome to ${platform}`;
},
REGISTER_EMAIL_BODY: (name: string, role: string, link: string) => {
return `Hi ${name}! You are our ${role} now. Please click on the link <a href="${link}" target="_blank">${link}</a> to verify your account.`;
},
RESET_HEADING: (platform: string) => {
return `Reset Password for ${platform}`;
},
RESET_EMAIL_BODY: (name: string, link: string) => {
return `Hi ${name}! Don't worry. Reset your password by clicking on the following link <a href="${link}" target="_blank">${link}</a>.`;
},
};
...@@ -9,7 +9,8 @@ Meteor.startup(() => { ...@@ -9,7 +9,8 @@ Meteor.startup(() => {
if (seed) { if (seed) {
seedDB(); seedDB();
} }
// @ts-ignore
Migrations.migrateTo('latest');
// Validate Login Attempt // Validate Login Attempt
Accounts.validateLoginAttempt((data): boolean => { Accounts.validateLoginAttempt((data): boolean => {
const user: Meteor.User = data.user; const user: Meteor.User = data.user;
......
import { settingsCollection } from './collections/setting.collections';
// @ts-ignore
Migrations.add({
version: 1,
name: 'Adding Email Templates',
up() {
if (settingsCollection.find({ REGISTER_HEADING: { $exists: true } }).fetch().length === 0) {
settingsCollection.insert({ REGISTER_HEADING: 'Welcome to $platform' });
}
if (settingsCollection.find({ REGISTER_EMAIL_BODY: { $exists: true } }).fetch().length === 0) {
settingsCollection.insert({ REGISTER_EMAIL_BODY: 'Hi $name! You are our $role now. Please click on the link <a href="$link" target="_blank">$link</a> to verify your account.' });
}
if (settingsCollection.find({ RESET_HEADING: { $exists: true } }).fetch().length === 0) {
settingsCollection.insert({ RESET_HEADING: 'Reset Password for $platform' });
}
if (settingsCollection.find({ RESET_EMAIL_BODY: { $exists: true } }).fetch().length === 0) {
settingsCollection.insert({ RESET_EMAIL_BODY: 'Hi $name! Don\'t worry. Reset your password by clicking on the following link <a href="$link" target="_blank">$link</a>.' });
}
},
});
import { CONFIG } from '../config'; import { CONFIG } from '../config';
import { emailEnum } from '../enum/email.enum'; import { settingsCollection } from '../collections/setting.collections';
export class EmailService { export class EmailService {
static sendVerificationEmail(user: any, userId: string): void { static sendVerificationEmail(user: any, userId: string): void {
...@@ -9,12 +9,16 @@ export class EmailService { ...@@ -9,12 +9,16 @@ export class EmailService {
Accounts.emailTemplates.verifyEmail = { Accounts.emailTemplates.verifyEmail = {
subject() { subject() {
return emailEnum.REGISTER_HEADING(CONFIG.SiteName); const content: any = settingsCollection.findOne({ REGISTER_HEADING: { $exists: true } });
return content ? content.REGISTER_HEADING.replace('$platform', CONFIG.SiteName) : 'Welcome';
}, },
html(usr, url) { html(usr, url) {
const token = url.substr(url.lastIndexOf('/') + 1); const token = url.substr(url.lastIndexOf('/') + 1);
const link = `${process.env.appUrl}#/auth/verify-email/${token}`; const link = `${process.env.appUrl}#/auth/verify-email/${token}`;
return emailEnum.REGISTER_EMAIL_BODY(user.name, user.role, link); const content: any = settingsCollection.findOne({ REGISTER_EMAIL_BODY: { $exists: true } });
return content.REGISTER_EMAIL_BODY.replace(/\$name/g, user.name)
.replace(/\$role/g, user.role)
.replace(/\$link/g, link);
}, },
}; };
...@@ -28,12 +32,15 @@ export class EmailService { ...@@ -28,12 +32,15 @@ export class EmailService {
Accounts.emailTemplates.resetPassword = { Accounts.emailTemplates.resetPassword = {
subject() { subject() {
return emailEnum.RESET_HEADING(CONFIG.SiteName); const content: any = settingsCollection.findOne({ RESET_HEADING: { $exists: true } });
return content ? content.RESET_HEADING.replace('$platform', CONFIG.SiteName) : 'Welcome';
}, },
html(usr, url) { html(usr, url) {
const token = url.substr(url.lastIndexOf('/') + 1); const token = url.substr(url.lastIndexOf('/') + 1);
const link = `${process.env.appUrl}#/auth/reset-password/${token}`; const link = `${process.env.appUrl}#/auth/reset-password/${token}`;
return emailEnum.RESET_EMAIL_BODY(user.profile.name, link); const content: any = settingsCollection.findOne({ RESET_EMAIL_BODY: { $exists: true } });
return content.RESET_EMAIL_BODY.replace(/\$name/g, user.profile.name)
.replace(/\$link/g, link);
}, },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment