From 9ab08a71c090d8415e3d44201b72b9df3049d8e9 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Sat, 25 Sep 2021 00:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E5=BD=95=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/auth.ts | 34 +++++++++++++++++++++++++--------- src/pages/login/index.tsx | 10 +++++++++- src/pages/setting/loginLog.tsx | 6 ++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/back/services/auth.ts b/back/services/auth.ts index d8805e2c..fb606051 100644 --- a/back/services/auth.ts +++ b/back/services/auth.ts @@ -50,6 +50,7 @@ export default class AuthService { twoFactorActivated, twoFactorActived, tokens = {}, + platform, } = content; // patch old field twoFactorActivated = twoFactorActivated || twoFactorActived; @@ -103,22 +104,29 @@ export default class AuthService { retries: 0, lastip: ip, lastaddr: address, + platform: req.platform, isTwoFactorChecking: false, }); await this.notificationService.notify( '登陆通知', - `你于${new Date( - timestamp, - ).toLocaleString()}在 ${address} 登陆成功,ip地址 ${ip}`, + `你于${new Date(timestamp).toLocaleString()}在 ${address} ${ + req.platform + }端 登陆成功,ip地址 ${ip}`, ); await this.getLoginLog(); await this.insertDb({ type: AuthDataType.loginLog, - info: { timestamp, address, ip, status: LoginStatus.success }, + info: { + timestamp, + address, + ip, + platform: req.platform, + status: LoginStatus.success, + }, }); return { code: 200, - data: { token, lastip, lastaddr, lastlogon, retries }, + data: { token, lastip, lastaddr, lastlogon, retries, platform }, }; } else { this.updateAuthInfo(content, { @@ -126,17 +134,24 @@ export default class AuthService { lastlogon: timestamp, lastip: ip, lastaddr: address, + platform: req.platform, }); await this.notificationService.notify( '登陆通知', - `你于${new Date( - timestamp, - ).toLocaleString()}在 ${address} 登陆失败,ip地址 ${ip}`, + `你于${new Date(timestamp).toLocaleString()}在 ${address} ${ + req.platform + }端 登陆失败,ip地址 ${ip}`, ); await this.getLoginLog(); await this.insertDb({ type: AuthDataType.loginLog, - info: { timestamp, address, ip, status: LoginStatus.fail }, + info: { + timestamp, + address, + ip, + platform: req.platform, + status: LoginStatus.fail, + }, }); return { code: 400, message: config.authError }; } @@ -243,6 +258,7 @@ export default class AuthService { this.updateAuthInfo(authInfo, { lastip: ip, lastaddr: address, + platform: req.platform, }); return { code: 430, message: '验证失败' }; } diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 418e6df5..bcf9e8e8 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -77,7 +77,14 @@ const Login = () => { const checkResponse = (data: any) => { if (data.code === 200) { - const { token, lastip, lastaddr, lastlogon, retries = 0 } = data.data; + const { + token, + lastip, + lastaddr, + lastlogon, + retries = 0, + platform, + } = data.data; localStorage.setItem(config.authKey, token); notification.success({ message: '登录成功!', @@ -89,6 +96,7 @@ const Login = () => {