mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 01:38:19 +08:00
Hello Typescript!
This commit is contained in:
1 parent
c9b6412527
commit
ba03d7a7bf
98 files changed
+3186
-2616
No files matched your search
@@ -7,7 +7,7 @@ const document = require('../model/document');
|
||||
const discussion = require('../model/discussion');
|
||||
const user = require('../model/user');
|
||||
const blacklist = require('../model/blacklist');
|
||||
const db = require('../service/db.js');
|
||||
const db = require('../service/db');
|
||||
|
||||
async function _address(ip, bset, uset, dset, dryrun, report) {
|
||||
if (bset.has(ip))
|
||||
|
||||
+23
-24
@@ -1,14 +1,10 @@
|
||||
const description = 'Install';
|
||||
|
||||
const { defaults } = require('lodash');
|
||||
const db = require('../service/db');
|
||||
const { PRIV_ALL } = require('../model/builtin').PRIV;
|
||||
const system = require('../model/system');
|
||||
const user = require('../model/user');
|
||||
const domain = require('../model/domain');
|
||||
const pwhash = require('../lib/hash.hydro');
|
||||
const { udoc } = require('../interface');
|
||||
|
||||
const collUser = db.collection('user');
|
||||
|
||||
async function run({ username, password } = {}) {
|
||||
const def = {
|
||||
@@ -38,7 +34,7 @@ async function run({ username, password } = {}) {
|
||||
changemail_token_expire_seconds: 3600 * 24,
|
||||
registration_token_expire_seconds: 600,
|
||||
};
|
||||
let tasks = [];
|
||||
const tasks = [];
|
||||
for (const key in def) {
|
||||
tasks.push(system.get(key).then((value) => {
|
||||
if (!value) return system.set(key, def[key]);
|
||||
@@ -46,26 +42,29 @@ async function run({ username, password } = {}) {
|
||||
}));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
tasks = [domain.add('system', 0, 'Hydro', true)];
|
||||
await domain.add('system', 0, 'Hydro', true);
|
||||
if (username && password) {
|
||||
const salt = String.random();
|
||||
tasks.push(
|
||||
collUser.updateOne({ _id: -1 }, {
|
||||
$set: defaults({
|
||||
_id: -1,
|
||||
mail: 'root@hydro',
|
||||
mailLower: 'root@hydro',
|
||||
uname: username,
|
||||
unameLower: username.trim().toLowerCase(),
|
||||
hash: pwhash(password, salt),
|
||||
salt,
|
||||
gravatar: 'root@hydro',
|
||||
priv: PRIV_ALL,
|
||||
}, udoc),
|
||||
}, { upsert: true }),
|
||||
);
|
||||
const udoc = await user.getById('system', -1, false);
|
||||
if (!udoc) {
|
||||
await user.create({
|
||||
uid: -1,
|
||||
mail: 'root@hydro.local',
|
||||
uname: username,
|
||||
password,
|
||||
regip: '127.0.0.1',
|
||||
priv: PRIV_ALL,
|
||||
});
|
||||
} else {
|
||||
const salt = String.random();
|
||||
await user.setById(-1, {
|
||||
uname: username,
|
||||
unameLower: username.trim().toLowerCase(),
|
||||
salt,
|
||||
hash: pwhash.default(password, salt),
|
||||
hashType: 'hydro',
|
||||
});
|
||||
}
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
global.Hydro.script.install = module.exports = { run, description };
|
||||
Reference in new issue
Block a user