Generate the user invite link only in one location

This commit is contained in:
Johannes Zellner
2020-02-05 15:53:05 +01:00
parent 68b1d1dde1
commit 1fbbaa82ab
4 changed files with 14 additions and 9 deletions

View File

@@ -562,6 +562,10 @@ function getOwner(callback) {
});
}
function inviteLink(user) {
return `${settings.adminOrigin()}/setupaccount.html?resetToken=${user.resetToken}&email=${encodeURIComponent(user.email)}` + (user.username ? `&username=${encodeURIComponent(user.username)}` : '');
}
function createInvite(userId, callback) {
assert.strictEqual(typeof userId, 'string');
assert.strictEqual(typeof callback, 'function');
@@ -576,7 +580,7 @@ function createInvite(userId, callback) {
userdb.update(userId, userObject, function (error) {
if (error) return callback(error);
callback(null, userObject.resetToken);
callback(null, { resetToken: userObject.resetToken, inviteLink: inviteLink(userObject) });
});
});
}
@@ -592,7 +596,7 @@ function sendInvite(userId, options, callback) {
if (userObject.source) return callback(new BoxError(BoxError.CONFLICT, 'User is from an external directory'));
if (!userObject.resetToken) return callback(new BoxError(BoxError.CONFLICT, 'Must generate resetToken to send invitation'));
mailer.sendInvite(userObject, options.invitor || null);
mailer.sendInvite(userObject, options.invitor || null, inviteLink(userObject));
callback(null);
});