Commit 3b23497b by GD-A-150752

custom-email

parent 6fd1e96b
...@@ -6,3 +6,7 @@ export const PERMISSIONS = { ...@@ -6,3 +6,7 @@ export const PERMISSIONS = {
CAN_SEE_ALL_USERS: 'CAN_SEE_ALL_USERS', CAN_SEE_ALL_USERS: 'CAN_SEE_ALL_USERS',
CAN_ACCESS_DASHBOARD_PAGE: 'CAN_ACCESS_DASHBOARD_PAGE', CAN_ACCESS_DASHBOARD_PAGE: 'CAN_ACCESS_DASHBOARD_PAGE',
}; };
export const CONFIG = {
SiteName: 'JIBC',
};
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>.`;
},
};
process.env.S3 = '{"path": "files", "key":"AKIAWEWXPEPGGRRUHLH4","secret":"e1oyj+xF14yvNqC030EdaG/o+Q/EWeWy9WzpvYRZ","bucket":"siingio","region":"us-east-1"}'; process.env.S3 = '{"path": "files", "key":"AKIAWEWXPEPGGRRUHLH4","secret":"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","bucket":"siingio","region":"us-east-1"}';
process.env.MAIL_URL = 'smtp://postmaster%40mail.vqode.com:VQode1234@smtp.mailgun.org:587'; process.env.MAIL_URL = 'smtp://postmaster%40mail.vqode.com:VQode1234@smtp.mailgun.org:587';
process.env.appUrl = 'http://localhost:4200/';
import { Meteor } from 'meteor/meteor';
import { EmailService } from '../services/email.service';
Meteor.methods({
sendForgotPasswordEmail(email: string): boolean {
const user: Meteor.User = Accounts.findUserByEmail(email);
if (user) {
EmailService.sendForgotPasswordEmail(user, email);
return true;
}
throw new Meteor.Error(422, 'Email address doesn\'t exist.');
},
});
...@@ -3,6 +3,7 @@ import { Roles } from '../collections/role.collection'; ...@@ -3,6 +3,7 @@ import { Roles } from '../collections/role.collection';
import { PERMISSIONS } from '../config'; import { PERMISSIONS } from '../config';
import { UtilsService } from '../services/utils.service'; import { UtilsService } from '../services/utils.service';
import { QueryModel } from '../models/query.model'; import { QueryModel } from '../models/query.model';
import { EmailService } from '../services/email.service';
Meteor.methods({ Meteor.methods({
...@@ -17,7 +18,6 @@ Meteor.methods({ ...@@ -17,7 +18,6 @@ Meteor.methods({
registerUser(user: any): string { registerUser(user: any): string {
const defaultRole = Roles.findOne({ title: user.role }); const defaultRole = Roles.findOne({ title: user.role });
if (!Accounts.findUserByEmail(user.email)) { if (!Accounts.findUserByEmail(user.email)) {
const userObj = { const userObj = {
email: user.email, email: user.email,
password: user.password, password: user.password,
...@@ -27,7 +27,10 @@ Meteor.methods({ ...@@ -27,7 +27,10 @@ Meteor.methods({
role: defaultRole._id, role: defaultRole._id,
}, },
}; };
return Accounts.createUser(userObj); const userId = Accounts.createUser(userObj);
EmailService.sendVerificationEmail(user, userId);
return userId;
} }
throw new Meteor.Error(422, 'Email address already in use.'); throw new Meteor.Error(422, 'Email address already in use.');
}, },
......
import { CONFIG } from '../config';
import { emailEnum } from '../enum/email.enum';
export class EmailService {
static sendVerificationEmail(user: any, userId: string): void {
Accounts.emailTemplates.siteName = CONFIG.SiteName;
// Will uncomment it later with domain email
// Accounts.emailTemplates.from = CONFIG.DomainEmail;
Accounts.emailTemplates.verifyEmail = {
subject() {
return emailEnum.REGISTER_HEADING(CONFIG.SiteName);
},
html(usr, url) {
const token = url.substr(url.lastIndexOf('/') + 1);
const link = `${process.env.appUrl}#/auth/verify-email/${token}`;
return emailEnum.REGISTER_EMAIL_BODY(user.name, user.role, link);
},
};
Accounts.sendVerificationEmail(userId, user.email);
}
static sendForgotPasswordEmail(user: Meteor.User, email: string): void {
Accounts.emailTemplates.siteName = CONFIG.SiteName;
// Will uncomment it later with domain email
// Accounts.emailTemplates.from = CONFIG.DomainEmail;
Accounts.emailTemplates.resetPassword = {
subject() {
return emailEnum.RESET_HEADING(CONFIG.SiteName);
},
html(usr, url) {
const token = url.substr(url.lastIndexOf('/') + 1);
const link = `${process.env.appUrl}#/auth/reset-password/${token}`;
return emailEnum.RESET_EMAIL_BODY(user.profile.name, link);
},
};
Accounts.sendResetPasswordEmail(user._id, email);
}
}
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