diff --git a/src/server/api/common/signin.ts b/src/server/api/common/signin.ts index 0f4ee4ca11..37229ad1bc 100644 --- a/src/server/api/common/signin.ts +++ b/src/server/api/common/signin.ts @@ -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)); + })(); } diff --git a/src/server/api/private/signin.ts b/src/server/api/private/signin.ts index eb267aa604..1e0694368f 100644 --- a/src/server/api/private/signin.ts +++ b/src/server/api/private/signin.ts @@ -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