Skip to content

Commit 26b15da

Browse files
committed
Merge branch 'develop' into bug/162
2 parents d23855f + 3815f2d commit 26b15da

40 files changed

Lines changed: 1611 additions & 454 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ node_modules
6060

6161
#creds
6262
gcp_creds.json
63+
64+
#certbot
65+
certbot/

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@
163163
"${workspaceFolder}/tests/email.service.spec.js"
164164
],
165165
"internalConsoleOptions": "openOnSessionStart"
166+
},
167+
{
168+
"type": "node",
169+
"request": "launch",
170+
"name": "Mocha Tests - Auth",
171+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
172+
"args": [
173+
"-u",
174+
"tdd",
175+
"--timeout",
176+
"999999",
177+
"--colors",
178+
"${workspaceFolder}/tests/setup.spec.js",
179+
"${workspaceFolder}/tests/auth.test.js"
180+
],
181+
"internalConsoleOptions": "openOnSessionStart"
166182
}
167183
]
168184
}

apidoc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"defaultVersion": "0.0.8",
55
"description": "Documentation for the API used for mchacks",
66
"title": "hackerAPI documentation",
7-
"url": "https://mchacks.ca/api",
8-
"sampleUrl": "https://mchacks.ca/api"
7+
"url": "https://api.mchacks.ca/api",
8+
"sampleUrl": "https://api.mchacks.ca/api"
99
}

app.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ const volunteerRouter = require("./routes/api/volunteer");
3131

3232
const app = express();
3333
Services.db.connect(app);
34-
app.use(cors());
34+
35+
let corsOptions = {};
36+
37+
if (!Services.env.isProduction()) {
38+
corsOptions = { origin: ["http://localhost:1337", "http://localhost:8989"], credentials: true };
39+
} else {
40+
// TODO: change this when necessary
41+
corsOptions = { origin: ["https://mchacks.ca/"], credentials: true };
42+
}
43+
44+
app.use(cors(corsOptions));
3545
app.use(Services.log.requestLogger);
3646
app.use(Services.log.errorLogger);
3747
app.use(express.json());

assets/email/AccountInvitation.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<b>
2+
Create Your Account:
3+
<a href="{{link}}">here</a>
4+
</b>

constants/error.constant.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const SPONSOR_ID_409_MESSAGE = "Conflict with sponsor accountId link";
1111
const VOLUNTEER_ID_409_MESSAGE = "Conflict with volunteer accountId link";
1212
const HACKER_ID_409_MESSAGE = "Conflict with hacker accountId link";
1313
const TEAM_MEMBER_409_MESSAGE = "Conflict with team member being in another team";
14-
const HACKER_CHECKIN_409_MESSAGE = "Cannot check-in non-confirmed hacker";
14+
const HACKER_STATUS_409_MESSAGE = "Conflict with hacker status";
1515

1616
const TEAM_MEMBER_422_MESSAGE = "Duplicate team member in input";
1717
const VALIDATION_422_MESSAGE = "Validation failed";
@@ -60,5 +60,5 @@ module.exports = {
6060
GENERIC_500_MESSAGE: GENERIC_500_MESSAGE,
6161
ACCOUNT_DUPLICATE_422_MESSAGE: ACCOUNT_DUPLICATE_422_MESSAGE,
6262
LOGIN_500_MESSAGE: LOGIN_500_MESSAGE,
63-
HACKER_CHECKIN_409_MESSAGE: HACKER_CHECKIN_409_MESSAGE,
63+
HACKER_STATUS_409_MESSAGE: HACKER_STATUS_409_MESSAGE,
6464
};

constants/general.constant.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ EMAIL_SUBJECTS[HACKER_STATUS_CONFIRMED] = `Thanks for confirming your attendance
7373
EMAIL_SUBJECTS[HACKER_STATUS_CANCELLED] = "Sorry to see you go";
7474
EMAIL_SUBJECTS[HACKER_STATUS_CHECKED_IN] = `Welcome to ${HACKATHON_NAME}`;
7575

76-
const CONFIRM_ACC_EMAIL_SUBJECTS = {};
77-
CONFIRM_ACC_EMAIL_SUBJECTS[HACKER] = `Please complete your hacker application for ${HACKATHON_NAME}`;
78-
CONFIRM_ACC_EMAIL_SUBJECTS[SPONSOR] = `You've been invited to create a sponsor account for ${HACKATHON_NAME}`;
79-
CONFIRM_ACC_EMAIL_SUBJECTS[VOLUNTEER] = `You've been invited to create a volunteer account for ${HACKATHON_NAME}`;
80-
CONFIRM_ACC_EMAIL_SUBJECTS[STAFF] = `You've been invited to create a staff account for ${HACKATHON_NAME}`;
76+
const CONFIRM_ACC_EMAIL_SUBJECT = `Please complete your hacker application for ${HACKATHON_NAME}`;
77+
const CREATE_ACC_EMAIL_SUBJECTS = {};
78+
CREATE_ACC_EMAIL_SUBJECTS[HACKER] = `You've been invited to create a hacker account for ${HACKATHON_NAME}`;
79+
CREATE_ACC_EMAIL_SUBJECTS[SPONSOR] = `You've been invited to create a sponsor account for ${HACKATHON_NAME}`;
80+
CREATE_ACC_EMAIL_SUBJECTS[VOLUNTEER] = `You've been invited to create a volunteer account for ${HACKATHON_NAME}`;
81+
CREATE_ACC_EMAIL_SUBJECTS[STAFF] = `You've been invited to create a staff account for ${HACKATHON_NAME}`;
8182

