From 2bb55294fcb244f791f8e97e441370f80ebbf78a Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Tue, 31 Aug 2021 10:54:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=A4=E6=AD=A5=E9=AA=8C=E8=AF=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=A2=9E=E5=8A=A0ip=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/auth.ts | 7 ++++++- src/layouts/index.tsx | 9 +++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/back/services/auth.ts b/back/services/auth.ts index 8fc5ba30..1846d704 100644 --- a/back/services/auth.ts +++ b/back/services/auth.ts @@ -155,7 +155,7 @@ export default class AuthService { return isValid; } - public twoFactorLogin({ username, password, code }, req) { + public async twoFactorLogin({ username, password, code }, req) { const authInfo = this.getAuthInfo(); const isValid = authenticator.verify({ token: code, @@ -165,6 +165,11 @@ export default class AuthService { this.updateAuthInfo(authInfo, { twoFactorChecked: true }); return this.login({ username, password }, req); } else { + const { ip, address } = await getNetIp(req); + this.updateAuthInfo(authInfo, { + lastip: ip, + lastaddr: address, + }); return { code: 430, message: '验证失败' }; } } diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 7d0b0d37..cf6d3c3d 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -34,6 +34,9 @@ export default function (props: any) { .then((data) => { if (data.data.username) { setUser(data.data); + if (props.location.pathname === '/') { + history.push('/crontab'); + } } }) .catch((e) => { @@ -56,12 +59,6 @@ export default function (props: any) { document.title = '控制面板'; }, []); - useEffect(() => { - if (props.location.pathname === '/') { - history.push('/crontab'); - } - }, [props.location.pathname]); - useEffect(() => { const _theme = localStorage.getItem('qinglong_dark_theme') || 'auto'; setFetchMethod(window.fetch);