core: 优化注册逻辑以防止在token失效时丢出系统级错误

This commit is contained in:
undefined committed 2021-01-08 22:04:25 +08:00
1 parent ba94c59e3f
commit c3b314f8dd
4 files changed
+5 -8

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.15.13", "version": "2.15.14",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+1 -1
View File
@@ -158,7 +158,7 @@ class HomeSecurityHandler extends Handler {
if (udoc) throw new UserAlreadyExistError(email); if (udoc) throw new UserAlreadyExistError(email);
const [code] = await token.add( const [code] = await token.add(
token.TYPE_CHANGEMAIL, token.TYPE_CHANGEMAIL,
system.get('changemail_token_expire_seconds'), system.get('session.unsaved_expire_seconds'),
{ uid: this.user._id, email }, { uid: this.user._id, email },
); );
const m = await this.renderHTML('user_changemail_mail.html', { const m = await this.renderHTML('user_changemail_mail.html', {
+3 -3
View File
@@ -97,10 +97,10 @@ class UserRegisterWithCodeHandler extends Handler {
domainId: string, password: string, verify: string, domainId: string, password: string, verify: string,
uname: string, code: string, uname: string, code: string,
) { ) {
const { mail } = await token.get(code, token.TYPE_REGISTRATION); const tdoc = await token.get(code, token.TYPE_REGISTRATION);
if (!mail) throw new InvalidTokenError(token.TYPE_REGISTRATION, code); if (!tdoc || !tdoc.mail) throw new InvalidTokenError(token.TYPE_REGISTRATION, code);
if (password !== verify) throw new VerifyPasswordError(); if (password !== verify) throw new VerifyPasswordError();
const uid = await user.create(mail, uname, password, undefined, this.request.ip); const uid = await user.create(tdoc.mail, uname, password, undefined, this.request.ip);
await token.del(code, token.TYPE_REGISTRATION); await token.del(code, token.TYPE_REGISTRATION);
this.session.uid = uid; this.session.uid = uid;
this.session.scpoe = PERM.PERM_ALL; this.session.scpoe = PERM.PERM_ALL;
-3
View File
@@ -36,9 +36,6 @@ export interface SystemKeys {
'session.secure': boolean, 'session.secure': boolean,
'session.expire_seconds': number, 'session.expire_seconds': number,
'session.unsaved_expire_seconds': number, 'session.unsaved_expire_seconds': number,
'lostpass_token_expire_seconds': number,
'registration_token_expire_seconds': number,
'changemail_token_expire_seconds': number,
'user.quota': number, 'user.quota': number,
} }