Skip to content

Commit 09576d9

Browse files
committed
Merge branch 'dev'
Merge dev -> master | test & rebuild of new version of code. In this code changes, I've refactored a little bit of code and more importantly, I've tested the new version of accountCleanup.js, and fixed the sequelize bugs within index.js ( these happend when the sequelize import was removed ). Hope that was clear. Massiles.
2 parents aadaf51 + 20c3797 commit 09576d9

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/controllers/User/Account/signup.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ module.exports.signup = async (req, res) => {
5959
},
6060
)
6161
.then((data) => {
62-
62+
// generate token
6363
const id_token = sign({ id: data.id }, process.env.EMAIL_TOKEN, { expiresIn: "10 days", });
6464

65+
// build-up the email markup
66+
let emailData = fs.readFileSync(path.join(process.cwd(), "/res/emails/confirmEmail.html"), 'ascii');
67+
6568
emailData = emailData.replace('${data.username}', data.username);
6669
emailData = emailData.replace('${id_token}', id_token);
6770

6871
// send the email
6972
mailer(emailData, String(data.email), 'Confirm Your Email Address');
7073

71-
// send the email
72-
mailer(emailData, String(data.email), "Confirm Your Email Address")
73-
7474
res.json({
7575
token: sign(
7676
{

src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ require('dotenv').config();
22

33
// Configure Imports
44
const express = require('express');
5-
const sequelize = require("sequelize");
5+
const { Sequelize } = require('sequelize');
6+
const models = require('./models');
67
const schedule = require('node-schedule');
78
const { removeUnconfirmedAccounts, emailConfirmationRemainder } = require('./jobs/accountCleanup');
89

@@ -14,7 +15,7 @@ const port = process.env.PORT || 8080;
1415
app.use(express.static('public'));
1516
app.use(express.urlencoded({ extended: true }));
1617
app.use(express.json());
17-
app.use(require('cors')({ origin: 'https://fairfieldprogramming.org' }));
18+
app.use(require('cors')({ origin: '*' }));
1819

1920
// Programs
2021
app.get('/', require('./routes/index'));
@@ -36,15 +37,15 @@ app.use('/user', require('./routes/userRoutes'));
3637

3738
// Sync the Database
3839
(async () => {
40+
3941
// await the database creation process, so as we can access the data on our jobs
4042
await sequelize.sync();
4143
app.emit('database-started');
4244

4345
// this will run the job at the 10th day of each month at 08:00;
4446
schedule.scheduleJob(
4547
"remind users to confirm their email address",
46-
"30 * * * * *",
47-
// "0 8 10 * *",
48+
"0 8 10 * *",
4849
() => {
4950
emailConfirmationRemainder();
5051
},

src/jobs/accountCleanup.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
const fs = require('fs');
2+
const { sign } = require('jsonwebtoken');
3+
const path = require('path');
4+
const { mailer } = require('../helpers/mailer');
5+
6+
17
const {
28
MAX_UNCONFIRMED_ACCOUNT_AGE,
39
EMAIL_CONFIRMATION_REMAINDER_TIMEOUT,
@@ -6,6 +12,7 @@ const {
612

713

814

15+
916
/**
1017
* @module Remove User Accounts With Unconfirmed Email Addresses
1118
*
@@ -62,7 +69,7 @@ module.exports.emailConfirmationRemainder = async () => {
6269

6370
// find and retreive all the users with an unconfirmed email address
6471

65-
const accounts = await User.findAll(
72+
let accounts = await User.findAll(
6673
{
6774
where:
6875
{
@@ -76,22 +83,14 @@ module.exports.emailConfirmationRemainder = async () => {
7683
return;
7784
}
7885

79-
console.log("before the filter", accounts);
8086
accounts = accounts.filter(account => Date.parse(account.createdAt) < Date.now() - EMAIL_CONFIRMATION_REMAINDER_TIMEOUT);
81-
console.log("after the filter", accounts);
82-
83-
const accountInfo = accounts.map(account => { account.id, account.username, account.email });
84-
85-
console.log("after the map", accounts);
8687

88+
accounts.forEach((element) => {
8789

88-
89-
90-
accountInfo.forEach((element) => {
91-
90+
// generate a new token
9291
const id_token = sign({ id: element.id }, process.env.EMAIL_TOKEN, { expiresIn: "10 days", });
9392

94-
93+
// build-up the mail markup
9594
let emailData = fs.readFileSync(path.join(process.cwd(), "/res/emails/confirmEmail.html"), 'ascii');
9695

9796
emailData = emailData.replace("${data.username}", element.username);

0 commit comments

Comments
 (0)