mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
allow to specify password while create new user via CLI
This commit is contained in:
parent
89a5f01b6e
commit
6d750fe78e
1 changed files with 14 additions and 8 deletions
|
@ -65,12 +65,17 @@ async function resetPassword (args) {
|
|||
async function create (args) {
|
||||
await _initializeDB()
|
||||
const { User } = require('../api/models/models')
|
||||
try {
|
||||
const user = await User.create({
|
||||
email: args.email,
|
||||
password: args.password,
|
||||
is_active: true,
|
||||
is_admin: args.admin || false
|
||||
}).catch(e => console.error(String(e)))
|
||||
console.error(JSON.stringify(user, null, 2))
|
||||
})
|
||||
console.error(`User ${args.email} created`)
|
||||
} catch(e) {
|
||||
console.error(String(e))
|
||||
}
|
||||
await db.close()
|
||||
}
|
||||
|
||||
|
@ -106,11 +111,12 @@ const usersCLI = yargs => yargs
|
|||
}, resetPassword)
|
||||
.command('set-admin <email|username>', 'Set administrator privileges to the given user', {}, setAdmin)
|
||||
.command('unset-admin <email|username>', 'Remove administrator privileges to the given user', {}, unsetAdmin)
|
||||
.command('create <email|username> [admin]', 'Create an user', {
|
||||
admin: { describe: 'Define this user as administrator', type: 'boolean' }
|
||||
.command('create <email|username> [password] [admin]', 'Create an user', {
|
||||
admin: { describe: 'Define this user as administrator', type: 'boolean' },
|
||||
}, create)
|
||||
.command('remove <email|username>', 'Remove an user', {}, remove)
|
||||
.positional('email', { describe: 'user email or username', type: 'string', demandOption: true })
|
||||
.positional('password', { describe: 'Password', type: 'string', demandOption: false })
|
||||
.recommendCommands()
|
||||
.demandCommand(1, '')
|
||||
.argv
|
||||
|
|
Loading…
Reference in a new issue