Fix signin history (#5180)

* Fix #5179

* Fix wrong value in signin history
This commit is contained in:
Satsuki Yanagi 2019-07-18 04:22:44 +09:00 committed by syuilo
parent 69263b5b68
commit 9e31812bd2
2 changed files with 19 additions and 1 deletions

View File

@ -2,6 +2,9 @@ import * as Koa from 'koa';
import config from '../../../config';
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) {
if (redirect) {
@ -24,4 +27,19 @@ export default function(ctx: Koa.BaseContext, user: ILocalUser, redirect = false
ctx.body = { i: user.token };
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));
})();
}

View File

@ -61,7 +61,7 @@ export default async (ctx: Koa.BaseContext) => {
userId: user.id,
ip: ctx.ip,
headers: ctx.headers,
success: !!(status || failure)
success: false
});
// Publish signin event