You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
853 B
JavaScript

module.exports = async function(pg, users) {
let adminUser
for (const user of users) {
const existing = await pg.user.findByEmail(user.email)
if(existing) {
console.warn(" Warning: duplicate user with email " + user.email)
continue;
}
const newUser = await pg.user.import(user.email, user.password);
if (user.emailConfirmed) {
await pg.user.markEmailVerified(newUser.uuid)
}
if (user.isAdmin) {
await pg.user.makeAdmin(newUser.uuid)
}
if (user.isAdmin && !adminUser) {
adminUser = newUser;
}
const creationDate = new Date(parseInt(user._id.toString().slice(0,8), 16)*1000)
await pg.user.updateRegistrationDate(newUser.uuid, creationDate, user.emailConfirmed)
}
if (!adminUser) {
throw new Error("Unable to find importing admin")
}
return adminUser
}