Skip to content

Commit 605f782

Browse files
authored
fix: account invites with correct acc types (#920)
1 parent 82423ce commit 605f782

12 files changed

+264
-153
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<mjml>
2+
<mj-head>
3+
<mj-title>We've got your application!</mj-title>
4+
<mj-font name="Hind" href="http://fonts.googleapis.com/css?family=Hind:400" />
5+
</mj-head>
6+
<mj-body background-color="#F9F9F9">
7+
<mj-include path="assets/email/Header.mjml" />
8+
<!-- START BODY -->
9+
<mj-section background-color="#FFFFFF" border="5px solid #E9E9E9">
10+
<mj-column>
11+
<mj-spacer />
12+
<mj-text font-family="Hind" line-height="150%" font-size="14px" color="#4D4D4D">
13+
Hey there! 👋
14+
</mj-text>
15+
16+
<mj-text font-family="Hind" line-height="150%" font-size="14px" color="#4D4D4D">
17+
You've been invited to create an account on our <a href="https://app.mchacks.ca/"
18+
style="-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;color:#F2463A;text-decoration:none;">sponsor
19+
dashboard</a>. On the sponsor dashboard you can find important
20+
information about check-in, mentoring, judging, workshops, Discord, and
21+
the schedule for the weekend. On the sponsor dashboard you will be able
22+
to look up hacker applications and information. Additionally, if you
23+
have resume access you will be able to download hacker resumes through
24+
the dashboard.
25+
</mj-text>
26+
27+
<mj-text font-family="Hind" line-height="150%" font-size="14px" color="#4D4D4D">
28+
Sponsor check-in starts at 6:00 pm on Saturday, January 28th on the
29+
McHacks Discord server and opening ceremonies will begin at 7:00 pm. Be
30+
sure to get set up on the McHacks Discord server at <a
31+
href="https://discord.gg/XVSdW9pc"
32+
style="-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;color:#F2463A;text-decoration:none;">https://discord.gg/XVSdW9pc</a>
33+
and contact your coordinator to set up your server roles.
34+
</mj-text>
35+
36+
<mj-text font-family="Hind" line-height="150%" font-size="14px" color="#4D4D4D">
37+
Get access to the sponsor dashboard by clicking on the button below.
38+
</mj-text>
39+
40+
<mj-spacer />
41+
<mj-button href="{{{ link }}}" font-family="Hind" background-color="#F2463A" color="white" border-radius="40px">
42+
Create your account
43+
</mj-button>
44+
<mj-spacer />
45+
46+
<mj-text font-family="Hind" line-height="150%" font-size="14px" color="#4D4D4D">
47+
If you have any questions, feel free to reach out to your coordinator.
48+
</mj-text>
49+
50+
<mj-text font-family="Hind" line-height="150%" font-size="14px" color="#4D4D4D">
51+
McHacks Team
52+
<br />
53+
<a href="https://mchacks.ca" style="color: #F2463A; text-decoration: none;">mchacks.ca</a>
54+
</mj-text>
55+
</mj-column>
56+
</mj-section>
57+
<!-- END BODY -->
58+
<mj-include path="assets/email/Footer.mjml" />
59+
</mj-body>
60+
</mjml>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export enum AuthorizationLevel {
2-
Staff = "Staff",
3-
Sponsor = "Sponsor",
4-
Volunteer = "Volunteer",
5-
Hacker = "Hacker",
6-
Account = "Account",
7-
None = "None",
2+
Staff = "Staff",
3+
Sponsor = "Sponsor",
4+
Volunteer = "Volunteer",
5+
Hacker = "Hacker",
6+
Account = "Account",
7+
None = "None"
88
}

src/constants/error.constant.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const SPONSOR_ID_409_MESSAGE = "Conflict with sponsor accountId link";
1313
const VOLUNTEER_ID_409_MESSAGE = "Conflict with volunteer accountId link";
1414
const HACKER_ID_409_MESSAGE = "Conflict with hacker accountId link";
1515
const TEAM_MEMBER_409_MESSAGE =
16-
"Conflict with team member being in another team";
16+
"Conflict with team member being in another team";
1717
const TEAM_NAME_409_MESSAGE = "Conflict with team name already in use";
1818
const HACKER_STATUS_409_MESSAGE = "Conflict with hacker status";
1919
const TEAM_SIZE_409_MESSAGE = "Team full";
@@ -24,7 +24,7 @@ const VALIDATION_422_MESSAGE = "Validation failed";
2424
const ACCOUNT_DUPLICATE_422_MESSAGE = "Account already exists";
2525
const ROLE_DUPLICATE_422_MESSAGE = "Role already exists";
2626
const SETTINGS_422_MESSAGE =
27-
"openTime must be before closeTime, and closeTime must be before confirmTime";
27+
"openTime must be before closeTime, and closeTime must be before confirmTime";
2828

2929
const ACCOUNT_TOKEN_401_MESSAGE = "Invalid token for account";
3030
const AUTH_401_MESSAGE = "Invalid Authentication";
@@ -49,46 +49,46 @@ const ROLE_CREATE_500_MESSAGE = "Error while creating role";
4949
const TRAVEL_CREATE_500_MESSAGE = "Error while creating travel";
5050

5151
export {
52-
ACCOUNT_404_MESSAGE,
53-
HACKER_404_MESSAGE,
54-
TEAM_404_MESSAGE,
55-
RESUME_404_MESSAGE,
56-
ACCOUNT_TYPE_409_MESSAGE,
57-
ACCOUNT_EMAIL_409_MESSAGE,
58-
SPONSOR_ID_409_MESSAGE,
59-
VOLUNTEER_ID_409_MESSAGE,
60-
TEAM_MEMBER_409_MESSAGE,
61-
TEAM_MEMBER_422_MESSAGE,
62-
VALIDATION_422_MESSAGE,
63-
ACCOUNT_TOKEN_401_MESSAGE,
64-
AUTH_401_MESSAGE,
65-
AUTH_403_MESSAGE,
66-
ACCOUNT_403_MESSAGE,
67-
TEAM_UPDATE_500_MESSAGE,
68-
HACKER_UPDATE_500_MESSAGE,
69-
HACKER_ID_409_MESSAGE,
70-
ACCOUNT_UPDATE_500_MESSAGE,
71-
HACKER_CREATE_500_MESSAGE,
72-
SPONSOR_404_MESSAGE,
73-
SPONSOR_CREATE_500_MESSAGE,
74-
TEAM_CREATE_500_MESSAGE,
75-
VOLUNTEER_CREATE_500_MESSAGE,
76-
EMAIL_500_MESSAGE,
77-
GENERIC_500_MESSAGE,
78-
ACCOUNT_DUPLICATE_422_MESSAGE,
79-
LOGIN_500_MESSAGE,
80-
HACKER_STATUS_409_MESSAGE,
81-
TEAM_SIZE_409_MESSAGE,
82-
ROLE_DUPLICATE_422_MESSAGE,
83-
SETTINGS_422_MESSAGE,
84-
ROLE_CREATE_500_MESSAGE,
85-
TEAM_NAME_409_MESSAGE,
86-
TEAM_JOIN_SAME_409_MESSAGE,
87-
TEAM_READ_500_MESSAGE,
88-
VOLUNTEER_404_MESSAGE,
89-
SPONSOR_UPDATE_500_MESSAGE,
90-
SETTINGS_404_MESSAGE,
91-
SETTINGS_403_MESSAGE,
92-
TRAVEL_404_MESSAGE,
93-
TRAVEL_CREATE_500_MESSAGE,
52+
ACCOUNT_404_MESSAGE,
53+
HACKER_404_MESSAGE,
54+
TEAM_404_MESSAGE,
55+
RESUME_404_MESSAGE,
56+
ACCOUNT_TYPE_409_MESSAGE,
57+
ACCOUNT_EMAIL_409_MESSAGE,
58+
SPONSOR_ID_409_MESSAGE,
59+
VOLUNTEER_ID_409_MESSAGE,
60+
TEAM_MEMBER_409_MESSAGE,
61+
TEAM_MEMBER_422_MESSAGE,
62+
VALIDATION_422_MESSAGE,
63+
ACCOUNT_TOKEN_401_MESSAGE,
64+
AUTH_401_MESSAGE,
65+
AUTH_403_MESSAGE,
66+
ACCOUNT_403_MESSAGE,
67+
TEAM_UPDATE_500_MESSAGE,
68+
HACKER_UPDATE_500_MESSAGE,
69+
HACKER_ID_409_MESSAGE,
70+
ACCOUNT_UPDATE_500_MESSAGE,
71+
HACKER_CREATE_500_MESSAGE,
72+
SPONSOR_404_MESSAGE,
73+
SPONSOR_CREATE_500_MESSAGE,
74+
TEAM_CREATE_500_MESSAGE,
75+
VOLUNTEER_CREATE_500_MESSAGE,
76+
EMAIL_500_MESSAGE,
77+
GENERIC_500_MESSAGE,
78+
ACCOUNT_DUPLICATE_422_MESSAGE,
79+
LOGIN_500_MESSAGE,
80+
HACKER_STATUS_409_MESSAGE,
81+
TEAM_SIZE_409_MESSAGE,
82+
ROLE_DUPLICATE_422_MESSAGE,
83+
SETTINGS_422_MESSAGE,
84+
ROLE_CREATE_500_MESSAGE,
85+
TEAM_NAME_409_MESSAGE,
86+
TEAM_JOIN_SAME_409_MESSAGE,
87+
TEAM_READ_500_MESSAGE,
88+
VOLUNTEER_404_MESSAGE,
89+
SPONSOR_UPDATE_500_MESSAGE,
90+
SETTINGS_404_MESSAGE,
91+
SETTINGS_403_MESSAGE,
92+
TRAVEL_404_MESSAGE,
93+
TRAVEL_CREATE_500_MESSAGE
9494
};

src/controllers/account.controller.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Validator } from "@middlewares/validator.middleware";
2929
import AccountConfirmation from "@models/account-confirmation-token.model";
3030
import * as jwt from "jsonwebtoken";
3131
import { InvitationService } from "@app/services/invitation.service";
32+
import Invitation from "@app/models/invitation.model";
3233

