删除用户功能

This commit is contained in:
undefined committed 2020-06-25 19:03:26 +08:00
1 parent 441eeadaf3
commit 39ea30664d
12 files changed
+159 -23

No files matched your search

+5 -2
View File
@@ -72,10 +72,13 @@ class DiscussionMainHandler extends Handler {
['Hydro', 'homepage'],
['discussion_main', null],
];
const vndict = await discussion.getListVnodes(domainId, ddocs, this);
const [vndict, vnodes] = await Promise.all([
discussion.getListVnodes(domainId, ddocs, this),
discussion.getNodes(domainId),
]);
this.response.template = 'discussion_main_or_node.html';
this.response.body = {
ddocs, dpcount, udict, page, page_name: 'discussion_main', vndict, vnode: {}, path,
ddocs, dpcount, udict, page, page_name: 'discussion_main', vndict, vnode: {}, path, vnodes,
};
}
}
+14 -8
View File
@@ -126,13 +126,23 @@ class ProblemCategoryHandler extends ProblemHandler {
}
class ProblemRandomHandler extends ProblemHandler {
async get({ domainId }) {
const q = {};
async get({ domainId, category }) {
const q = category[0] ? { $and: [] } : {};
for (const name of category) {
if (name) {
q.$and.push({
$or: [
{ category: { $elemMatch: { $eq: name } } },
{ tag: { $elemMatch: { $eq: name } } },
],
});
}
}
if (!this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) q.hidden = false;
const pid = await problem.random(domainId, q);
if (!pid) throw new NoProblemError();
this.response.body = { pid };
this.response.redirect = `/p/${pid}`;
this.response.redirect = this.url('problem_detail', { pid });
}
}
@@ -163,10 +173,6 @@ class ProblemDetailHandler extends ProblemHandler {
}
class ProblemSubmitHandler extends ProblemDetailHandler {
async prepare() {
this.checkPerm(PERM_SUBMIT_PROBLEM);
}
async get({ domainId, pid }) {
this.response.template = 'problem_submit.html';
const rdocs = await record.getUserInProblemMulti(domainId, this.user._id, this.pdoc.docId)
@@ -471,7 +477,7 @@ async function apply() {
Route('problem_category', '/p/category/:category', ProblemCategoryHandler);
Route('problem_random', '/problem/random', ProblemRandomHandler);
Route('problem_detail', '/p/:pid', ProblemDetailHandler);
Route('problem_submit', '/p/:pid/submit', ProblemSubmitHandler);
Route('problem_submit', '/p/:pid/submit', ProblemSubmitHandler, PERM_SUBMIT_PROBLEM);
Route('problem_pretest', '/p/:pid/pretest', ProblemPretestHandler);
Route('problem_settings', '/p/:pid/settings', ProblemSettingsHandler);
Route('problem_statistics', '/p/:pid/statistics', ProblemStatisticsHandler);
+12 -1
View File
@@ -68,7 +68,18 @@ class SystemSettingHandler extends SystemHandler {
if (typeof args[key] === 'object') {
const subtasks = [];
for (const sub in args[key]) {
subtasks.push(system.set(`${key}.${sub}`, args[key][sub]));
if (setting.SYSTEM_SETTINGS_BY_KEY[`${key}.${sub}`]) {
const s = setting.SYSTEM_SETTINGS_BY_KEY[`${key}.${sub}`];
if (s.ui === 'checkbox') {
if (args[key][sub] === 'on') {
subtasks.push(system.set(`${key}.${sub}`, true));
} else {
subtasks.push(system.set(`${key}.${sub}`, false));
}
} else {
subtasks.push(system.set(`${key}.${sub}`, args[key][sub]));
}
}
}
tasks.push(Promise.all(subtasks));
} else tasks.push(system.set(key, args[key]));
+20 -2
View File
@@ -1,7 +1,9 @@
const superagent = require('superagent');
const moment = require('moment-timezone');
const { Route, Handler } = require('../service/server.js');
const user = require('../model/user');
const token = require('../model/token');
const task = require('../model/task');
const system = require('../model/system');
const { sendMail } = require('../lib/mail');
const misc = require('../lib/misc');
@@ -10,6 +12,7 @@ const {
UserNotFoundError, LoginError, SystemError,
PermissionError, BlacklistedError, UserFacingError,
} = require('../error');
const { PERM_LOGGEDIN } = require('../permission.js');
class UserLoginHandler extends Handler {
async get() {
@@ -112,12 +115,12 @@ class UserLostPassHandler extends Handler {
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(
const [tid] = await token.add(
token.TYPE_LOSTPASS,
await system.get('lostpass_token_expire_seconds'),
{ uid: udoc._id },
);
const m = await this.renderHTML('user_lostpass_mail', { url: `/lostpass/${tid}`, uname: udoc.uname });
const m = await this.renderHTML('user_lostpass_mail', { url: `lostpass/${tid}`, uname: udoc.uname });
await sendMail(mail, 'Lost Password', 'user_lostpass_mail', m);
this.response.template = 'user_lostpass_mail_sent.html';
}
@@ -151,6 +154,20 @@ class UserDetailHandler extends Handler {
}
}
class UserDeleteHandler extends Handler {
async post({ password }) {
this.user.checkPassword(password);
const tid = await task.add({
executeAfter: moment().add(7, 'days').toDate(),
type: 'script',
id: 'deleteUser',
args: { uid: this.user._id },
});
await user.setById(this.user._id, { del: tid });
this.response.template = 'user_delete_pending.html';
}
}
class UserSearchHandler extends Handler {
async get({ domainId, q, exactMatch = false }) {
let udocs;
@@ -307,6 +324,7 @@ async function apply() {
Route('user_lostpass', '/lostpass', UserLostPassHandler);
Route('user_lostpass_with_code', '/lostpass/:code', UserLostPassWithCodeHandler);
Route('user_search', '/user/search', UserSearchHandler);
Route('user_delete', '/user/delete', UserDeleteHandler, PERM_LOGGEDIN);
Route('user_detail', '/user/:uid', UserDetailHandler);
}