mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: auth/login event (#1181)
This commit is contained in:
1 parent
3ef155b938
commit
43fb00e3c7
2 files changed
+11
-2
No files matched your search
@@ -31,7 +31,10 @@ import {
|
||||
} from '../service/server';
|
||||
|
||||
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.session.viewLang = '';
|
||||
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.oauthBind = null;
|
||||
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 {
|
||||
|
||||
@@ -98,6 +98,9 @@ export interface EventMap {
|
||||
|
||||
'record/change': (rdoc: RecordDoc, $set?: any, $push?: any, body?: any) => void;
|
||||
'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) {
|
||||
|
||||
Reference in new issue
Block a user