mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
完善设置
This commit is contained in:
1 parent
fc0d9873a2
commit
7edb29d7b8
43 files changed
+219
-184
No files matched your search
@@ -19,6 +19,6 @@ function index() {
|
||||
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.blacklist = module.exports = {
|
||||
add, get, del, index,
|
||||
};
|
||||
@@ -229,7 +229,8 @@ const STATUS_CODES = {
|
||||
22: 'progress',
|
||||
30: 'ignored',
|
||||
};
|
||||
module.exports = {
|
||||
|
||||
global.Hydro.model.builtin = module.exports = {
|
||||
BUILTIN_ROLES,
|
||||
CATEGORIES,
|
||||
VIEW_LANGS,
|
||||
|
||||
@@ -342,7 +342,7 @@ const ContestHandlerMixin = (c) => class extends c {
|
||||
}
|
||||
};
|
||||
|
||||
global.Hydro['model.contest'] = module.exports = {
|
||||
global.Hydro.model.contest = module.exports = {
|
||||
RULES,
|
||||
ContestHandlerMixin,
|
||||
add,
|
||||
|
||||
@@ -142,15 +142,19 @@ async function getVnode(ddoc, handler) {
|
||||
const pdoc = await problem.getById(ddoc.parentId);
|
||||
if (!pdoc) return null;
|
||||
if (pdoc.hidden && handler) handler.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
|
||||
return { ...pdoc, parentType: ddoc.parentType, parentId: ddoc.parentId };
|
||||
return { ...pdoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
} if (ddoc.parentType === 'contest') {
|
||||
const tdoc = await contest.get(ddoc.parentId);
|
||||
return { ...tdoc, parentType: ddoc.parentType, parentId: ddoc.parentId };
|
||||
return { ...tdoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
} if (ddoc.parentType === 'node') {
|
||||
const ndoc = await getNode(ddoc.parentId);
|
||||
return { ...ndoc, parentType: ddoc.parentType, parentId: ddoc.parentId };
|
||||
return { ...ndoc, type: ddoc.parentType, id: ddoc.parentId };
|
||||
}
|
||||
return null;
|
||||
return {
|
||||
title: 'Missing Node',
|
||||
type: 'Unknown',
|
||||
id: new ObjectID(),
|
||||
};
|
||||
}
|
||||
|
||||
async function getListVnodes(ddocs, handler) {
|
||||
@@ -162,7 +166,7 @@ async function getListVnodes(ddocs, handler) {
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.discussion = module.exports = {
|
||||
add,
|
||||
get,
|
||||
edit,
|
||||
|
||||
+23
-23
@@ -3,26 +3,26 @@ const db = require('../service/db.js');
|
||||
|
||||
const coll = db.collection('opcount');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* @param {string} op
|
||||
* @param {string} ident
|
||||
* @param {number} period_secs
|
||||
* @param {number} max_operations
|
||||
*/
|
||||
async inc(op, ident, periodSecs, maxOperations) {
|
||||
const curTime = new Date().getTime();
|
||||
const beginAt = new Date(curTime - (curTime % (periodSecs * 1000)));
|
||||
const expireAt = new Date(beginAt.getTime() + periodSecs * 1000);
|
||||
try {
|
||||
await coll.findOneAndUpdate({
|
||||
ident,
|
||||
beginAt,
|
||||
expireAt,
|
||||
op: { $not: { $gte: maxOperations } },
|
||||
}, { $inc: { op: 1 } }, { upsert: true });
|
||||
} catch (e) {
|
||||
throw new OpcountExceededError(op, periodSecs, maxOperations);
|
||||
}
|
||||
},
|
||||
};
|
||||
/**
|
||||
* @param {string} op
|
||||
* @param {string} ident
|
||||
* @param {number} period_secs
|
||||
* @param {number} max_operations
|
||||
*/
|
||||
async function inc(op, ident, periodSecs, maxOperations) {
|
||||
const curTime = new Date().getTime();
|
||||
const beginAt = new Date(curTime - (curTime % (periodSecs * 1000)));
|
||||
const expireAt = new Date(beginAt.getTime() + periodSecs * 1000);
|
||||
try {
|
||||
await coll.findOneAndUpdate({
|
||||
ident,
|
||||
beginAt,
|
||||
expireAt,
|
||||
op: { $not: { $gte: maxOperations } },
|
||||
}, { $inc: { op: 1 } }, { upsert: true });
|
||||
} catch (e) {
|
||||
throw new OpcountExceededError(op, periodSecs, maxOperations);
|
||||
}
|
||||
}
|
||||
|
||||
global.Hydro.model.opcount = module.exports = { inc };
|
||||
@@ -104,7 +104,7 @@ async function rejudge(rid) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.record = module.exports = {
|
||||
add,
|
||||
get,
|
||||
getMany,
|
||||
|
||||
+10
-2
@@ -47,9 +47,17 @@ const SYSTEM_SETTINGS = [
|
||||
Setting('setting_smtp', 'smtp.user', null, null, 'text', 'SMTP Username'),
|
||||
Setting('setting_smtp', 'smtp.pass', null, null, 'password', 'SMTP Password'),
|
||||
Setting('setting_smtp', 'smtp.host', null, null, 'text', 'SMTP Server Host'),
|
||||
Setting('setting_smtp', 'smtp.port', null, null, 'text', 'SMTP Server Port'),
|
||||
Setting('setting_smtp', 'smtp.port', null, 465, 'text', 'SMTP Server Port'),
|
||||
Setting('setting_smtp', 'smtp.from', null, null, 'text', 'Mail From'),
|
||||
Setting('setting_smtp', 'smtp.secure', null, null, 'checkbox', 'SSL'),
|
||||
Setting('setting_smtp', 'smtp.secure', null, false, 'checkbox', 'SSL'),
|
||||
Setting('setting_server', 'listen.port', null, 8888, 'text', 'Server Port', ''),
|
||||
Setting('setting_constant', 'PROBLEM_PER_PAGE', null, 100, 'text', 'Problems per Page'),
|
||||
Setting('setting_constant', 'CONTEST_PER_PAGE', null, 20, 'text', 'Contests per Page'),
|
||||
Setting('setting_constant', 'DISCUSSION_PER_PAGE', null, 50, 'text', 'Discussion per Page'),
|
||||
Setting('setting_constant', 'RECORD_PER_PAGE', null, 100, 'text', 'Record per Page'),
|
||||
Setting('setting_constant', 'SOLUTION_PER_PAGE', null, 20, 'text', 'Solutions per Page'),
|
||||
Setting('setting_constant', 'TRAINING_PER_PAGE', null, 10, 'text', 'Training per Page'),
|
||||
Setting('setting_constant', 'REPLY_PER_PAGE', null, 50, 'text', 'Reply per Page'),
|
||||
];
|
||||
|
||||
global.Hydro.model.setting = module.exports = {
|
||||
|
||||
@@ -106,7 +106,7 @@ async function getListStatus(list, uid) {
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.solution = module.exports = {
|
||||
count,
|
||||
add,
|
||||
get,
|
||||
|
||||
@@ -22,7 +22,8 @@ async function set(_id, value) {
|
||||
function inc(field) {
|
||||
return update(field, { $inc: { value: 1 } }, { upsert: true });
|
||||
}
|
||||
module.exports = {
|
||||
|
||||
global.Hydro.model.system = module.exports = {
|
||||
get,
|
||||
update,
|
||||
inc,
|
||||
|
||||
@@ -10,7 +10,7 @@ function index() {
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.token = module.exports = {
|
||||
TYPE_SESSION: 0,
|
||||
TYPE_CSRF_TOKEN: 1,
|
||||
TYPE_REGISTER: 2,
|
||||
|
||||
@@ -35,7 +35,7 @@ async function setStatus(tid, uid, $set) {
|
||||
return await collStatus.findOne({ tid, uid }); // eslint-disable-line no-return-await
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.training = module.exports = {
|
||||
getPids(tdoc) {
|
||||
const pids = new Set();
|
||||
for (const node of tdoc.dag) {
|
||||
|
||||
+13
-10
@@ -1,7 +1,7 @@
|
||||
const system = require('./system');
|
||||
const { UserNotFoundError, UserAlreadyExistError } = require('../error');
|
||||
const perm = require('../permission');
|
||||
const pwhash = require('../lib/pwhash');
|
||||
const pwhash = require('../lib/hash.hydro');
|
||||
const db = require('../service/db');
|
||||
|
||||
const coll = db.collection('user');
|
||||
@@ -12,8 +12,8 @@ class USER {
|
||||
this._id = user._id;
|
||||
this.mail = user.mail;
|
||||
this.uname = user.uname;
|
||||
this.salt = user.salt;
|
||||
this.hash = user.hash;
|
||||
this.salt = () => user.salt;
|
||||
this.hash = () => user.hash;
|
||||
this.perm = user.perm;
|
||||
this.viewLang = user.language || 'zh_CN';
|
||||
this.codeLang = user.codeLang || 'c';
|
||||
@@ -31,7 +31,9 @@ class USER {
|
||||
}
|
||||
|
||||
checkPassword(password) {
|
||||
return pwhash.check(password, this.salt, this.hash);
|
||||
const h = global.Hydro.lib[`hash.${this.hashType}`];
|
||||
if (!h) throw new Error('Unknown hash method');
|
||||
return h.check(password, this.salt(), this.hash());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +73,9 @@ async function getByEmail(mail, ignoreMissing = false) {
|
||||
}
|
||||
|
||||
function setPassword(uid, password) {
|
||||
const salt = pwhash.salt();
|
||||
const salt = String.random();
|
||||
return coll.findOneAndUpdate({ _id: uid }, {
|
||||
$set: { salt, hash: pwhash.hash(password, salt) },
|
||||
$set: { salt, hash: pwhash.hash(password, salt), hashType: 'hydro' },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -88,11 +90,11 @@ function setEmail(uid, mail) {
|
||||
async function changePassword(uid, currentPassword, newPassword) {
|
||||
const udoc = await getById(uid);
|
||||
udoc.checkPassword(currentPassword);
|
||||
const salt = pwhash.salt();
|
||||
const salt = String.random();
|
||||
return await coll.findOneAndUpdate({ // eslint-disable-line no-return-await
|
||||
_id: udoc._id,
|
||||
}, {
|
||||
$set: { salt, hash: pwhash.hash(newPassword, salt) },
|
||||
$set: { salt, hash: pwhash.hash(newPassword, salt), hashType: 'hydro' },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ async function inc(_id, field, n = 1) {
|
||||
async function create({
|
||||
uid, mail, uname, password, regip = '127.0.0.1', role = 'default',
|
||||
}) {
|
||||
const salt = pwhash.salt();
|
||||
const salt = String.random();
|
||||
if (!uid) uid = system.inc('user');
|
||||
try {
|
||||
await Promise.all([
|
||||
@@ -118,6 +120,7 @@ async function create({
|
||||
unameLower: uname.trim().toLowerCase(),
|
||||
password: pwhash.hash(password, salt),
|
||||
salt,
|
||||
hashType: 'hydro',
|
||||
regat: new Date(),
|
||||
regip,
|
||||
loginat: new Date(),
|
||||
@@ -179,7 +182,7 @@ function index() {
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.model.user = module.exports = {
|
||||
changePassword,
|
||||
create,
|
||||
getByEmail,
|
||||
|
||||
Reference in new issue
Block a user