diff options
author | guillaume <guillaume.cassou@supinfo.com> | 2018-07-16 19:20:47 +0200 |
---|---|---|
committer | guillaume <guillaume.cassou@supinfo.com> | 2018-07-16 19:20:47 +0200 |
commit | df54f15ecb36e105ad2116443672c99d52569958 (patch) | |
tree | 6a0fb272362f366a3bd12ff19fd36c6b0cadb9f8 /models/settings.js | |
parent | c0ddecb2eeea3277dcab5a750eac991b7b0945ea (diff) | |
download | wekan-df54f15ecb36e105ad2116443672c99d52569958.tar.gz wekan-df54f15ecb36e105ad2116443672c99d52569958.tar.bz2 wekan-df54f15ecb36e105ad2116443672c99d52569958.zip |
patch re-invit
Diffstat (limited to 'models/settings.js')
-rw-r--r-- | models/settings.js | 29 |
1 files changed, 21 insertions, 8 deletions
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); + } + }); + } } }); }, |