@nodebb/nodebb-plugin-import-users-csv
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -46,2 +46,4 @@ 'use strict'; | ||
controllerHelpers.formatApiResponse(201, res, { users, fields, createCount: users.length, ignoreCount }); | ||
await main.executePostRegistration(req.uid, users); | ||
} catch (e) { | ||
@@ -48,0 +50,0 @@ controllerHelpers.formatApiResponse(400, res, e); |
@@ -12,2 +12,3 @@ /* eslint-disable no-await-in-loop */ | ||
const user = require.main.require('./src/user'); | ||
const batch = require.main.require('./src/batch'); | ||
const routeHelpers = require.main.require('./src/routes/helpers'); | ||
@@ -161,2 +162,38 @@ | ||
plugin.executePostRegistration = async (adminUid, users) => { | ||
// Post-registration behaviour | ||
let { behaviour, password: newPassword } = await meta.settings.get('import-users-csv'); | ||
behaviour = behaviour || 'manual'; // manual behaviour === do nothing | ||
if (behaviour === 'auto') { | ||
await batch.processArray(users, async (users) => { | ||
await Promise.all(users.map(async (userObj) => { | ||
await user.reset.send(userObj.email); | ||
})); | ||
}, { | ||
interval: 1000, | ||
batch: 100, | ||
}); | ||
} | ||
if (behaviour === 'password') { | ||
await batch.processArray(users, async (users) => { | ||
await Promise.all(users.map(async (userObj) => { | ||
console.log(`changing password for ${userObj.email}, to ${newPassword}`); | ||
await user.changePassword(adminUid, { | ||
uid: userObj.uid, | ||
newPassword, | ||
}); | ||
})); | ||
}, { | ||
interval: 1000, | ||
batch: 10, | ||
}); | ||
// Trigger password reset on first login | ||
const uids = users.map(user => user.uid); | ||
await db.setObjectField(uids.map(uid => `user:${uid}`), 'passwordExpiry', Date.now()); | ||
} | ||
}; | ||
module.exports = plugin; |
{ | ||
"name": "@nodebb/nodebb-plugin-import-users-csv", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A starter kit for quickly creating NodeBB plugins", | ||
@@ -37,4 +37,4 @@ "main": "library.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "17.6.6", | ||
"@commitlint/config-angular": "17.6.6", | ||
"@commitlint/cli": "17.6.7", | ||
"@commitlint/config-angular": "17.6.7", | ||
"eslint": "8.45.0", | ||
@@ -41,0 +41,0 @@ "eslint-config-nodebb": "0.2.1", |
@@ -29,2 +29,9 @@ /* eslint-disable import/no-unresolved */ | ||
$('#save').on('click', saveSettings); | ||
document.querySelector('[data-action="behaviour-password-insecure-why"]').addEventListener('click', () => { | ||
bootbox.alert({ | ||
title: 'Why is the 'common password' behaviour less secure?', | ||
message: 'We consider this import behaviour less secure as all imported users will have the same common password set. It is theoretically possible that an attacker can guess a valid email and take over a migrated account before the proper user.', | ||
}); | ||
}); | ||
} | ||
@@ -31,0 +38,0 @@ |
Sorry, the diff of this file is not supported yet
186063
316