3334
@autoInjectable()
3435
@Controller("/account")
@@ -56,20 +57,25 @@ export class AccountController {
5657
);
5758

5859
if (inviter) {
59-
const invitation = await this.invitationService.save({email, accountType, inviter});
60+
const invitation = await this.invitationService.save({
61+
email,
62+
accountType,
63+
inviter
64+
});
6065
await this.mailer.send(
6166
{
6267
to: invitation.email,
63-
subject: "Account Confirmation Instructions",
68+
subject: "Account Creation Instructions",
6469
html: join(
6570
__dirname,
66-
"../assets/email/AccountConfirmation.mjml"
71+
"../assets/email/AccountInvitation.mjml"
6772
)
6873
},
6974
{
70-
link: this.accountConfirmationService.generateLink(
71-
"confirm",
72-
this.invitationService.generateToken(invitation)
75+
link: this.invitationService.generateLink(
76+
"account/create",
77+
this.invitationService.generateToken(invitation),
78+
accountType
7379
)
7480
},
7581
(error?: any) => {
@@ -86,7 +92,7 @@ export class AccountController {
8692
});
8793
} else {
8894
return response.status(404).json({
89-
message: ErrorConstants.ACCOUNT_404_MESSAGE,
95+
message: ErrorConstants.ACCOUNT_404_MESSAGE
9096
});
9197
}
9298
}
@@ -186,33 +192,32 @@ export class AccountController {
186192
async create(
187193
@Response() response: ExpressResponse,
188194
@Body() account: Account,
189-
@Headers("X-Invite-Token") token?: string
195+
// @Params("token") token?: string,
196+
// @Params("accountType") accType?: string,
197+
@Headers("token") token?: string
190198
) {
191199
if (token) {
192-
const data = jwt.verify(
193-
token,
194-
process.env.JWT_CONFIRM_ACC_SECRET!
195-
) as {
196-
identifier: number;
200+
const data = jwt.verify(token, process.env.JWT_INVITE_SECRET!) as {
201+
invitation: Invitation;
197202
};
198203

199-
const result = await this.accountConfirmationService.findByIdentifier(
200-
data.identifier
204+
const result = await this.invitationService.findByIdentifier(
205+
data.email
201206
);
202207

203208
if (result) {
204209
account.confirmed = true;
205210
account.accountType = result.accountType;
206211

207-
this.accountConfirmationService.delete(result.identifier);
212+
this.invitationService.delete(data.email);
208213
}
209214
}
210215

211216
const result: Account = await this.accountService.save(account);
212217

213218
if (result) {
214219
const model = await this.accountConfirmationService.save({
215-
accountType: GeneralConstants.HACKER,
220+
accountType: result.accountType,
216221
email: result.email,
217222
confirmationType: GeneralConstants.CONFIRMATION_TYPE_ORGANIC,
218223
account: result

src/controllers/search.controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export class SearchController {
2525
@Query("model") model: string,
2626
@Query("q") filters: string
2727
) {
28-
const result = await this.searchService.executeQuery(model, JSON.parse(filters));
28+
const result = await this.searchService.executeQuery(
29+
model,
30+
JSON.parse(filters)
31+
);
2932

3033
response.status(200).send({
3134
message:

src/controllers/setting.controller.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Validator } from "@app/middlewares/validator.middleware";
2121
@autoInjectable()
2222
@Controller("/settings")
2323
export class SettingController {
24-
constructor(private readonly settingService: SettingService) { }
24+
constructor(private readonly settingService: SettingService) {}
2525

2626
@Get("/")
2727
async getAll(@Response() response: ExpressResponse) {
@@ -55,17 +55,17 @@ export class SettingController {
5555

5656
return result
5757
? response.status(200).send({
58-
message: SuccessConstants.SETTINGS_POST,
59-
data: result
60-
})
58+
message: SuccessConstants.SETTINGS_POST,
59+
data: result
60+
})
6161
: response.status(422).send({
62-
message: ErrorConstants.SETTINGS_422_MESSAGE
63-
});
62+
message: ErrorConstants.SETTINGS_422_MESSAGE
63+
});
6464
}
6565

6666
@Patch("", [
6767
EnsureAuthenticated,
68-
EnsureAuthorization([AuthorizationLevel.Staff]),
68+
EnsureAuthorization([AuthorizationLevel.Staff])
6969
])
7070
async update(
7171
@Response() response: ExpressResponse,
@@ -74,7 +74,7 @@ export class SettingController {
7474
await this.settingService.update(settings);
7575
return response.status(200).json({
7676
message: SuccessConstants.SETTINGS_PATCH
77-
})
77+
});
7878
}
7979

8080
@Patch("/:identifier", [
@@ -91,14 +91,14 @@ export class SettingController {
9191

9292
return result
9393
? response.status(200).json({
94-
message: SuccessConstants.SETTINGS_PATCH,
95-
data: result
96-
})
94+
message: SuccessConstants.SETTINGS_PATCH,
95+
data: result
96+
})
9797
: response.status(404).json({
98-
message: ErrorConstants.SETTINGS_404_MESSAGE,
99-
data: {
100-
identifier: identifier
101-
}
102-
});
98+
message: ErrorConstants.SETTINGS_404_MESSAGE,
99+
data: {
100+
identifier: identifier
101+
}
102+
});
103103
}
104104
}

0 commit comments

Comments
 (0)