-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from Carifio24/youve-got-mail
Send email notification when educator account is created
- Loading branch information
Showing
4 changed files
with
79 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
// import nodemailer from "nodemailer"; | ||
import nodemailer, { SendMailOptions } from "nodemailer"; | ||
import dotenv from "dotenv"; | ||
|
||
// const transporter = nodemailer.createTransport({ | ||
// host: "smtp.gmail.com", | ||
// port: 587, | ||
// secure: false, | ||
// auth: { | ||
// user: "[email protected]", | ||
// pass: "C@rifio00" | ||
// } | ||
// }); | ||
dotenv.config(); | ||
|
||
// export async function sendEmail(to: string, from: string, subject: string, body: string) { | ||
// const options = { | ||
// from: from, | ||
// to: to, | ||
// subject: subject, | ||
// text: body | ||
// }; | ||
// transporter.sendMail(options, (error, info) => { | ||
// if (error) { | ||
// console.log(error); | ||
// } else { | ||
// console.log("Email sent: " + info.response); | ||
// } | ||
// }); | ||
// } | ||
const transporter = nodemailer.createTransport({ | ||
service: process.env.EMAIL_SERVICE, | ||
auth: { | ||
user: process.env.EMAIL_USERNAME, | ||
pass: process.env.EMAIL_PASSWORD, | ||
}, | ||
}); | ||
|
||
export interface SendEmailOptions { | ||
to: string; | ||
subject: string; | ||
text: string; | ||
} | ||
|
||
export async function sendEmail(options: SendEmailOptions) { | ||
const sendOptions: SendMailOptions = { | ||
...options, | ||
from: process.env.EMAIL_FROM, | ||
}; | ||
transporter.sendMail(sendOptions, (error, info) => { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log("Email sent: " + info.response); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ import * as Either from "effect/Either"; | |
import { setupApp } from "./app"; | ||
import { getAPIKey } from "./authorization"; | ||
import { Sequelize } from "sequelize"; | ||
import { sendEmail } from "./email"; | ||
|
||
// TODO: Clean up these type definitions | ||
|
||
|
@@ -144,10 +145,24 @@ export function createApp(db: Sequelize): Express { | |
result = SignUpResult.BadRequest; | ||
} | ||
const statusCode = SignUpResult.statusCode(result); | ||
const success = SignUpResult.success(result); | ||
|
||
if (success) { | ||
sendEmail({ | ||
to: "[email protected]", | ||
subject: "Educator account created", | ||
text: ` | ||
Educator account created at ${Date()}: | ||
Name: ${data.first_name} ${data.last_name} | ||
Email: ${data.email} | ||
`, | ||
}) | ||
.catch(error => console.log(error)); | ||
} | ||
res.status(statusCode).json({ | ||
educator_info: data, | ||
status: result, | ||
success: SignUpResult.success(result) | ||
success, | ||
}); | ||
}); | ||
|
||
|