|
@@ -91,6 +91,10 @@ Users.attachSchema(new SimpleSchema({
|
|
|
type: [String],
|
|
|
optional: true,
|
|
|
},
|
|
|
+ 'profile.icode': {
|
|
|
+ type: String,
|
|
|
+ optional: true,
|
|
|
+ },
|
|
|
services: {
|
|
|
type: Object,
|
|
|
optional: true,
|
|
@@ -401,11 +405,12 @@ if (Meteor.isServer) {
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
- const iCode = options.profile.invitationcode | '';
|
|
|
-
|
|
|
- const invitationCode = InvitationCodes.findOne({code: iCode, valid:true});
|
|
|
+ if (!options || !options.profile) {
|
|
|
+ throw new Meteor.Error('error-invitation-code-blank', 'The invitation code is required');
|
|
|
+ }
|
|
|
+ const invitationCode = InvitationCodes.findOne({code: options.profile.invitationcode, email: options.email, valid: true});
|
|
|
if (!invitationCode) {
|
|
|
- throw new Meteor.Error('error-invitation-code-not-exist');
|
|
|
+ throw new Meteor.Error('error-invitation-code-not-exist', 'The invitation code doesn\'t exist');
|
|
|
}else{
|
|
|
user.profile = {icode: options.profile.invitationcode};
|
|
|
}
|
|
@@ -487,16 +492,19 @@ if (Meteor.isServer) {
|
|
|
//invite user to corresponding boards
|
|
|
const disableRegistration = Settings.findOne().disableRegistration;
|
|
|
if (disableRegistration) {
|
|
|
- const user = Users.findOne(doc._id);
|
|
|
- const invitationCode = InvitationCodes.findOne({code: user.profile.icode, valid:true});
|
|
|
+ const invitationCode = InvitationCodes.findOne({code: doc.profile.icode, valid:true});
|
|
|
if (!invitationCode) {
|
|
|
- throw new Meteor.Error('error-user-notCreated');
|
|
|
+ throw new Meteor.Error('error-invitation-code-not-exist');
|
|
|
}else{
|
|
|
invitationCode.boardsToBeInvited.forEach((boardId) => {
|
|
|
const board = Boards.findOne(boardId);
|
|
|
board.addMember(doc._id);
|
|
|
});
|
|
|
- user.profile = {invitedBoards: invitationCode.boardsToBeInvited};
|
|
|
+ if (!doc.profile) {
|
|
|
+ doc.profile = {};
|
|
|
+ }
|
|
|
+ doc.profile.invitedBoards = invitationCode.boardsToBeInvited;
|
|
|
+ Users.update(doc._id, {$set:{profile: doc.profile}});
|
|
|
InvitationCodes.update(invitationCode._id, {$set: {valid:false}});
|
|
|
}
|
|
|
}
|