2021-07-20 05:26:36 -04:00
|
|
|
const minimist = require('minimist')
|
|
|
|
const { db, waitForDb } = require('../../../app/src/infrastructure/mongodb')
|
|
|
|
const UserRegistrationHandler = require('../../../app/src/Features/User/UserRegistrationHandler')
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await waitForDb()
|
|
|
|
|
|
|
|
const argv = minimist(process.argv.slice(2), {
|
|
|
|
string: ['email'],
|
|
|
|
boolean: ['admin'],
|
|
|
|
})
|
|
|
|
|
|
|
|
const { admin, email } = argv
|
|
|
|
if (!email) {
|
|
|
|
console.error(`Usage: node ${__filename} [--admin] --email=joe@example.com`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
UserRegistrationHandler.registerNewUserAndSendActivationEmail(
|
2021-09-10 04:30:01 -04:00
|
|
|
email,
|
2021-07-20 05:26:36 -04:00
|
|
|
(error, user, setNewPasswordUrl) => {
|
|
|
|
if (error) {
|
|
|
|
return reject(error)
|
|
|
|
}
|
|
|
|
db.users.updateOne(
|
|
|
|
{ _id: user._id },
|
|
|
|
{ $set: { isAdmin: admin } },
|
|
|
|
error => {
|
|
|
|
if (error) {
|
|
|
|
return reject(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('')
|
|
|
|
console.log(`\
|
|
|
|
Successfully created ${email} as ${admin ? 'an admin' : 'a'} user.
|
|
|
|
|
|
|
|
Please visit the following URL to set a password for ${email} and log in:
|
|
|
|
|
|
|
|
${setNewPasswordUrl}
|
|
|
|
|
|
|
|
`)
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
console.error('Done.')
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|