Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ define({
"field": "phoneNumber",
"description": "<p>the user's phone number, represented as a string.</p>"
}
]
],
"header": [{
"group": "header",
"type": "JWT",
"optional": true,
"field": "token",
"description": "<p>the user's invite token.</p>"
}]
},
"examples": [{
"title": "Request-Example:",
Expand Down
9 changes: 8 additions & 1 deletion docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@
"field": "phoneNumber",
"description": "<p>the user's phone number, represented as a string.</p>"
}
]
],
"header": [{
"group": "header",
"type": "JWT",
"optional": true,
"field": "token",
"description": "<p>the user's invite token.</p>"
}]
},
"examples": [{
"title": "Request-Example:",
Expand Down
12 changes: 12 additions & 0 deletions middlewares/auth.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ function createRoleBindings(roleName = undefined) {
});
}

/**
* Adds a rolebinding between the user and the role with the name stored in 'accountType'.
* @param {{user: {id: ObjectId, accountType: string}}} req
* @param {*} res
* @param {(err?) => void} next
*/
async function addAccountTypeRoleBinding(req, res, next) {
await Services.RoleBinding.createRoleBindingByRoleName(req.user.id, req.user.accountType);
return next();
}

/**
* Middleware to retrieve all the roles in the database
* @param {*} req
Expand Down Expand Up @@ -450,6 +461,7 @@ module.exports = {
getAccountTypeFromConfirmationToken: Middleware.Util.asyncMiddleware(getAccountTypeFromConfirmationToken),
validateConfirmationTokenWithoutAccount: Middleware.Util.asyncMiddleware(validateConfirmationTokenWithoutAccount),
createRoleBindings: createRoleBindings,
addAccountTypeRoleBinding: Middleware.Util.asyncMiddleware(addAccountTypeRoleBinding),
addCreationRoleBindings: Middleware.Util.asyncMiddleware(addCreationRoleBindings),
resendConfirmAccountEmail: Middleware.Util.asyncMiddleware(resendConfirmAccountEmail),
retrieveRoleBindings: Middleware.Util.asyncMiddleware(retrieveRoleBindings),
Expand Down
2 changes: 1 addition & 1 deletion middlewares/validators/account.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", false),
VALIDATOR.enumValidator("body", "shirtSize", Constants.SHIRT_SIZES, false),
VALIDATOR.passwordValidator("body", "password", false),
VALIDATOR.jwtValidator("param", "token", process.env.JWT_CONFIRM_ACC_SECRET, true),
VALIDATOR.jwtValidator("header", "token", process.env.JWT_CONFIRM_ACC_SECRET, true),
VALIDATOR.dateValidator("body", "birthDate", false),
VALIDATOR.phoneNumberValidator("body", "phoneNumber", false)
],
Expand Down
2 changes: 1 addition & 1 deletion models/account.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AccountSchema = new mongoose.Schema({
},
accountType: {
type: String,
enum: Constants.USER_TYPES,
enum: Constants.EXTENDED_USER_TYPES,
default: Constants.HACKER
},
birthDate: {
Expand Down
1 change: 1 addition & 0 deletions routes/api/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module.exports = {
* @apiParam (body) {String} password The password of the account.
* @apiParam (body) {String} birthDate a Date parsable string.
* @apiParam (body) {Number} phoneNumber the user's phone number, represented as a string.
* @apiParam (header) {JWT} [token] the user's invite token.
*
* @apiParamExample {json} Request-Example:
* {
Expand Down
2 changes: 1 addition & 1 deletion routes/api/sponsor.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {

Middleware.Sponsor.parseSponsor,

Middleware.Auth.createRoleBindings(CONSTANTS.SPONSOR),
Middleware.Auth.addAccountTypeRoleBinding,

Middleware.Sponsor.createSponsor,
Controllers.Sponsor.createdSponsor
Expand Down