mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
system check & setting_secret
This commit is contained in:
1 parent
c52ddd7512
commit
57f711ed4f
18 files changed
+295
-134
No files matched your search
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable no-bitwise */
|
||||
const PERM = {
|
||||
PERM_NONE: '',
|
||||
|
||||
|
||||
+17
-6
@@ -9,6 +9,10 @@ for (const country of countries) {
|
||||
}
|
||||
const timezones = Array.from(tzs).sort().map((tz) => [tz, tz]);
|
||||
|
||||
const FLAG_HIDDEN = 1;
|
||||
const FLAG_DISABLED = 2;
|
||||
const FLAG_SECRET = 4;
|
||||
|
||||
const PREFERENCE_SETTINGS = [];
|
||||
const ACCOUNT_SETTINGS = [];
|
||||
const DOMAIN_SETTINGS = [];
|
||||
@@ -23,9 +27,9 @@ const SYSTEM_SETTINGS_BY_KEY = {};
|
||||
const Setting = (
|
||||
family, key, range = null,
|
||||
value = null, type = 'text', name = '',
|
||||
desc = '', hidden = false, disabled = false,
|
||||
desc = '', flag = 0,
|
||||
) => ({
|
||||
family, key, range, value, type, name, desc, hidden, disabled,
|
||||
family, key, range, value, type, name, desc, flag,
|
||||
});
|
||||
|
||||
const PreferenceSetting = (...settings) => {
|
||||
@@ -93,11 +97,15 @@ DomainSetting(
|
||||
Setting('setting_domain', 'name', null, 'New domain', 'text', 'name'),
|
||||
Setting('setting_domain', 'gravatar', null, '', 'text', 'gravatar', 'Will be used as the domain icon.'),
|
||||
Setting('setting_domain', 'bulletin', null, '', 'markdown', 'Bulletin'),
|
||||
Setting('storage', 'nAccept', null, 0, 'number', 'nAccept', null, FLAG_HIDDEN & FLAG_DISABLED),
|
||||
Setting('storage', 'nSubmit', null, 0, 'number', 'nSubmit', null, FLAG_HIDDEN & FLAG_DISABLED),
|
||||
Setting('storage', 'nLike', null, 0, 'number', 'nLike', null, FLAG_HIDDEN & FLAG_DISABLED),
|
||||
Setting('storage', 'rating', null, 1500, 'number', 'rating', null, FLAG_HIDDEN & FLAG_DISABLED),
|
||||
);
|
||||
|
||||
SystemSetting(
|
||||
Setting('setting_smtp', 'smtp.user', null, null, 'text', 'SMTP Username'),
|
||||
Setting('setting_smtp', 'smtp.pass', null, null, 'password', 'SMTP Password'),
|
||||
Setting('setting_smtp', 'smtp.pass', null, null, 'password', 'SMTP Password', null, FLAG_SECRET),
|
||||
Setting('setting_smtp', 'smtp.host', null, null, 'text', 'SMTP Server Host'),
|
||||
Setting('setting_smtp', 'smtp.port', null, 465, 'number', 'SMTP Server Port'),
|
||||
Setting('setting_smtp', 'smtp.from', null, null, 'text', 'Mail From'),
|
||||
@@ -109,9 +117,9 @@ SystemSetting(
|
||||
Setting('setting_server', 'server.port', null, 8888, 'number', 'Server Port'),
|
||||
Setting('setting_server', 'server.log', null, false, 'boolean', 'Disable Access Log'),
|
||||
Setting('setting_oauth', 'oauth.githubappid', null, null, 'text', 'Github Oauth AppID'),
|
||||
Setting('setting_oauth', 'oauth.githubsecret', null, null, 'text', 'Github Oauth Secret'),
|
||||
Setting('setting_oauth', 'oauth.googleappid', null, null, 'text', 'Google Oauth ClientID'),
|
||||
Setting('setting_oauth', 'oauth.googlesecret', null, null, 'text', 'Google Oauth Secret'),
|
||||
Setting('setting_oauth', 'oauth.githubsecret', null, null, 'text', 'Github Oauth Secret', null, FLAG_SECRET),
|
||||
Setting('setting_oauth', 'oauth.googleappid', null, null, 'text', 'Google Oauth ClientID', null),
|
||||
Setting('setting_oauth', 'oauth.googlesecret', null, null, 'text', 'Google Oauth Secret', null, FLAG_SECRET),
|
||||
Setting('setting_proxy', 'proxy', null, null, 'text', 'Proxy Server URL'),
|
||||
Setting('setting_constant', 'PROBLEM_PER_PAGE', null, 100, 'number', 'Problems per Page'),
|
||||
Setting('setting_constant', 'CONTEST_PER_PAGE', null, 20, 'number', 'Contests per Page'),
|
||||
@@ -129,6 +137,9 @@ global.Hydro.model.setting = module.exports = {
|
||||
DomainSetting,
|
||||
DomainUserSetting,
|
||||
SystemSetting,
|
||||
FLAG_HIDDEN,
|
||||
FLAG_DISABLED,
|
||||
FLAG_SECRET,
|
||||
PREFERENCE_SETTINGS,
|
||||
ACCOUNT_SETTINGS,
|
||||
SETTINGS,
|
||||
|
||||
+22
-19
@@ -9,6 +9,14 @@ const db = require('../service/db');
|
||||
|
||||
const coll = db.collection('user');
|
||||
|
||||
function setPassword(uid, password) {
|
||||
const salt = String.random();
|
||||
return coll.findOneAndUpdate(
|
||||
{ _id: uid },
|
||||
{ $set: { salt, hash: pwhash(password, salt), hashType: 'hydro' } },
|
||||
);
|
||||
}
|
||||
|
||||
class USER {
|
||||
constructor(udoc, dudoc) {
|
||||
this.udoc = () => udoc;
|
||||
@@ -18,7 +26,12 @@ class USER {
|
||||
this.uname = udoc.uname;
|
||||
this.salt = () => udoc.salt;
|
||||
this.hash = () => udoc.hash;
|
||||
this.hashType = udoc.hashType || 'hydro';
|
||||
this.priv = udoc.priv;
|
||||
this.regat = udoc.regat;
|
||||
this.loginat = udoc.loginat;
|
||||
this.perm = dudoc.perm;
|
||||
this.role = dudoc.role || 'default';
|
||||
|
||||
for (const key in setting.SETTINGS_BY_KEY) {
|
||||
if (udoc[key]) this[key] = udoc[key];
|
||||
@@ -27,14 +40,12 @@ class USER {
|
||||
}
|
||||
}
|
||||
|
||||
this.regat = udoc.regat;
|
||||
this.loginat = udoc.loginat;
|
||||
this.ban = udoc.ban || false;
|
||||
this.nAccept = dudoc.nAccept || 0;
|
||||
this.nSubmit = dudoc.nSubmit || 0;
|
||||
this.rating = dudoc.rating || 1500;
|
||||
this.perm = dudoc.perm;
|
||||
this.role = dudoc.role || 'default';
|
||||
for (const key in setting.DOMAIN_USER_SETTINGS_BY_KEY) {
|
||||
if (dudoc[key]) this[key] = dudoc[key];
|
||||
else if (setting.DOMAIN_USER_SETTINGS_BY_KEY[key].value) {
|
||||
this[key] = setting.DOMAIN_USER_SETTINGS_BY_KEY[key].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasPerm(p) {
|
||||
@@ -42,15 +53,16 @@ class USER {
|
||||
}
|
||||
|
||||
hasPriv(p) {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
return this.priv & p;
|
||||
}
|
||||
|
||||
checkPassword(password) {
|
||||
const h = global.Hydro.lib[`hash.${this.hashType || 'hydro'}`];
|
||||
const h = global.Hydro.lib[`hash.${this.hashType}`];
|
||||
if (!h) throw new Error('Unknown hash method');
|
||||
if (!(h(password, this.salt(), this) === this.hash())) {
|
||||
throw new LoginError(this.uname);
|
||||
} else if (this.hashType !== 'hydro') {
|
||||
setPassword(this._id, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +71,6 @@ async function getInDomain(domainId, udoc) {
|
||||
let dudoc = await document.getStatus(domainId, document.TYPE_DOMAIN_USER, 0, udoc._id);
|
||||
dudoc = dudoc || {};
|
||||
if (udoc._id === 1) dudoc.role = 'guest';
|
||||
// eslint-disable-next-line no-bitwise
|
||||
if (udoc.priv & PRIV.PRIV_MANAGE_ALL_DOMAIN) dudoc.role = 'admin';
|
||||
const p = await document.get(domainId, document.TYPE_DOMAIN_USER, dudoc.role || 'default');
|
||||
dudoc.perm = p ? p.content : BUILTIN_ROLES[dudoc.role || 'default'].perm;
|
||||
@@ -116,14 +127,6 @@ async function getByEmail(domainId, mail, ignoreMissing = false) {
|
||||
return new USER(udoc, dudoc);
|
||||
}
|
||||
|
||||
function setPassword(uid, password) {
|
||||
const salt = String.random();
|
||||
return coll.findOneAndUpdate(
|
||||
{ _id: uid },
|
||||
{ $set: { salt, hash: pwhash(password, salt), hashType: 'hydro' } },
|
||||
);
|
||||
}
|
||||
|
||||
function setById(uid, $set, $unset) {
|
||||
const op = {};
|
||||
if ($set && Object.keys($set).length) op.$set = $set;
|
||||
|
||||
Reference in new issue
Block a user