summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/components/settings/settingBody.js1
-rw-r--r--models/settings.js29
-rw-r--r--models/users.js8
3 files changed, 28 insertions, 10 deletions
diff --git a/client/components/settings/settingBody.js b/client/components/settings/settingBody.js
index 5995cbf1..de96c100 100644
--- a/client/components/settings/settingBody.js
+++ b/client/components/settings/settingBody.js
@@ -101,6 +101,7 @@ BlazeComponent.extendComponent({
// if (!err) {
// TODO - show more info to user
// }
+
this.setLoading(false);
});
}
diff --git a/models/settings.js b/models/settings.js
index 34f693d9..308d867d 100644
--- a/models/settings.js
+++ b/models/settings.js
@@ -124,20 +124,33 @@ if (Meteor.isServer) {
sendInvitation(emails, boards) {
check(emails, [String]);
check(boards, [String]);
+
const user = Users.findOne(Meteor.userId());
if(!user.isAdmin){
throw new Meteor.Error('not-allowed');
}
emails.forEach((email) => {
if (email && SimpleSchema.RegEx.Email.test(email)) {
- const code = getRandomNum(100000, 999999);
- InvitationCodes.insert({code, email, boardsToBeInvited: boards, createdAt: new Date(), authorId: Meteor.userId()}, function(err, _id){
- if (!err && _id) {
- sendInvitationEmail(_id);
- } else {
- throw new Meteor.Error('invitation-generated-fail', err.message);
- }
- });
+ // Checks if the email is already link to an account.
+ const userExist = Users.findOne({email});
+ if (userExist){
+ throw new Meteor.Error('user-exist', `The user with the email ${email} has already an account.`);
+ }
+ // Checks if the email is already link to an invitation.
+ const invitation = InvitationCodes.findOne({email});
+ if (invitation){
+ InvitationCodes.update(invitation, {$set : {boardsToBeInvited: boards}});
+ sendInvitationEmail(invitation._id);
+ }else {
+ const code = getRandomNum(100000, 999999);
+ InvitationCodes.insert({code, email, boardsToBeInvited: boards, createdAt: new Date(), authorId: Meteor.userId()}, function(err, _id){
+ if (!err && _id) {
+ sendInvitationEmail(_id);
+ } else {
+ throw new Meteor.Error('invitation-generated-fail', err.message);
+ }
+ });
+ }
}
});
},
diff --git a/models/users.js b/models/users.js
index 5a7fbbe5..9d859664 100644
--- a/models/users.js
+++ b/models/users.js
@@ -501,9 +501,13 @@ if (Meteor.isServer) {
} else {
user.profile = {icode: options.profile.invitationcode};
user.profile.boardView = 'board-view-lists';
- }
- return user;
+ // Deletes the invitation code after the user was created successfully.
+ setTimeout(Meteor.bindEnvironment(() => {
+ InvitationCodes.remove({'_id': invitationCode._id});
+ }), 200);
+ return user;
+ }
});
}