Ability to not create users on first sign in (fix #497).
This commit is contained in:
parent
f0497ec16d
commit
bd9396b031
@ -10,5 +10,10 @@
|
||||
],
|
||||
"mounts": {}
|
||||
},
|
||||
"datadir": "/var/lib/xo-server/data"
|
||||
"datadir": "/var/lib/xo-server/data",
|
||||
|
||||
// Should users be created on first sign in?
|
||||
//
|
||||
// Necessary for external authentication providers.
|
||||
"createUserOnFirstSignin": true
|
||||
}
|
||||
|
@ -581,8 +581,8 @@ export default async function main (args) {
|
||||
|
||||
// Create the main object which will connects to Xen servers and
|
||||
// manages all the models.
|
||||
const xo = new Xo()
|
||||
await xo.start(config)
|
||||
const xo = new Xo(config)
|
||||
await xo.start()
|
||||
|
||||
// Loads default authentication providers.
|
||||
registerPasswordAuthenticationProvider(xo)
|
||||
|
12
src/xo.js
12
src/xo.js
@ -105,9 +105,11 @@ class NoSuchRemote extends NoSuchObject {
|
||||
// ===================================================================
|
||||
|
||||
export default class Xo extends EventEmitter {
|
||||
constructor () {
|
||||
constructor (config) {
|
||||
super()
|
||||
|
||||
this._config = config
|
||||
|
||||
this._objects = new XoCollection()
|
||||
this._objects.createIndex('byRef', new XoUniqueIndex('_xapiRef'))
|
||||
|
||||
@ -143,7 +145,9 @@ export default class Xo extends EventEmitter {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
async start (config) {
|
||||
async start () {
|
||||
const { _config: config } = this
|
||||
|
||||
await fs.mkdirp(config.datadir)
|
||||
|
||||
this._leveldb = sublevel(levelup(`${config.datadir}/leveldb`, {
|
||||
@ -393,6 +397,10 @@ export default class Xo extends EventEmitter {
|
||||
return user
|
||||
}
|
||||
|
||||
if (!this._config.createUserOnFirstSignin) {
|
||||
throw new Error(`registering ${name} user is forbidden`)
|
||||
}
|
||||
|
||||
return await this.createUser(name, {
|
||||
_provider: provider
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user