This commit is contained in:
undefined committed 2020-05-03 18:22:31 +08:00
1 parent 627e64a901
commit 1df19a7aa9
17 files changed
+62 -105

No files matched your search

+5 -4
View File
@@ -80,11 +80,12 @@ class HomeSecurityHandler extends Handler {
async get() {
// TODO(iceboy): pagination? or limit session count for uid?
// TODO(masnn): UA & IP
const sessions = await token.getSessionListByUid(this.user._id);
const parsed = sessions.map((session) => ({
...session,
updateUa: useragent.parse(session.updateUa || session.createUa || ''),
updateGeoip: geoip.ip2geo(session.updateIp || session.createIp, this.user.viewLang),
// updateUa: useragent.parse(session.updateUa || session.createUa || ''),
// updateGeoip: geoip.ip2geo(session.updateIp || session.createIp, this.user.viewLang),
_id: md5(session._id),
isCurrent: session._id === this.session._id,
}));
@@ -116,7 +117,7 @@ class HomeSecurityHandler extends Handler {
async postDeleteToken({ tokenDigest }) {
const sessions = await token.getSessionListByUid(this.user._id);
for (const session in sessions) {
for (const session of sessions) {
if (tokenDigest === md5(session._id)) {
// eslint-disable-next-line no-await-in-loop
await token.delete(session._id, token.TYPE_SESSION);
@@ -128,7 +129,7 @@ class HomeSecurityHandler extends Handler {
async postDeleteAllTokens() {
await token.deleteByUid(this.user._id);
this.back();
this.response.redirect = '/login';
}
}
-1
View File
@@ -29,7 +29,6 @@ class ProblemImportHandler extends Handler {
if (pid) pdoc.pid = pid;
if (hidden) pdoc.hidden = true;
const _id = await problem.add(pdoc);
console.log(_id);
await problem.setTestdata(_id, testdata);
this.response.body = { pid: pid || _id };
this.response.redirect = `/p/${pid || _id}/settings`;
+11 -10
View File
@@ -32,25 +32,26 @@ class ProblemHandler extends Handler {
this.checkPerm(PERM_VIEW_PROBLEM);
}
async get({ page = 1, category = null }) {
async get({ page = 1, category = '' }) {
this.response.template = 'problem_main.html';
const q = {};
let psdict = {};
if (category) q.category = category;
if (!this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) q.hidden = false;
const pdocs = await problem.getMany(q, { pid: 1 }, page, constants.PROBLEM_PER_PAGE);
const [pdocs, pcount] = await paginate(
problem.getMulti(q).sort({ pid: 1 }),
page,
constants.PROBLEM_PER_PAGE,
);
if (this.user.hasPerm(PERM_LOGGEDIN)) {
psdict = await problem.getListStatus(this.user._id, pdocs.map((pdoc) => pdoc._id));
}
const path = [
['Hydro', '/'],
['problem_main', null],
];
this.response.body = {
path: [
['Hydro', '/'],
['problem_main', null],
],
page,
pdocs,
psdict,
category: '',
path, page, pcount, pdocs, psdict, category,
};
}
}
+1
View File
@@ -38,6 +38,7 @@ module.exports = {
gravatar: misc.gravatar,
model,
Context: global.Hydro.ui,
isIE: (str) => str.includes('MSIE') || str.includes('rv:11.0'),
});
return new Promise((resolve, reject) => {
env.render(name, state, (err, res) => {
+3 -15
View File
@@ -11,13 +11,13 @@ const Setting = (
});
const PREFERENCE_SETTINGS = [
Setting('setting_display', 'view_lang', i18n,
Setting('setting_display', 'viewLang', i18n,
options.default_locale, 'select', 'UI Language'),
Setting('setting_display', 'timezone', [], // TODO(masnn) timezone
'Asia/Shanghai', 'select', 'Timezone'),
Setting('setting_usage', 'code_lang', builtin.LANG_TEXTS,
Setting('setting_usage', 'codeLang', builtin.LANG_TEXTS,
null, 'select', 'Default Code Language'),
Setting('setting_usage', 'code_template', null,
Setting('setting_usage', 'codeTemplate', null,
null, 'textarea', 'Default Code Template',
'If left blank, the built-in template of the corresponding language will be used.'),
];
@@ -28,22 +28,10 @@ const ACCOUNT_SETTINGS = [
'We use <a href="https://en.gravatar.com/" target="_blank">Gravatar</a> to present your avatar icon.'),
Setting('setting_info', 'qq', null,
null, null, 'QQ'),
Setting('setting_info', 'wechat', null,
null, null, 'WeChat'),
Setting('setting_info', 'gender', builtin.USER_GENDER_RANGE,
null, 'select', 'Gender'),
Setting('setting_info', 'bio', null,
null, 'markdown', 'Bio'),
Setting('setting_privacy', 'show_mail', builtin.PRIVACY_RANGE,
null, 'select', 'Email Visibility'),
Setting('setting_privacy', 'show_qq', builtin.PRIVACY_RANGE,
null, 'select', 'QQ Visibility'),
Setting('setting_privacy', 'show_wechat', builtin.PRIVACY_RANGE,
null, 'select', 'WeChat Visibility'),
Setting('setting_privacy', 'show_gender', builtin.PRIVACY_RANGE,
null, 'select', 'Gender Visibility'),
Setting('setting_privacy', 'show_bio', builtin.PRIVACY_RANGE,
null, 'select', 'Bio Visibility'),
Setting('setting_customize', 'background_img', builtin.BACKGROUND_RANGE,
null, 'image_radio', 'Profile Background Image',
'Choose the background image in your profile page.',
+2 -2
View File
@@ -77,9 +77,9 @@ module.exports = {
return coll.deleteMany({ uid });
},
getMostRecentSessionByUid(uid) {
return coll.findOne({ uid, token_type: this.TYPE_SESSION }, { sort: { updateAt: -1 } });
return coll.findOne({ uid, tokenType: this.TYPE_SESSION }, { sort: { updateAt: -1 } });
},
getSessionListByUid(uid) {
return coll.find({ uid, token_type: this.TYPE_SESSION }).sort('updateAt', -1).toArray();
return coll.find({ uid, tokenType: this.TYPE_SESSION }).sort('updateAt', -1).toArray();
},
};
+9 -13
View File
@@ -128,13 +128,12 @@ class Handler {
this.now = new Date();
this._handler.sid = this.request.cookies.get('sid');
this._handler.save = this.request.cookies.get('save');
this._handler.tokenType = token.TYPE_SESSION;
if (this._handler.save) this._handler.expireSeconds = options.session.saved_expire_seconds;
else this._handler.expireSeconds = options.session.unsaved_expire_seconds;
this.session = this._handler.sid
? await token.update(
this._handler.sid,
this._handler.tokenType,
token.TYPE_SESSION,
this._handler.expireSeconds,
{
update_ip: this.request.ip,
@@ -194,19 +193,16 @@ class Handler {
}
async saveCookie() {
if (this.session.sid) {
if (this.session._id) {
await token.update(
this.session.sid,
this._handler.tokenType,
this.session._id,
token.TYPE_SESSION,
this._handler.expireSeconds,
{
updateIp: this.request.ip,
updateUa: this.request.headers['user-agent'] || '',
},
this.session,
);
} else {
[this.session.sid] = await token.add(
this._handler.tokenType,
[this.session._id] = await token.add(
token.TYPE_SESSION,
this._handler.expireSeconds,
{
createIp: this.request.ip,
@@ -221,9 +217,9 @@ class Handler {
if (this._handler.save) {
cookie.expires = this.session.expireAt;
cookie.maxAge = this._handler.expireSeconds;
this.request.cookies.set('save', 'true', cookie);
this.ctx.cookies.set('save', 'true', cookie);
}
this.ctx.cookies.set('sid', this.session.sid, cookie);
this.ctx.cookies.set('sid', this.session._id, cookie);
}
async onerror(error) {