Commit 5de1083e by GD-A-150752

update-email-template

parent 61c560b7
import { MongoObservable } from 'meteor-rxjs';
import { SettingModel } from '../models/setting.model';
export const settingsCollection = new MongoObservable.Collection('setting');
export const settingsCollection = new MongoObservable.Collection<SettingModel>('setting');
......@@ -5,6 +5,7 @@ export const PERMISSIONS = {
CAN_UPDATE_USER: 'CAN_UPDATE_USER',
CAN_SEE_ALL_USERS: 'CAN_SEE_ALL_USERS',
CAN_ACCESS_DASHBOARD_PAGE: 'CAN_ACCESS_DASHBOARD_PAGE',
CAN_UPDATE_SETTINGS: 'CAN_UPDATE_SETTINGS',
};
export const CONFIG = {
......
import { Meteor } from 'meteor/meteor';
import { PERMISSIONS } from '../config';
import { UtilsService } from '../services/utils.service';
import { settingsCollection } from '../collections/setting.collections';
Meteor.methods({
updateSettings(setting: any): void {
if (UtilsService.hasPermission(PERMISSIONS.CAN_UPDATE_SETTINGS)) {
settingsCollection.update(setting.id, {
$set: {
Value: {
SUBJECT: setting.subject,
CONTENT: setting.content,
},
},
});
} else {
throw new Meteor.Error(403, 'Not Enough Permissions');
}
},
});
......@@ -56,17 +56,28 @@ Migrations.add({
version: 3,
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({ Key: 'REGISTER' }).fetch().length === 0) {
settingsCollection.insert({
Key: 'REGISTER',
Value: {
SUBJECT: 'Welcome to $platform',
CONTENT: 'Hi $name! You are our $role now. Please click on the link <a href="$link" target="_blank">$link</a> to verify your account.',
},
Description: 'Register Email Template',
IsEmail: true,
});
}
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>.' });
if (settingsCollection.find({ Key: 'RESET' }).fetch().length === 0) {
settingsCollection.insert({
Key: 'RESET',
Value: {
SUBJECT: 'Reset Password for $platform',
CONTENT: 'Hi $name! Don\'t worry. Reset your password by clicking on the following link <a href="$link" target="_blank">$link</a>.',
},
Description: 'Reset Password Email Template',
IsEmail: true,
});
}
},
});
export interface SettingModel {
_id?: string;
Key?: string;
Value?: any;
Description?: string;
IsEmail?: boolean;
}
import { settingsCollection } from '../collections/setting.collections';
Meteor.publish('settings', () => settingsCollection.find({}));
......@@ -9,14 +9,14 @@ export class EmailService {
Accounts.emailTemplates.verifyEmail = {
subject() {
const content: any = settingsCollection.findOne({ REGISTER_HEADING: { $exists: true } });
return content ? content.REGISTER_HEADING.replace('$platform', CONFIG.SiteName) : 'Welcome';
const content: any = settingsCollection.findOne({ Key: 'REGISTER' });
return content ? content.Value.SUBJECT.replace('$platform', CONFIG.SiteName) : 'Welcome';
},
html(usr, url) {
const token = url.substr(url.lastIndexOf('/') + 1);
const link = `${process.env.appUrl}#/auth/verify-email/${token}`;
const content: any = settingsCollection.findOne({ REGISTER_EMAIL_BODY: { $exists: true } });
return content.REGISTER_EMAIL_BODY.replace(/\$name/g, user.name)
const content: any = settingsCollection.findOne({ Key: 'REGISTER' });
return content.Value.CONTENT.replace(/\$name/g, user.name)
.replace(/\$role/g, user.role)
.replace(/\$link/g, link);
},
......@@ -32,14 +32,14 @@ export class EmailService {
Accounts.emailTemplates.resetPassword = {
subject() {
const content: any = settingsCollection.findOne({ RESET_HEADING: { $exists: true } });
return content ? content.RESET_HEADING.replace('$platform', CONFIG.SiteName) : 'Welcome';
const content: any = settingsCollection.findOne({ Key: 'RESET' });
return content ? content.Value.SUBJECT.replace('$platform', CONFIG.SiteName) : 'Welcome';
},
html(usr, url) {
const token = url.substr(url.lastIndexOf('/') + 1);
const link = `${process.env.appUrl}#/auth/reset-password/${token}`;
const content: any = settingsCollection.findOne({ RESET_EMAIL_BODY: { $exists: true } });
return content.RESET_EMAIL_BODY.replace(/\$name/g, user.profile.name)
const content: any = settingsCollection.findOne({ Key: 'RESET' });
return content.Value.CONTENT.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