Invite is now also separate
This commit is contained in:
+21
-13
@@ -29,8 +29,6 @@ exports = module.exports = {
|
||||
|
||||
del,
|
||||
|
||||
sendInvite,
|
||||
|
||||
setTwoFactorAuthenticationSecret,
|
||||
enableTwoFactorAuthentication,
|
||||
disableTwoFactorAuthentication,
|
||||
@@ -40,6 +38,9 @@ exports = module.exports = {
|
||||
getPasswordResetLink,
|
||||
sendPasswordResetEmail,
|
||||
|
||||
getInviteLink,
|
||||
sendInviteEmail,
|
||||
|
||||
notifyLoginLocation,
|
||||
|
||||
setupAccount,
|
||||
@@ -742,19 +743,12 @@ async function createOwner(email, username, password, displayName, auditSource)
|
||||
return await add(email, { username, password, fallbackEmail: '', displayName, role: exports.ROLE_OWNER }, auditSource);
|
||||
}
|
||||
|
||||
async function sendInvite(user, options, auditSource) {
|
||||
async function getInviteLink(user, auditSource) {
|
||||
assert.strictEqual(typeof user, 'object');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
if (user.source) throw new BoxError(BoxError.CONFLICT, 'User is from an external directory');
|
||||
|
||||
// not sure if this can ever be the case
|
||||
if (!user.inviteToken) {
|
||||
const inviteToken = hat(256);
|
||||
user.inviteToken = inviteToken;
|
||||
await update(user, { inviteToken }, auditSource);
|
||||
}
|
||||
|
||||
const directoryConfig = await settings.getDirectoryConfig();
|
||||
let inviteLink = `${settings.dashboardOrigin()}/setupaccount.html?inviteToken=${user.inviteToken}&email=${encodeURIComponent(user.email)}`;
|
||||
|
||||
@@ -762,11 +756,25 @@ async function sendInvite(user, options, auditSource) {
|
||||
if (user.displayName) inviteLink += `&displayName=${encodeURIComponent(user.displayName)}`;
|
||||
if (directoryConfig.lockUserProfiles) inviteLink += '&profileLocked=true';
|
||||
|
||||
await mailer.sendInvite(user, options.invitor || null, inviteLink);
|
||||
|
||||
return inviteLink;
|
||||
}
|
||||
|
||||
async function sendInviteEmail(user, email, auditSource) {
|
||||
assert.strictEqual(typeof user, 'object');
|
||||
assert.strictEqual(typeof email, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
// not sure if this can ever be the case
|
||||
if (!user.inviteToken) {
|
||||
const inviteToken = hat(256);
|
||||
user.inviteToken = inviteToken;
|
||||
await update(user, { inviteToken }, auditSource);
|
||||
}
|
||||
|
||||
const resetLink = await getInviteLink(user, auditSource);
|
||||
await mailer.sendInvite(user, null /* invitor */, email, resetLink);
|
||||
}
|
||||
|
||||
async function setupAccount(user, data, auditSource) {
|
||||
assert.strictEqual(typeof user, 'object');
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
|
||||
Reference in New Issue
Block a user