core: auth/login event (#1181)

This commit is contained in:
Baoshuo authored and GitHub committed 2026-06-18 11:01:39 +08:00
1 parent 3ef155b938
commit 43fb00e3c7
2 files changed
+11 -2

No files matched your search

+8 -2
View File
@@ -31,7 +31,10 @@ import {
} from '../service/server'; } from '../service/server';
async function successfulAuth(this: Handler, udoc: User) { async function successfulAuth(this: Handler, udoc: User) {
if (udoc._id !== 0) await user.setById(udoc._id, { loginat: new Date(), loginip: this.request.ip }); if (udoc._id !== 0) {
await this.ctx.serial('auth/before-login', this, udoc);
await user.setById(udoc._id, { loginat: new Date(), loginip: this.request.ip });
}
this.context.HydroContext.user = udoc; this.context.HydroContext.user = udoc;
this.session.viewLang = ''; this.session.viewLang = '';
this.session.uid = udoc._id; this.session.uid = udoc._id;
@@ -40,7 +43,10 @@ async function successfulAuth(this: Handler, udoc: User) {
this.session.scope = PERM.PERM_ALL.toString(); this.session.scope = PERM.PERM_ALL.toString();
this.session.oauthBind = null; this.session.oauthBind = null;
this.session.recreate = true; this.session.recreate = true;
if (udoc._id !== 0) await oplog.log(this, 'user.loginSuccess', { uid: udoc._id }); if (udoc._id !== 0) {
await oplog.log(this, 'user.loginSuccess', { uid: udoc._id });
await this.ctx.serial('auth/login', this, udoc);
}
} }
class UserLoginHandler extends Handler { class UserLoginHandler extends Handler {
+3
View File
@@ -98,6 +98,9 @@ export interface EventMap {
'record/change': (rdoc: RecordDoc, $set?: any, $push?: any, body?: any) => void; 'record/change': (rdoc: RecordDoc, $set?: any, $push?: any, body?: any) => void;
'record/judge': (rdoc: RecordDoc, updated: boolean, pdoc?: ProblemDoc, updater?: any) => VoidReturn; 'record/judge': (rdoc: RecordDoc, updated: boolean, pdoc?: ProblemDoc, updater?: any) => VoidReturn;
'auth/before-login': (ctx: Handler, udoc: User) => VoidReturn;
'auth/login': (ctx: Handler, udoc: User) => VoidReturn;
} }
export function apply(ctx: Context) { export function apply(ctx: Context) {