Skip to content

Commit 4ebd870

Browse files
authored
Merge pull request #178 from hackmcgill/bugfix/172-moreResetPasswordBugs
Finess the frontend address configurations
2 parents 895b796 + d728fa2 commit 4ebd870

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ PORT=<Some Port such as 3000>
33
#The address on which the server is being run:
44
ADDRESS=<Some address such as 127.0.0.1>
55

6+
#front-end server
7+
FRONTEND_ADDRESS_DEV=localhost:1337
8+
FRONTEND_ADDRESS_DEPLOY=app.mchacks.ca
9+
610
#The info for the deployment database
711
DB_ADDRESS_DEPLOY=<Deployment address>
812
DB_USER_DEPLOY=<username for db connection>

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ let corsOptions = {};
3636

3737
if (!Services.env.isProduction()) {
3838
corsOptions = {
39-
origin: ["http://localhost:1337", "http://localhost:8989"],
39+
origin: [process.env.FRONTEND_ADDRESS_DEV],
4040
credentials: true
4141
};
4242
} else {
4343
// TODO: change this when necessary
4444
corsOptions = {
45-
origin: ["https://mchacks.ca/"],
45+
origin: [process.env.FRONTEND_ADDRESS_DEPLOY],
4646
credentials: true
4747
};
4848
}

middlewares/account.middleware.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const Services = {
77
Logger: require("../services/logger.service"),
88
Account: require("../services/account.service"),
99
AccountConfirmation: require("../services/accountConfirmation.service"),
10-
Email: require("../services/email.service")
10+
Email: require("../services/email.service"),
11+
Env: require("../services/env.service")
1112
};
1213

1314
const Middleware = {
@@ -149,8 +150,9 @@ async function inviteAccount(req, res, next) {
149150
const accountType = req.body.accountType;
150151
const confirmationObj = await Services.AccountConfirmation.create(accountType, email);
151152
const confirmationToken = Services.AccountConfirmation.generateToken(confirmationObj.id);
153+
const address = Services.Env.isProduction() ? process.env.FRONTEND_ADDRESS_DEPLOY : process.env.FRONTEND_ADDRESS_DEV;
152154

153-
const mailData = Services.AccountConfirmation.generateAccountInvitationEmail(process.env.FRONTEND_ADDRESS, email, accountType, confirmationToken);
155+
const mailData = Services.AccountConfirmation.generateAccountInvitationEmail(address, email, accountType, confirmationToken);
154156
if (mailData !== undefined) {
155157
Services.Email.send(mailData, (err) => {
156158
if (err) {

middlewares/auth.middleware.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const Services = {
99
Email: require("../services/email.service"),
1010
AccountConfirmation: require("../services/accountConfirmation.service"),
1111
Role: require("../services/role.service"),
12-
RoleBinding: require("../services/roleBinding.service")
12+
RoleBinding: require("../services/roleBinding.service"),
13+
Env: require("../services/env.service")
1314
};
1415

1516
const Middleware = {
@@ -140,7 +141,8 @@ async function sendResetPasswordEmailMiddleware(req, res, next) {
140141
const ResetPasswordTokenModel = await Services.ResetPasswordToken.findByAccountId(user.id);
141142
//generate email
142143
const token = Services.ResetPasswordToken.generateToken(ResetPasswordTokenModel.id, user.id);
143-
const mailData = Services.ResetPasswordToken.generateResetPasswordEmail(process.env.FRONTEND_ADDRESS, req.body.email, token);
144+
const address = Services.Env.isProduction() ? process.env.FRONTEND_ADDRESS_DEPLOY : process.env.FRONTEND_ADDRESS_DEV;
145+
const mailData = Services.ResetPasswordToken.generateResetPasswordEmail(address, req.body.email, token);
144146
if (mailData !== undefined) {
145147
Services.Email.send(mailData, (err) => {
146148
if (err) {
@@ -176,7 +178,8 @@ async function sendConfirmAccountEmailMiddleware(req, res, next) {
176178
await Services.AccountConfirmation.create(Constants.General.HACKER, account.email, account.id);
177179
const accountConfirmationToken = await Services.AccountConfirmation.findByAccountId(account.id);
178180
const token = Services.AccountConfirmation.generateToken(accountConfirmationToken.id, account.id);
179-
const mailData = Services.AccountConfirmation.generateAccountConfirmationEmail(process.env.FRONTEND_ADDRESS, account.email, Constants.General.HACKER, token);
181+
const address = Services.Env.isProduction() ? process.env.FRONTEND_ADDRESS_DEPLOY : process.env.FRONTEND_ADDRESS_DEV;
182+
const mailData = Services.AccountConfirmation.generateAccountConfirmationEmail(address, account.email, Constants.General.HACKER, token);
180183
if (mailData !== undefined) {
181184
Services.Email.send(mailData, (err) => {
182185
if (err) {
@@ -214,7 +217,8 @@ async function resendConfirmAccountEmail(req, res, next) {
214217
});
215218
}
216219
const token = Services.AccountConfirmation.generateToken(accountConfirmationToken.id, account.id);
217-
const mailData = Services.AccountConfirmation.generateAccountConfirmationEmail(process.env.FRONTEND_ADDRESS, account.email, accountConfirmationToken.accountType, token);
220+
const address = Services.Env.isProduction() ? process.env.FRONTEND_ADDRESS_DEPLOY : process.env.FRONTEND_ADDRESS_DEV;
221+
const mailData = Services.AccountConfirmation.generateAccountConfirmationEmail(address, account.email, accountConfirmationToken.accountType, token);
218222
if (mailData !== undefined) {
219223
Services.Email.send(mailData, (err) => {
220224
if (err) {

0 commit comments

Comments
 (0)