feat: register validation + create + admin improvements

This commit is contained in:
Nicolas Giard
2018-12-17 00:51:52 -05:00
parent 17244a0cb3
commit 901dbb98e0
25 changed files with 668 additions and 62 deletions

View File

@@ -292,4 +292,23 @@ module.exports = class User extends Model {
}
throw new WIKI.Error.AuthTFAInvalid()
}
static async register ({ email, password, name }, context) {
const usr = await WIKI.models.users.query().findOne({ email, providerKey: 'local' })
if (!usr) {
await WIKI.models.users.query().insert({
provider: 'local',
email,
name,
password,
locale: 'en',
defaultEditor: 'markdown',
tfaIsActive: false,
isSystem: false
})
return true
} else {
throw new WIKI.Error.AuthAccountAlreadyExists()
}
}
}