Skip to content

Commit

Permalink
Merge pull request #2561 from cisagov/issue-2508/revert-back-to-s3-em…
Browse files Browse the repository at this point in the history
…ail-templates

Revert back to S3 html template logic in registration email process
  • Loading branch information
nickviola authored Feb 23, 2024
2 parents 5f6de4e + edba51d commit acb479e
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 356 deletions.
60 changes: 27 additions & 33 deletions backend/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
import { ValidationOptions, validateOrReject } from 'class-validator';
import { ClassType } from 'class-transformer/ClassTransformer';
import { plainToClass } from 'class-transformer';
import S3Client from '../tasks/s3-client';
import { SES } from 'aws-sdk';
import * as nodemailer from 'nodemailer';
import fs from 'fs';
import * as handlebars from 'handlebars';

export const validateBody = async <T>(
Expand Down Expand Up @@ -146,47 +146,40 @@ export const sendUserRegistrationEmail = async (
subject: string,
firstName: string,
lastName: string,
templateFilePath: string
templateFileName: string
) => {
console.log('TemplateFilePath: ', templateFilePath);
const fs = require('fs');
const htmlTemplate = await fs.promises.readFile(
templateFilePath,
'utf8',
(err, data) => {
if (err) {
console.error('Error reading file data', err);
return;
}
console.log('Finished reading file');
return data;
}
);
const template = handlebars.compile(htmlTemplate);
const data = {
firstName: firstName,
lastName: lastName
};
try {
const client = new S3Client();
const htmlTemplate = await client.getEmailAsset(templateFileName);
const template = handlebars.compile(htmlTemplate);
const data = {
firstName: firstName,
lastName: lastName
};

const htmlToSend = template(data);
const mailOptions = {
from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER!,
to: recepient,
subject: subject,
html: htmlToSend,
replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!
};
const htmlToSend = template(data);
const mailOptions = {
from: process.env.CROSSFEED_SUPPORT_EMAIL_SENDER!,
to: recepient,
subject: subject,
html: htmlToSend,
replyTo: process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO!
};
} catch (errorMessage) {
console.log('Email error: ', errorMessage);
}
};

export const sendRegistrationDeniedEmail = async (
recepient: string,
subject: string,
firstName: string,
lastName: string,
templateFilePath: string
templateFileName: string
) => {
try {
const htmlTemplate = fs.readFileSync(templateFilePath, 'utf-8');
const client = new S3Client();
const htmlTemplate = await client.getEmailAsset(templateFileName);
const template = handlebars.compile(htmlTemplate);
const data = {
firstName: firstName,
Expand All @@ -211,10 +204,11 @@ export const sendRegistrationApprovedEmail = async (
subject: string,
firstName: string,
lastName: string,
templateFilePath: string
templateFileName: string
) => {
try {
const htmlTemplate = fs.readFileSync(templateFilePath, 'utf-8');
const client = new S3Client();
const htmlTemplate = await client.getEmailAsset(templateFileName);
const template = handlebars.compile(htmlTemplate);
const data = {
firstName: firstName,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export const register = wrapHandler(async (event) => {
'Crossfeed Registration Pending',
savedUser.firstName,
savedUser.lastName,
'../email_templates/crossfeed_registration_notification.html'
'crossfeed_registration_notification.html'
);

return {
Expand Down Expand Up @@ -662,7 +662,7 @@ export const registrationApproval = wrapHandler(async (event) => {
'Crossfeed Registration Approved',
user.firstName,
user.lastName,
'../email_templates/crossfeed_approval_notification.html'
'crossfeed_approval_notification.html'
);

// TODO: Handle Response Output
Expand Down Expand Up @@ -707,7 +707,7 @@ export const registrationDenial = wrapHandler(async (event) => {
'Crossfeed Registration Denied',
user.firstName,
user.lastName,
'../email_templates/crossfeed_denial_notification.html'
'crossfeed_denial_notification.html'
);

// TODO: Handle Response Output
Expand Down
Binary file removed backend/src/email_templates/banner.png
Binary file not shown.
105 changes: 0 additions & 105 deletions backend/src/email_templates/crossfeed_approval_notification.html

This file was deleted.

104 changes: 0 additions & 104 deletions backend/src/email_templates/crossfeed_denial_notification.html

This file was deleted.

Loading

0 comments on commit acb479e

Please sign in to comment.