mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
交互式安装
This commit is contained in:
1 parent
6134a16f8c
commit
27cfe81e31
21 files changed
+333
-181
No files matched your search
@@ -3,12 +3,12 @@ const {
|
||||
ContestNotAttendedError,
|
||||
} = require('../error');
|
||||
const { PERM_CREATE_CONTEST, PERM_EDIT_CONTEST } = require('../permission');
|
||||
const { constants } = require('../options');
|
||||
const paginate = require('../lib/paginate');
|
||||
const contest = require('../model/contest');
|
||||
const problem = require('../model/problem');
|
||||
const record = require('../model/record');
|
||||
const user = require('../model/user');
|
||||
const system = require('../model/system');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
|
||||
const ContestHandler = contest.ContestHandlerMixin(Handler);
|
||||
@@ -27,7 +27,7 @@ class ContestListHandler extends ContestHandler {
|
||||
qs = 'rule={0}'.format(rule);
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
[tdocs, tpcount] = await paginate(tdocs, page, constants.CONTEST_PER_PAGE);
|
||||
[tdocs, tpcount] = await paginate(tdocs, page, await system.get('CONTEST_PER_PAGE'));
|
||||
const tids = [];
|
||||
for (const tdoc of tdocs) tids.push(tdoc._id);
|
||||
const tsdict = await contest.getListStatus(this.user._id, tids);
|
||||
@@ -51,12 +51,14 @@ class ContestDetailHandler extends ContestHandler {
|
||||
attended;
|
||||
if (tsdoc) {
|
||||
attended = tsdoc.attend === 1;
|
||||
for (const pdetail of tsdoc.journal || []) { psdict[pdetail.pid] = pdetail; }
|
||||
for (const pdetail of tsdoc.journal || []) psdict[pdetail.pid] = pdetail;
|
||||
if (this.canShowRecord(this.tdoc)) {
|
||||
const q = [];
|
||||
for (const i in psdict) q.push(psdict[i].rid);
|
||||
rdict = await record.getList(q);
|
||||
} else { for (const i in psdict) rdict[psdict[i].rid] = { _id: psdict[i].rid }; }
|
||||
} else {
|
||||
for (const i in psdict) rdict[psdict[i].rid] = { _id: psdict[i].rid };
|
||||
}
|
||||
} else attended = false;
|
||||
const udict = await user.getList([this.tdoc.owner]);
|
||||
const path = [
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const paginate = require('../lib/paginate');
|
||||
const problem = require('../model/problem');
|
||||
const contest = require('../model/contest');
|
||||
const system = require('../model/system');
|
||||
const user = require('../model/user');
|
||||
const discussion = require('../model/discussion');
|
||||
const {
|
||||
@@ -9,7 +10,6 @@ const {
|
||||
const {
|
||||
DiscussionNodeNotFoundError, DiscussionNotFoundError, DocumentNotFoundError,
|
||||
} = require('../error');
|
||||
const { constants } = require('../options');
|
||||
const {
|
||||
PERM_VIEW_DISCUSSION, PERM_EDIT_DISCUSSION, PERM_EDIT_DISCUSSION_REPLY,
|
||||
PERM_VIEW_PROBLEM_HIDDEN, PERM_DELETE_DISCUSSION, PERM_DELETE_DISCUSSION_REPLY,
|
||||
@@ -65,7 +65,7 @@ class DiscussionMainHandler extends DiscussionHandler {
|
||||
const [ddocs, dpcount] = await paginate(
|
||||
discussion.getMulti(),
|
||||
page,
|
||||
constants.DISCUSSION_PER_PAGE,
|
||||
await system.get('DISCUSSION_PER_PAGE'),
|
||||
);
|
||||
const udict = await user.getList(ddocs.map((ddoc) => ddoc.owner));
|
||||
const path = [
|
||||
@@ -84,7 +84,7 @@ class DiscussionNodeHandler extends DiscussionHandler {
|
||||
const [ddocs, dpcount] = await paginate(
|
||||
discussion.getMulti({ type, docId }),
|
||||
page,
|
||||
constants.DISCUSSION_PER_PAGE,
|
||||
await system.get('DISCUSSION_PER_PAGE'),
|
||||
);
|
||||
const udict = await user.getList(ddocs.map((ddoc) => ddoc.owner));
|
||||
const path = [
|
||||
@@ -142,7 +142,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
||||
const [drdocs, pcount, drcount] = await paginate(
|
||||
discussion.getMultiReply(did),
|
||||
page,
|
||||
constants.REPLY_PER_PAGE,
|
||||
await system.get('REPLY_PER_PAGE'),
|
||||
);
|
||||
const uids = drdocs.map((drdoc) => drdoc.owner);
|
||||
uids.push(this.ddoc.owner);
|
||||
|
||||
@@ -2,7 +2,6 @@ const {
|
||||
VerifyPasswordError, UserAlreadyExistError, InvalidTokenError,
|
||||
NotFoundError, MessageNotFoundError,
|
||||
} = require('../error');
|
||||
const options = require('../options');
|
||||
const bus = require('../service/bus');
|
||||
const {
|
||||
Route, Connection, Handler, ConnectionHandler,
|
||||
@@ -11,6 +10,7 @@ const misc = require('../lib/misc');
|
||||
const md5 = require('../lib/md5');
|
||||
const contest = require('../model/contest');
|
||||
const message = require('../model/message');
|
||||
const system = require('../model/system');
|
||||
const user = require('../model/user');
|
||||
const setting = require('../model/setting');
|
||||
const discussion = require('../model/discussion');
|
||||
@@ -20,13 +20,12 @@ const {
|
||||
PERM_VIEW_TRAINING, PERM_VIEW_CONTEST, PERM_VIEW_DISCUSSION,
|
||||
PERM_LOGGEDIN,
|
||||
} = require('../permission');
|
||||
const { CONTESTS_ON_MAIN, TRAININGS_ON_MAIN, DISCUSSIONS_ON_MAIN } = require('../options').constants;
|
||||
|
||||
class HomeHandler extends Handler {
|
||||
async contest() {
|
||||
if (this.user.hasPerm(PERM_VIEW_CONTEST)) {
|
||||
const tdocs = await contest.getMulti()
|
||||
.limit(CONTESTS_ON_MAIN)
|
||||
.limit(await system.get('CONTESTS_ON_MAIN'))
|
||||
.toArray();
|
||||
const tsdict = await contest.getListStatus(
|
||||
this.user._id, tdocs.map((tdoc) => tdoc._id),
|
||||
@@ -40,7 +39,7 @@ class HomeHandler extends Handler {
|
||||
if (this.user.hasPerm(PERM_VIEW_TRAINING)) {
|
||||
const tdocs = await training.getMulti()
|
||||
.sort('_id', 1)
|
||||
.limit(TRAININGS_ON_MAIN)
|
||||
.limit(await system.get('TRAININGS_ON_MAIN'))
|
||||
.toArray();
|
||||
const tsdict = await training.getListStatus(
|
||||
this.user._id, tdocs.map((tdoc) => tdoc._id),
|
||||
@@ -53,7 +52,7 @@ class HomeHandler extends Handler {
|
||||
async discussion() {
|
||||
if (this.user.hasPerm(PERM_VIEW_DISCUSSION)) {
|
||||
const ddocs = await discussion.getMulti()
|
||||
.limit(DISCUSSIONS_ON_MAIN)
|
||||
.limit(await system.get('DISCUSSIONS_ON_MAIN'))
|
||||
.toArray();
|
||||
const vndict = await discussion.getListVnodes(ddocs, this);
|
||||
return [ddocs, vndict];
|
||||
@@ -106,7 +105,7 @@ class HomeSecurityHandler extends Handler {
|
||||
if (udoc) throw new UserAlreadyExistError(mail);
|
||||
const [rid] = await token.add(
|
||||
token.TYPE_CHANGEMAIL,
|
||||
options.changemail_token_expire_seconds,
|
||||
await system.get('changemail_token_expire_seconds'),
|
||||
{ uid: this.udoc._id, mail },
|
||||
);
|
||||
await mail.sendMail(mail, 'Change Email', 'user_changemail_mail.html', {
|
||||
|
||||
@@ -15,7 +15,6 @@ const {
|
||||
NoProblemError, ProblemDataNotFoundError, BadRequestError,
|
||||
SolutionNotFoundError,
|
||||
} = require('../error');
|
||||
const { constants } = require('../options');
|
||||
const {
|
||||
PERM_VIEW_PROBLEM, PERM_VIEW_PROBLEM_HIDDEN, PERM_SUBMIT_PROBLEM,
|
||||
PERM_CREATE_PROBLEM, PERM_READ_PROBLEM_DATA, PERM_EDIT_PROBLEM,
|
||||
@@ -38,7 +37,7 @@ class ProblemHandler extends Handler {
|
||||
const [pdocs, pcount] = await paginate(
|
||||
problem.getMulti(q).sort({ pid: 1 }),
|
||||
page,
|
||||
constants.PROBLEM_PER_PAGE,
|
||||
await system.get('PROBLEM_PER_PAGE'),
|
||||
);
|
||||
if (this.user.hasPerm(PERM_LOGGEDIN)) {
|
||||
psdict = await problem.getListStatus(this.user._id, pdocs.map((pdoc) => pdoc._id));
|
||||
@@ -252,7 +251,8 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
|
||||
this.checkPerm(PERM_VIEW_PROBLEM_SOLUTION);
|
||||
const [psdocs, pcount, pscount] = await paginate(
|
||||
solution.getMulti(this.pdoc._id),
|
||||
page, constants.SOLUTION_PER_PAGE,
|
||||
page,
|
||||
await system.get('SOLUTION_PER_PAGE'),
|
||||
);
|
||||
const uids = [this.pdoc.owner]; const
|
||||
docids = [];
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const { constants } = require('../options');
|
||||
const {
|
||||
PERM_READ_RECORD_CODE, PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD,
|
||||
PERM_REJUDGE, PERM_VIEW_PROBLEM_HIDDEN,
|
||||
@@ -6,6 +5,7 @@ const {
|
||||
const problem = require('../model/problem');
|
||||
const record = require('../model/record');
|
||||
const contest = require('../model/contest');
|
||||
const system = require('../model/system');
|
||||
const user = require('../model/user');
|
||||
const bus = require('../service/bus');
|
||||
const {
|
||||
@@ -16,7 +16,7 @@ class RecordListHandler extends Handler {
|
||||
async get({ page = 1 }) {
|
||||
this.response.template = 'record_main.html';
|
||||
const q = {};
|
||||
const rdocs = await record.getMany(q, { _id: -1 }, page, constants.RECORD_PER_PAGE);
|
||||
const rdocs = await record.getMany(q, { _id: -1 }, page, await system.get('RECORD_PER_PAGE'));
|
||||
const pdict = {};
|
||||
const udict = {};
|
||||
const ulist = [];
|
||||
|
||||
@@ -4,12 +4,12 @@ const {
|
||||
PERM_LOGGEDIN, PERM_VIEW_TRAINING, PERM_VIEW_PROBLEM_HIDDEN,
|
||||
PERM_CREATE_TRAINING, PERM_EDIT_TRAINING,
|
||||
} = require('../permission');
|
||||
const { constants } = require('../options');
|
||||
const paginate = require('../lib/paginate');
|
||||
const problem = require('../model/problem');
|
||||
const builtin = require('../model/builtin');
|
||||
const training = require('../model/training');
|
||||
const user = require('../model/user');
|
||||
const system = require('../model/system');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
|
||||
async function _parseDagJson(dag) {
|
||||
@@ -60,7 +60,7 @@ class TrainingMainHandler extends TrainingHandler {
|
||||
const [tdocs, tpcount] = await paginate(
|
||||
training.getMulti().sort('_id', 1),
|
||||
page,
|
||||
constants.TRAINING_PER_PAGE,
|
||||
await system.get('TRAINING_PER_PAGE'),
|
||||
);
|
||||
const tids = new Set();
|
||||
for (const tdoc of tdocs) tids.add(tdoc._id);
|
||||
|
||||
+6
-14
@@ -4,7 +4,6 @@ const token = require('../model/token');
|
||||
const system = require('../model/system');
|
||||
const { sendMail } = require('../lib/mail');
|
||||
const misc = require('../lib/misc');
|
||||
const options = require('../options');
|
||||
const { PERM_REGISTER_USER, PERM_LOGGEDIN } = require('../permission');
|
||||
const {
|
||||
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
||||
@@ -58,10 +57,10 @@ class UserRegisterHandler extends Handler {
|
||||
this.limitRate('send_mail', 3600, 30);
|
||||
const t = await token.add(
|
||||
token.TYPE_REGISTRATION,
|
||||
options.registration_token_expire_seconds,
|
||||
await system.get('registration_token_expire_seconds'),
|
||||
{ mail },
|
||||
);
|
||||
if (options.smtp.user) {
|
||||
if (await system.get('smtp.user')) {
|
||||
const m = await this.renderHTML('user_register_mail', { url: `/register/${t}` });
|
||||
await sendMail(mail, 'Sign Up', 'user_register_mail', m);
|
||||
this.response.template = 'user_register_mail_sent.html';
|
||||
@@ -100,21 +99,18 @@ class UserRegisterWithCodeHandler extends Handler {
|
||||
}
|
||||
|
||||
class UserLostPassHandler extends Handler {
|
||||
constructor(ctx) {
|
||||
if (!options.smtp.user) throw new SystemError('Cannot send mail');
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
async get() {
|
||||
if (!await system.get('smtp.user')) throw new SystemError('Cannot send mail');
|
||||
this.response.template = 'user_lostpass.html';
|
||||
}
|
||||
|
||||
async post({ mail }) {
|
||||
if (!await system.get('smtp.user')) throw new SystemError('Cannot send mail');
|
||||
const udoc = await user.getByEmail(mail);
|
||||
if (!udoc) throw new UserNotFoundError(mail);
|
||||
const tid = await token.add(
|
||||
token.TYPE_LOSTPASS,
|
||||
options.lostpass_token_expire_seconds,
|
||||
await system.get('lostpass_token_expire_seconds'),
|
||||
{ uid: udoc._id },
|
||||
);
|
||||
const m = await this.renderHTML('user_lostpass_mail', { url: `/lostpass/${tid}`, uname: udoc.uname });
|
||||
@@ -142,16 +138,12 @@ class UserLostPassWithCodeHandler extends Handler {
|
||||
}
|
||||
|
||||
class UserDetailHandler extends Handler {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
this.response.template = 'user_detail.html';
|
||||
}
|
||||
|
||||
async get({ uid }) {
|
||||
const isSelfProfile = this.user._id === uid;
|
||||
const udoc = await user.getById(uid);
|
||||
if (!udoc) throw new UserNotFoundError(uid);
|
||||
const sdoc = await token.getMostRecentSessionByUid(uid);
|
||||
this.response.template = 'user_detail.html';
|
||||
this.response.body = { isSelfProfile, udoc, sdoc };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user