summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/components/settings/invitationCode.js4
-rw-r--r--config/accounts.js2
-rw-r--r--models/settings.js1
-rw-r--r--models/users.js24
4 files changed, 19 insertions, 12 deletions
diff --git a/client/components/settings/invitationCode.js b/client/components/settings/invitationCode.js
index e712c89a..a403d8ab 100644
--- a/client/components/settings/invitationCode.js
+++ b/client/components/settings/invitationCode.js
@@ -1,6 +1,6 @@
Template.invitationCode.onRendered(() => {
- const disableRegistration = Settings.findOne().disableRegistration;
- if(!disableRegistration){
+ const setting = Settings.findOne();
+ if (!setting || !setting.disableRegistration) {
$('#invitationcode').hide();
}
});
diff --git a/config/accounts.js b/config/accounts.js
index 51c0f49e..e7faa4cd 100644
--- a/config/accounts.js
+++ b/config/accounts.js
@@ -13,7 +13,6 @@ AccountsTemplates.addFields([{
displayName: 'Invitation Code',
required: false,
minLength: 6,
- errStr: 'Invitation code doesn\'t exist',
template: 'invitationCode',
}]);
@@ -69,4 +68,3 @@ if (Meteor.isServer) {
};
});
}
-
diff --git a/models/settings.js b/models/settings.js
index 0e6ab762..29b5f97c 100644
--- a/models/settings.js
+++ b/models/settings.js
@@ -104,6 +104,7 @@ if (Meteor.isServer) {
text: TAPi18n.__('email-invite-register-text', params, lang),
});
} catch (e) {
+ InvitationCodes.remove(_id);
throw new Meteor.Error('email-fail', e.message);
}
}
diff --git a/models/users.js b/models/users.js
index 06b84fa0..cdc4d9dc 100644
--- a/models/users.js
+++ b/models/users.js
@@ -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}});
}
}