From a97c14a7b7b306e2ffee56642be93d90814ee299 Mon Sep 17 00:00:00 2001 From: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com> Date: Thu, 18 Jul 2019 04:22:44 +0900 Subject: [PATCH] Fix signin history (#5180) * Fix #5179 * Fix wrong value in signin history --- src/server/api/common/signin.ts | 18 ++++++++++++++++++ src/server/api/private/signin.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/server/api/common/signin.ts b/src/server/api/common/signin.ts index 0f4ee4ca1..37229ad1b 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 eb267aa60..1e0694368 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