diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-07-18 14:17:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-18 14:17:36 +0300 |
commit | c708877ddeedfe229462c241db520e149934ad01 (patch) | |
tree | 9535112d29dff8f5d41e41ead35f0ee0d4c964a4 /models/settings.js | |
parent | 19402f5850adcc2505533f08ed065e580f807f9c (diff) | |
parent | e2ae5d6b8e5d2b8b23ecfb48c54a7a748eb425a6 (diff) | |
download | wekan-c708877ddeedfe229462c241db520e149934ad01.tar.gz wekan-c708877ddeedfe229462c241db520e149934ad01.tar.bz2 wekan-c708877ddeedfe229462c241db520e149934ad01.zip |
Merge pull request #1785 from Akuket/devel
Bugfix : Resending invitation code.
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); + } + }); + } } }); }, |