Cancel an enrollment email?


#1

So, I have some code which will invite a user then add an “invitation” to their profile.

Meteor.methods({
  'Player.invite': function (playerDoc) {
    check(playerDoc, Players.simpleSchema()._schema);

    var userId = Accounts.createUser({
      email: playerDoc.email,
      profile: {
        playerId: playerDoc._id
      }
    });

    Accounts.sendEnrollmentEmail(userId);

    Players.update(playerDoc._id, {
      $push: {
        sentAt: new Date(),
        expiresAt: Accounts._tokenExpiration(new Date()),
        accepted: false
      }
    });

    return userId;
  }
});
// ...

Accounts.onEnrollmentLink(function (token, done) {
  var user = Meteor.users.findOne({
    "services.password.reset.token": token
  });
  Players.update({
    _id: user.profile.playerId,
    "invitations.sentAt": { $lt: new Date },
    "invitations.expiresAt": { $gt: new Date },
    "invitations.accepted": false
  }, {
    "invitations.$.accepted": true
  });
});

However, what I need to do is invalidate this enrollment email on command, given they have not already accepted the invitation. How can I invalidate an enrollment email safely?