From ef4e34c584216f294f3c507bf0a2f6500014edb9 Mon Sep 17 00:00:00 2001 From: "meilin.huang" <954537473@qq.com> Date: Sat, 17 Jun 2023 15:15:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8F=8C=E5=9B=A0?= =?UTF-8?q?=E7=B4=A0=E6=A0=A1=E9=AA=8C(OTP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mayfly_go_web/package.json | 1 + mayfly_go_web/src/common/openApi.ts | 1 + mayfly_go_web/src/common/sysconfig.ts | 27 +++- .../views/login/component/AccountLogin.vue | 110 +++++++++++-- .../src/views/system/account/AccountList.vue | 30 ++-- mayfly_go_web/src/views/system/api.ts | 1 + .../src/views/system/config/ConfigList.vue | 65 ++++---- mayfly_go_web/yarn.lock | 5 + server/config.yml | 2 +- server/go.mod | 2 + server/internal/sys/api/account.go | 146 ++++++++++++++++-- server/internal/sys/api/form/form.go | 5 + server/internal/sys/application/config.go | 2 +- server/internal/sys/domain/entity/account.go | 1 + server/internal/sys/domain/entity/config.go | 53 ++++++- server/internal/sys/router/account.go | 14 ++ server/internal/sys/router/config.go | 2 + server/mayfly-go.sql | 8 +- server/pkg/cache/str_cache.go | 61 ++++++-- server/pkg/cache/timed_cache.go | 8 +- server/pkg/otp/otp.go | 19 +++ server/pkg/starter/redis.go | 2 +- server/pkg/utils/crypto.go | 8 +- 23 files changed, 462 insertions(+), 111 deletions(-) create mode 100644 server/pkg/otp/otp.go diff --git a/mayfly_go_web/package.json b/mayfly_go_web/package.json index cb695586..718a8f7c 100644 --- a/mayfly_go_web/package.json +++ b/mayfly_go_web/package.json @@ -24,6 +24,7 @@ "monaco-themes": "^0.4.4", "nprogress": "^0.2.0", "pinia": "^2.1.3", + "qrcode.vue": "^3.4.0", "screenfull": "^6.0.2", "sortablejs": "^1.13.0", "sql-formatter": "^12.1.2", diff --git a/mayfly_go_web/src/common/openApi.ts b/mayfly_go_web/src/common/openApi.ts index c5cf61ef..44694164 100644 --- a/mayfly_go_web/src/common/openApi.ts +++ b/mayfly_go_web/src/common/openApi.ts @@ -2,6 +2,7 @@ import Api from './Api' export default { login: Api.newPost("/sys/accounts/login"), + otpVerify: Api.newPost("/sys/accounts/otp-verify"), changePwd: Api.newPost("/sys/accounts/change-pwd"), getPublicKey: Api.newGet("/common/public-key"), getConfigValue: Api.newGet("/sys/configs/value"), diff --git a/mayfly_go_web/src/common/sysconfig.ts b/mayfly_go_web/src/common/sysconfig.ts index 60e25058..1891b352 100644 --- a/mayfly_go_web/src/common/sysconfig.ts +++ b/mayfly_go_web/src/common/sysconfig.ts @@ -1,6 +1,7 @@ import openApi from './openApi'; // 登录是否使用验证码配置key +const AccountLoginSecurity = "AccountLoginSecurity" const UseLoginCaptchaConfigKey = "UseLoginCaptcha" const UseWartermarkConfigKey = "UseWartermark" @@ -22,11 +23,24 @@ export async function getConfigValue(key: string) : Promise { * @returns 是否为ture,1: true;其他: false */ export async function getBoolConfigValue(key :string, defaultValue :boolean) : Promise { - const value = await getConfigValue(key) + const value = await getConfigValue(key); + return convertBool(value, defaultValue); +} + +/** + * 获取账号登录安全配置 + * + * @returns + */ +export async function getAccountLoginSecurity() : Promise { + const value = await getConfigValue(AccountLoginSecurity); if (!value) { - return defaultValue; + return null; } - return value == "1"; + const jsonValue = JSON.parse(value); + jsonValue.useCaptcha = convertBool(jsonValue.useCaptcha, true); + jsonValue.useOtp = convertBool(jsonValue.useOtp, true); + return jsonValue; } /** @@ -45,4 +59,11 @@ export async function useLoginCaptcha() : Promise { */ export async function useWartermark() : Promise { return await getBoolConfigValue(UseWartermarkConfigKey, true) +} + +function convertBool(value: string, defaultValue: boolean) { + if (!value) { + return defaultValue; + } + return value == "1" || value == "true"; } \ No newline at end of file diff --git a/mayfly_go_web/src/views/login/component/AccountLogin.vue b/mayfly_go_web/src/views/login/component/AccountLogin.vue index a7440bd7..e7f8da2c 100644 --- a/mayfly_go_web/src/views/login/component/AccountLogin.vue +++ b/mayfly_go_web/src/views/login/component/AccountLogin.vue @@ -11,7 +11,7 @@ autocomplete="off" @keyup.enter="login" show-password> - + + + 提示:登录失败超过{{ accountLoginSecurity.loginFailCount }}次后将被限制{{ accountLoginSecurity.loginFailMin }}分钟内不可再次登录 +