Fix signin history (#5180)
* Fix #5179 * Fix wrong value in signin history
This commit is contained in:
parent
54ecf97c22
commit
a97c14a7b7
|
@ -2,6 +2,9 @@ import * as Koa from 'koa';
|
||||||
|
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
|
import { Signins } from '../../../models';
|
||||||
|
import { genId } from '../../../misc/gen-id';
|
||||||
|
import { publishMainStream } from '../../../services/stream';
|
||||||
|
|
||||||
export default function(ctx: Koa.BaseContext, user: ILocalUser, redirect = false) {
|
export default function(ctx: Koa.BaseContext, user: ILocalUser, redirect = false) {
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
|
@ -24,4 +27,19 @@ export default function(ctx: Koa.BaseContext, user: ILocalUser, redirect = false
|
||||||
ctx.body = { i: user.token };
|
ctx.body = { i: user.token };
|
||||||
ctx.status = 200;
|
ctx.status = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// Append signin history
|
||||||
|
const record = await Signins.save({
|
||||||
|
id: genId(),
|
||||||
|
createdAt: new Date(),
|
||||||
|
userId: user.id,
|
||||||
|
ip: ctx.ip,
|
||||||
|
headers: ctx.headers,
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Publish signin event
|
||||||
|
publishMainStream(user.id, 'signin', await Signins.pack(record));
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ export default async (ctx: Koa.BaseContext) => {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
ip: ctx.ip,
|
ip: ctx.ip,
|
||||||
headers: ctx.headers,
|
headers: ctx.headers,
|
||||||
success: !!(status || failure)
|
success: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// Publish signin event
|
// Publish signin event
|
||||||
|
|
Loading…
Reference in New Issue