update model.user.create() api

This commit is contained in:
undefined committed 2020-07-22 18:54:18 +08:00
1 parent 162d93e5db
commit 37756c3724
14 files changed
+31 -57

No files matched your search

+1 -8
View File
@@ -11,14 +11,7 @@ export async function run({ username = '', password = '' } = {}) {
if (username && password) {
const udoc = await user.getById('system', -1);
if (!udoc) {
await user.create({
uid: -1,
mail: 'root@hydro.local',
uname: username,
password,
regip: '127.0.0.1',
priv: PRIV.PRIV_ALL,
});
await user.create('root@hydro.local', username, password, -1, '127.0.0.1', PRIV.PRIV_ALL);
} else {
const salt = String.random();
await user.setById(-1, {
+3 -7
View File
@@ -1,17 +1,13 @@
import * as user from '../model/user';
import * as system from '../model/system';
export const description = 'Create a new user';
export async function run({
uname, password, mail, uid,
}) {
if (!uid) uid = await system.inc('user');
else uid = parseInt(uid, 10);
if (Number.isNaN(uid)) throw new Error('uid');
await user.create({
uid, uname, password, mail, regip: '127.0.0.1',
});
if (uid) uid = parseInt(uid, 10);
if (uid && Number.isNaN(uid)) throw new Error('uid');
uid = await user.create(mail, uname, password, uid);
return uid;
}