Skip to content

Commit

Permalink
Remove unused email templates and update package dependencies #55
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanPenchev05 committed Mar 13, 2024
1 parent 28dc75c commit 0d9e9b9
Show file tree
Hide file tree
Showing 7 changed files with 9,995 additions and 4,291 deletions.
45 changes: 19 additions & 26 deletions server/controllers/auth/registerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { v4 as uuidv4 } from "uuid"

import setTempMemory from "../../utils/mongoTempMemoryService.js"
import sendMail from "../../utils/emailService.js";
import { generateTemplate } from "../../utils/emailTemplateManager.js";

import { User } from "../../models/User.js";
import { Validator } from "../../utils/validator.js";
Expand Down Expand Up @@ -91,32 +90,26 @@ export default async function registerController(req, res) {
const uuid = uuidv4();
const verificationToken = jwt.sign({uuid}, process.env.JWT_SECRET, { expiresIn: '15m' });

const emailTemplate = await generateTemplate("verifyRegisterUser", {verificationToken, username})

console.log(emailTemplate);

sendMail(email, "User Verification", emailTemplate);

// Temporarily store the user's data in Redis with a 15 minute expiry
// Then send a verification email to the user
// await setTempMemory(uuid, {
// ip,
// userAgent,
// browser,
// operatingSystem,
// deviceType,
// firstName,
// lastName,
// email,
// username,
// password: hashPassword
// }, 60 * 15).then(async() => {
// const emailTemplate = await generateTemplate("verifyRegisterUser", {verificationToken, username})

// sendMail(email, "User Verification", emailTemplate);
// }).catch(err => {
// throw err;
// });
await setTempMemory(uuid, {
ip,
userAgent,
browser,
operatingSystem,
deviceType,
firstName,
lastName,
email,
username,
password: hashPassword
}, 60 * 15).then(async() => {
const emailTemplate = "<h1>";

sendMail(email, "User Verification", emailTemplate);
}).catch(err => {
throw err;
});

// If everything is successful, return a 200 status code and a success message
// and tells the client to await for veriification sent via email
Expand All @@ -128,7 +121,7 @@ export default async function registerController(req, res) {

} catch (err) {
// If the username is already taken, suggest a new one by calling the generateUniqueUsername function
if (err.errors.username) {
if (err.errors && err.errors.username) {
const newUsername = await generateUniqueUsername(username);
return res
.status(401)
Expand Down
Loading

0 comments on commit 0d9e9b9

Please sign in to comment.