8283
module.exports = {
8384
HACKATHON_NAME: HACKATHON_NAME,
@@ -99,7 +100,8 @@ module.exports = {
99100
EXTENDED_USER_TYPES: EXTENDED_USER_TYPES,
100101
URL_REGEX: URL_REGEX,
101102
EMAIL_SUBJECTS: EMAIL_SUBJECTS,
102-
CONFIRM_ACC_EMAIL_SUBJECTS: CONFIRM_ACC_EMAIL_SUBJECTS,
103+
CREATE_ACC_EMAIL_SUBJECTS: CREATE_ACC_EMAIL_SUBJECTS,
104+
CONFIRM_ACC_EMAIL_SUBJECT: CONFIRM_ACC_EMAIL_SUBJECT,
103105
HACKER: HACKER,
104106
SPONSOR: SPONSOR,
105107
VOLUNTEER: VOLUNTEER,

constants/role.constant.js

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ const Constants = {
44
Routes: require("./routes.constant"),
55
};
66
const mongoose = require("mongoose");
7-
const Role = require("../models/role.model");
7+
8+
const accountRole = {
9+
"_id": mongoose.Types.ObjectId(),
10+
"name": "account",
11+
"routes": [
12+
Constants.Routes.authRoutes.login,
13+
Constants.Routes.authRoutes.logout,
14+
Constants.Routes.authRoutes.getSelfRoleBindindings,
15+
Constants.Routes.accountRoutes.getSelf,
16+
Constants.Routes.accountRoutes.getSelfById,
17+
Constants.Routes.accountRoutes.patchSelfById
18+
]
19+
};
820

921
const adminRole = {
1022
"_id": mongoose.Types.ObjectId(),
@@ -16,10 +28,6 @@ const hackerRole = {
1628
"_id": mongoose.Types.ObjectId(),
1729
"name": Constants.General.HACKER,
1830
"routes": [
19-
Constants.Routes.authRoutes.login,
20-
Constants.Routes.authRoutes.logout,
21-
Constants.Routes.authRoutes.getSelfRoleBindindings,
22-
2331
Constants.Routes.accountRoutes.getSelf,
2432
Constants.Routes.accountRoutes.getSelfById,
2533
Constants.Routes.accountRoutes.patchSelfById,
@@ -28,17 +36,14 @@ const hackerRole = {
2836
Constants.Routes.hackerRoutes.getSelfById,
2937
Constants.Routes.hackerRoutes.getSelfResumeById,
3038
Constants.Routes.hackerRoutes.patchSelfById,
39+
Constants.Routes.hackerRoutes.patchSelfConfirmationById
3140
]
3241
};
3342

3443
const volunteerRole = {
3544
"_id": mongoose.Types.ObjectId(),
3645
"name": Constants.General.VOLUNTEER,
3746
"routes": [
38-
Constants.Routes.authRoutes.login,
39-
Constants.Routes.authRoutes.logout,
40-
Constants.Routes.authRoutes.getSelfRoleBindindings,
41-
4247
Constants.Routes.volunteerRoutes.post,
4348

4449
Constants.Routes.hackerRoutes.patchAnyCheckInById,
@@ -50,10 +55,6 @@ const sponsorT1Role = {
5055
"_id": mongoose.Types.ObjectId(),
5156
"name": Constants.General.SPONSOR_T1,
5257
"routes": [
53-
Constants.Routes.authRoutes.login,
54-
Constants.Routes.authRoutes.logout,
55-
Constants.Routes.authRoutes.getSelfRoleBindindings,
56-
5758
Constants.Routes.sponsorRoutes.post,
5859
Constants.Routes.sponsorRoutes.getSelfById,
5960
]
@@ -63,10 +64,6 @@ const sponsorT2Role = {
6364
"_id": mongoose.Types.ObjectId(),
6465
"name": Constants.General.SPONSOR_T2,
6566
"routes": [
66-
Constants.Routes.authRoutes.login,
67-
Constants.Routes.authRoutes.logout,
68-
Constants.Routes.authRoutes.getSelfRoleBindindings,
69-
7067
Constants.Routes.sponsorRoutes.post,
7168
Constants.Routes.sponsorRoutes.getSelfById,
7269
]
@@ -76,10 +73,6 @@ const sponsorT3Role = {
7673
"_id": mongoose.Types.ObjectId(),
7774
"name": Constants.General.SPONSOR_T3,
7875
"routes": [
79-
Constants.Routes.authRoutes.login,
80-
Constants.Routes.authRoutes.logout,
81-
Constants.Routes.authRoutes.getSelfRoleBindindings,
82-
8376
Constants.Routes.sponsorRoutes.post,
8477
Constants.Routes.sponsorRoutes.getSelfById,
8578
]
@@ -89,10 +82,6 @@ const sponsorT4Role = {
8982
"_id": mongoose.Types.ObjectId(),
9083
"name": Constants.General.SPONSOR_T4,
9184
"routes": [
92-
Constants.Routes.authRoutes.login,
93-
Constants.Routes.authRoutes.logout,
94-
Constants.Routes.authRoutes.getSelfRoleBindindings,
95-
9685
Constants.Routes.sponsorRoutes.post,
9786
Constants.Routes.sponsorRoutes.getSelfById,
9887
]
@@ -102,10 +91,6 @@ const sponsorT5Role = {
10291
"_id": mongoose.Types.ObjectId(),
10392
"name": Constants.General.SPONSOR_T5,
10493
"routes": [
105-
Constants.Routes.authRoutes.login,
106-
Constants.Routes.authRoutes.logout,
107-
Constants.Routes.authRoutes.getSelfRoleBindindings,
108-
10994
Constants.Routes.sponsorRoutes.post,
11095
Constants.Routes.sponsorRoutes.getSelfById,
11196
]
@@ -154,14 +139,15 @@ function createAllSingularRoles() {
154139
*/
155140
function createAllRoles() {
156141
let allRolesObject = {
142+
accountRole: accountRole,
157143
adminRole: adminRole,
158144
hackerRole: hackerRole,
159145
volunteerRole: volunteerRole,
160146
sponsorT1Role: sponsorT1Role,
161147
sponsorT2Role: sponsorT2Role,
162148
sponsorT3Role: sponsorT3Role,
163149
sponsorT4Role: sponsorT4Role,
164-
sponsorT5Role: sponsorT5Role
150+
sponsorT5Role: sponsorT5Role,
165151
};
166152

167153
const singularRoles = createAllSingularRoles();
@@ -176,6 +162,7 @@ function createAllRoles() {
176162
}
177163

178164
module.exports = {
165+
accountRole: accountRole,
179166
adminRole: adminRole,
180167
hackerRole: hackerRole,
181168
volunteerRole: volunteerRole,

constants/routes.constant.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ const accountRoutes = {
4949
requestType: Constants.REQUEST_TYPES.PATCH,
5050
uri: "/api/account/" + Constants.ROLE_CATEGORIES.ALL,
5151
},
52-
"patchSelfConfirmationById": {
53-
requestType: Constants.REQUEST_TYPES.PATCH,
54-
uri: "/api/account/confirmation/" + Constants.ROLE_CATEGORIES.SELF,
55-
},
56-
"patchAnyConfirmationById": {
57-
requestType: Constants.REQUEST_TYPES.PATCH,
58-
uri: "/api/account/confirmation/" + Constants.ROLE_CATEGORIES.ALL,
52+
"inviteAccount": {
53+
requestType: Constants.REQUEST_TYPES.POST,
54+
uri: "/api/account/invite"
5955
}
6056
};
6157

@@ -112,6 +108,10 @@ const hackerRoutes = {
112108
requestType: Constants.REQUEST_TYPES.PATCH,
113109
uri: "/api/hacker/checkin/" + Constants.ROLE_CATEGORIES.ALL,
114110
},
111+
"patchSelfConfirmationById": {
112+
requestType: Constants.REQUEST_TYPES.PATCH,
113+
uri: "/api/hacker/confirmation/" + Constants.ROLE_CATEGORIES.SELF,
114+
},
115115
};
116116

117117
const sponsorRoutes = {

controllers/account.controller.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ async function getUserById(req, res) {
6767
* @description Adds a user from information in req.body.accountDetails
6868
*/
6969
async function addUser(req, res) {
70-
const accountDetails = req.body.accountDetails;
71-
delete accountDetails.password;
70+
const acc = req.body.account;
7271
return res.status(200).json({
7372
message: "Account creation successful",
74-
data: accountDetails
73+
data: acc.toStrippedJSON()
7574
});
7675
}
7776

@@ -93,12 +92,20 @@ function updatedAccount(req, res) {
9392
});
9493
}
9594

95+
function invitedAccount(req, res) {
96+
return res.status(200).json({
97+
message: "Successfully invited user",
98+
data: {}
99+
});
100+
}
101+
102+
96103
module.exports = {
97104
getUserByEmail: Util.asyncMiddleware(getUserByEmail),
98105
getUserById: Util.asyncMiddleware(getUserById),
99106

100107
// assumes all information in req.body
101108
addUser: Util.asyncMiddleware(addUser),
102-
103109
updatedAccount: updatedAccount,
110+
invitedAccount: invitedAccount
104111
};

0 commit comments

Comments
 (0)