Skip to content

Commit 6621af9

Browse files
authored
Merge pull request #170 from hackmcgill/develop
Develop
2 parents 71fa9ef + 543fc59 commit 6621af9

31 files changed

Lines changed: 816 additions & 224 deletions

.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ NO_REPLY_EMAIL=<email that you dont want people emailing>
3737
#Storage information
3838
BUCKET_NAME=<bucket name>
3939

40-
#Hackathon name
41-
HACKATHON=mchacks
42-
4340
#Service account information (This is found in the json when you create a service account).
4441
TYPE=service_account
4542
PROJECT_ID=<project id>

.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
}

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/general.constant.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
const HACKATHON_NAME = "McHacks";
4+
35
// constants kept in alphabetical order
46
// matches optional http://, https://, http:, https:, and optional www., and then matches for devpost.com and further parameters
57
const DEVPOST_REGEX = /^(http(s)?:(\/\/)?)?(www\.)?(([-a-zA-Z0-9@:%._\+~#=]{2,256}\.)?devpost\.com)\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;
@@ -63,21 +65,23 @@ const EXTENDED_USER_TYPES = [HACKER, VOLUNTEER, STAFF, SPONSOR_T1, SPONSOR_T2, S
6365
const URL_REGEX = /^(http(s)?:(\/\/)?)?(www\.)?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;
6466

6567
const EMAIL_SUBJECTS = {};
66-
EMAIL_SUBJECTS[HACKER_STATUS_NONE] = `Application for ${process.env.HACKATHON} incomplete`;
67-
EMAIL_SUBJECTS[HACKER_STATUS_APPLIED] = `Thanks for applying to ${process.env.HACKATHON}`;
68-
EMAIL_SUBJECTS[HACKER_STATUS_ACCEPTED] = `Great update from ${process.env.HACKATHON}`;
69-
EMAIL_SUBJECTS[HACKER_STATUS_WAITLISTED] = `Update from ${process.env.HACKATHON}`;
70-
EMAIL_SUBJECTS[HACKER_STATUS_CONFIRMED] = `Thanks for confirming your attendance to ${process.env.HACKATHON}`;
68+
EMAIL_SUBJECTS[HACKER_STATUS_NONE] = `Application for ${HACKATHON_NAME} incomplete`;
69+
EMAIL_SUBJECTS[HACKER_STATUS_APPLIED] = `Thanks for applying to ${HACKATHON_NAME}`;
70+
EMAIL_SUBJECTS[HACKER_STATUS_ACCEPTED] = `Great update from ${HACKATHON_NAME}`;
71+
EMAIL_SUBJECTS[HACKER_STATUS_WAITLISTED] = `Update from ${HACKATHON_NAME}`;
72+
EMAIL_SUBJECTS[HACKER_STATUS_CONFIRMED] = `Thanks for confirming your attendance to ${HACKATHON_NAME}`;
7173
EMAIL_SUBJECTS[HACKER_STATUS_CANCELLED] = "Sorry to see you go";
72-
EMAIL_SUBJECTS[HACKER_STATUS_CHECKED_IN] = `Welcome to ${process.env.HACKATHON}`;
74+
EMAIL_SUBJECTS[HACKER_STATUS_CHECKED_IN] = `Welcome to ${HACKATHON_NAME}`;
7375

74-
const CONFIRM_ACC_EMAIL_SUBJECTS = {};
75-
CONFIRM_ACC_EMAIL_SUBJECTS[HACKER] = `Please complete your hacker application for ${process.env.HACKATHON}`;
76-
CONFIRM_ACC_EMAIL_SUBJECTS[SPONSOR] = `You've been invited to create a sponsor account for ${process.env.HACKATHON}`;
77-
CONFIRM_ACC_EMAIL_SUBJECTS[VOLUNTEER] = `You've been invited to create a volunteer account for ${process.env.HACKATHON}`;
78-
CONFIRM_ACC_EMAIL_SUBJECTS[STAFF] = `You've been invited to create a staff account for ${process.env.HACKATHON}`;
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}`;
7982

8083
module.exports = {
84+
HACKATHON_NAME: HACKATHON_NAME,
8185
DEVPOST_REGEX: DEVPOST_REGEX,
8286
EMAIL_REGEX: EMAIL_REGEX,
8387
HACKER_STATUS_NONE: HACKER_STATUS_NONE,
@@ -96,7 +100,8 @@ module.exports = {
96100
EXTENDED_USER_TYPES: EXTENDED_USER_TYPES,
97101
URL_REGEX: URL_REGEX,
98102
EMAIL_SUBJECTS: EMAIL_SUBJECTS,
99-
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,
100105
HACKER: HACKER,
101106
SPONSOR: SPONSOR,
102107
VOLUNTEER: VOLUNTEER,

constants/routes.constant.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const accountRoutes = {
4848
"patchAnyById": {
4949
requestType: Constants.REQUEST_TYPES.PATCH,
5050
uri: "/api/account/" + Constants.ROLE_CATEGORIES.ALL,
51+
},
52+
"inviteAccount": {
53+
requestType: Constants.REQUEST_TYPES.POST,
54+
uri: "/api/account/invite"
5155
}
5256
};
5357

controllers/account.controller.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ async function updateAccount(req, res) {
105105
}
106106
}
107107

108+
function invitedAccount(req, res){
109+
return res.status(200).json({
110+
message: "Successfully invited user",
111+
data: {}
112+
})
113+
}
114+
115+
108116
module.exports = {
109117
getUserByEmail: Util.asyncMiddleware(getUserByEmail),
110118
getUserById: Util.asyncMiddleware(getUserById),
@@ -113,4 +121,5 @@ module.exports = {
113121
addUser: Util.asyncMiddleware(addUser),
114122

115123
updateAccount: Util.asyncMiddleware(updateAccount),
124+
invitedAccount: invitedAccount
116125
};

controllers/auth.controller.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ module.exports = {
4343
message: "Successfully resent account email",
4444
data: {}
4545
})
46+
},
47+
retrievedRoles: function(req, res) {
48+
return res.status(200).json({
49+
message: "Successfully retrieved all roles",
50+
data: req.roles
51+
})
4652
}
4753
};

controllers/hacker.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ async function findById(req, res) {
4242
*/
4343
async function createHacker(req, res) {
4444
const hackerDetails = req.body.hackerDetails;
45-
4645
const success = await Services.Hacker.createHacker(hackerDetails);
47-
46+
hackerDetails.id = hackerDetails._id;
47+
delete hackerDetails._id;
4848
if (success) {
4949
return res.status(200).json({
5050
message: "Hacker creation successful",
5151
data: hackerDetails
5252
});
5353
} else {
54-
return res.status(400).json({
54+
return res.status(500).json({
5555
message: Constants.Error.HACKER_CREATE_500_MESSAGE,
5656
data: {}
5757
});

docs/api/api_data.js

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ define({
2222
"field": "lastName",
2323
"description": "<p>Last name of the account creator.</p>"
2424
},
25+
{
26+
"group": "body",
27+
"type": "String",
28+
"optional": false,
29+
"field": "pronoun",
30+
"description": "<p>the pronoun of the account creator.</p>"
31+
},
2532
{
2633
"group": "body",
2734
"type": "String",
@@ -47,8 +54,22 @@ define({
4754
"group": "body",
4855
"type": "String",
4956
"optional": false,
50-
"field": "passowrd",
57+
"field": "password",
5158
"description": "<p>The password of the account.</p>"
59+
},
60+
{
61+
"group": "body",
62+
"type": "String",
63+
"optional": false,
64+
"field": "birthDate",
65+
"description": "<p>a Date parsable string.</p>"
66+
},
67+
{
68+
"group": "body",
69+
"type": "Number",
70+
"optional": false,
71+
"field": "phoneNumber",
72+
"description": "<p>the user's phone number, represented as a string.</p>"
5273
}
5374
]
5475
}
@@ -263,6 +284,13 @@ define({
263284
"field": "lastName",
264285
"description": "<p>Last name of the account creator.</p>"
265286
},
287+
{
288+
"group": "body",
289+
"type": "String",
290+
"optional": true,
291+
"field": "pronoun",
292+
"description": "<p>the pronoun of the account creator.</p>"
293+
},
266294
{
267295
"group": "body",
268296
"type": "String",
@@ -290,6 +318,20 @@ define({
290318
"optional": true,
291319
"field": "passowrd",
292320
"description": "<p>The password of the account.</p>"
321+
},
322+
{
323+
"group": "body",
324+
"type": "String",
325+
"optional": true,
326+
"field": "birthDate",
327+
"description": "<p>a Date parsable string.</p>"
328+
},
329+
{
330+
"group": "body",
331+
"type": "Number",
332+
"optional": true,
333+
"field": "phoneNumber",
334+
"description": "<p>the user's phone number, represented as a string.</p>"
293335
}
294336
]
295337
}
@@ -476,6 +518,44 @@ define({
476518
"url": "https://mchacks.ca/api/auth/password/forgot"
477519
}]
478520
},
521+
{
522+
"type": "get",
523+
"url": "/auth/roles",
524+
"title": "get roles",
525+
"name": "getRoles",
526+
"description": "<p>get all roles that exist in the database</p>",
527+
"group": "Authentication",
528+
"version": "0.0.8",
529+
"success": {
530+
"fields": {
531+
"Success 200": [{
532+
"group": "Success 200",
533+
"type": "string",
534+
"optional": false,
535+
"field": "message",
536+
"description": "<p>Success message</p>"
537+
},
538+
{
539+
"group": "Success 200",
540+
"type": "object",
541+
"optional": false,
542+
"field": "data",
543+
"description": "<p>empty</p>"
544+
}
545+
]
546+
},
547+
"examples": [{
548+
"title": "Success-Response:",
549+
"content": "{\"message\": \"Sucessfully retrieved all roles\", \"data\":\n[{name: \"GodStaff\", routes: Array(27), id: \"5bee20ef3ca9dd4754382880\"},\n {name: \"Hacker\", routes: Array(10), id: \"5bee20ef3ca9dd4754382881\"},\n {name: \"Volunteer\", routes: Array(4), id: \"5bee20ef3ca9dd4754382882\"}]",
550+
"type": "json"
551+
}]
552+
},
553+
"filename": "routes/api/auth.js",
554+
"groupTitle": "Authentication",
555+
"sampleRequest": [{
556+
"url": "https://mchacks.ca/api/auth/roles"
557+
}]
558+
},
479559
{
480560
"type": "post",
481561
"url": "/auth/login",
@@ -847,6 +927,34 @@ define({
847927
"field": "needsBus",
848928
"description": "<p>Whether the hacker requires a bus for transportation</p>"
849929
},
930+
{
931+
"group": "body",
932+
"type": "String[]",
933+
"optional": false,
934+
"field": "ethnicity",
935+
"description": "<p>the ethnicities of the hacker</p>"
936+
},
937+
{
938+
"group": "body",
939+
"type": "String",
940+
"optional": false,
941+
"field": "major",
942+
"description": "<p>the major of the hacker</p>"
943+
},
944+
{
945+
"group": "body",
946+
"type": "Number",
947+
"optional": false,
948+
"field": "graduationYear",
949+
"description": "<p>the graduation year of the hacker</p>"
950+
},
951+
{
952+
"group": "body",
953+
"type": "Boolean",
954+
"optional": false,
955+
"field": "codeOfConduct",
956+
"description": "<p>acceptance of the code of conduct</p>"
957+
},
850958
{
851959
"group": "body",
852960
"type": "Json",

0 commit comments

Comments
 (0)