Explorar el Código

验证码改为配置项

徐少年 hace 3 años
padre
commit
77cc029444

+ 1 - 0
.gitignore

@@ -32,3 +32,4 @@ node_modules/
 /Admin.NET/Admin.NET.Web.Core/Admin.NET.Web.Core.csproj.user
 /Admin.NET/Admin.NET.Web.Entry/Admin.NET.Web.Entry.csproj.user
 /Admin.NET/Admin.NET.Web.Entry/Properties/PublishProfiles
+/Web/package-lock.json

+ 3 - 2
Admin.NET/Admin.NET.Core/Admin.NET.Core.xml

@@ -192,6 +192,7 @@
             登录二次验证
             </summary>
         </member>
+        <!-- Badly formed XML comment ignored for member "F:Admin.NET.Core.CommonConst.SysCaptcha" -->
         <member name="F:Admin.NET.Core.CommonConst.SysOpLog">
             <summary>
             开启操作日志
@@ -4064,9 +4065,9 @@
             退出系统
             </summary>
         </member>
-        <member name="M:Admin.NET.Core.Service.SysAuthService.GetSecondVerFlag">
+        <member name="M:Admin.NET.Core.Service.SysAuthService.GetLoginConfig">
             <summary>
-            是否启用二次验证
+            登录配置
             </summary>
             <returns></returns>
         </member>

+ 6 - 0
Admin.NET/Admin.NET.Core/Const/CommonConst.cs

@@ -22,6 +22,12 @@ public class CommonConst
     public const string SysSecondVer = "sys_second_ver";
 
     /// <summary>
+    /// 开启图形验证码
+
+    /// </summary>
+    public const string SysCaptcha = "sys_captcha";
+
+    /// <summary>
     /// 开启操作日志
     /// </summary>
     public const string SysOpLog = "sys_oplog";

+ 1 - 0
Admin.NET/Admin.NET.Core/SeedData/SysConfigSeedData.cs

@@ -20,6 +20,7 @@ public class SysConfigSeedData : ISqlSugarEntitySeedData<SysConfig>
             new SysConfig{ Id=252885263003803, Name="操作日志", Code="sys_oplog", Value="True", SysFlag=YesNoEnum.Y, Remark="开启操作日志", OrderNo=4, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
             new SysConfig{ Id=252885263003804, Name="单点登录", Code="sys_single_login", Value="True", SysFlag=YesNoEnum.Y, Remark="开启单点登录", OrderNo=5, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
             new SysConfig{ Id=252885263003805, Name="登录二次验证", Code="sys_second_ver", Value="True", SysFlag=YesNoEnum.Y, Remark="登录二次验证", OrderNo=6, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
+            new SysConfig{ Id=252885263003806, Name="开启图形验证码", Code="sys_captcha", Value="True", SysFlag=YesNoEnum.Y, Remark="开启图形验证码", OrderNo=7, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
         };
     }
 }

+ 13 - 6
Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs

@@ -59,8 +59,13 @@ public class SysAuthService : IDynamicApiController, ITransient
         //var host = _httpContextAccessor.HttpContext.Request.Host;
 
         // 判断验证码
-        if (!_captcha.Validate(input.CodeId.ToString(), input.Code))
-            throw Oops.Oh(ErrorCodeEnum.D0009);
+        var captchaConfig = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysCaptcha);
+        if (captchaConfig == true)
+        {
+            // 判断验证码
+            if (!_captcha.Validate(input.CodeId.ToString(), input.Code))
+                throw Oops.Oh(ErrorCodeEnum.D0009);
+        }
 
         var encryptPasswod = MD5Encryption.Encrypt(input.Password);
 
@@ -193,15 +198,17 @@ public class SysAuthService : IDynamicApiController, ITransient
     }
 
     /// <summary>
-    /// 是否启用二次验证
+    /// 登录配置
     /// </summary>
     /// <returns></returns>
-    [HttpGet("/secondVerFlag")]
+    [HttpGet("/loginConfig")]
     [AllowAnonymous]
     [SuppressMonitor]
-    public async Task<bool> GetSecondVerFlag()
+    public async Task<dynamic> GetLoginConfig()
     {
-        return await _sysConfigService.GetConfigValue<bool>(CommonConst.SysSecondVer);
+        var secondVerEnabled = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysSecondVer);
+        var captchaEnabled = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysCaptcha);
+        return new { SecondVerEnabled = secondVerEnabled, CaptchaEnabled = captchaEnabled };
     }
 
     /// <summary>

+ 12 - 12
Web/src/api-services/apis/sys-auth-api.ts

@@ -192,12 +192,12 @@ export const SysAuthApiAxiosParamCreator = function (configuration?: Configurati
         },
         /**
          * 
-         * @summary 是否启用二次验证
+         * @summary 登录配置
          * @param {*} [options] Override http request option.
          * @throws {RequiredError}
          */
-        secondVerFlagGet: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
-            const localVarPath = `/secondVerFlag`;
+        loginConfigGet: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
+            const localVarPath = `/loginConfig`;
             // use dummy base URL string because the URL constructor only accepts absolute URLs.
             const localVarUrlObj = new URL(localVarPath, 'https://example.com');
             let baseOptions;
@@ -413,12 +413,12 @@ export const SysAuthApiFp = function(configuration?: Configuration) {
         },
         /**
          * 
-         * @summary 是否启用二次验证
+         * @summary 登录配置
          * @param {*} [options] Override http request option.
          * @throws {RequiredError}
          */
-        async secondVerFlagGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminResultBoolean>>> {
-            const localVarAxiosArgs = await SysAuthApiAxiosParamCreator(configuration).secondVerFlagGet(options);
+        async loginConfigGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminResultBoolean>>> {
+            const localVarAxiosArgs = await SysAuthApiAxiosParamCreator(configuration).loginConfigGet(options);
             return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
                 const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
                 return axios.request(axiosRequestArgs);
@@ -514,12 +514,12 @@ export const SysAuthApiFactory = function (configuration?: Configuration, basePa
         },
         /**
          * 
-         * @summary 是否启用二次验证
+         * @summary 登录配置
          * @param {*} [options] Override http request option.
          * @throws {RequiredError}
          */
-        async secondVerFlagGet(options?: AxiosRequestConfig): Promise<AxiosResponse<AdminResultBoolean>> {
-            return SysAuthApiFp(configuration).secondVerFlagGet(options).then((request) => request(axios, basePath));
+        async loginConfigGet(options?: AxiosRequestConfig): Promise<AxiosResponse<AdminResultBoolean>> {
+            return SysAuthApiFp(configuration).loginConfigGet(options).then((request) => request(axios, basePath));
         },
         /**
          * 
@@ -604,13 +604,13 @@ export class SysAuthApi extends BaseAPI {
     }
     /**
      * 
-     * @summary 是否启用二次验证
+     * @summary 登录配置
      * @param {*} [options] Override http request option.
      * @throws {RequiredError}
      * @memberof SysAuthApi
      */
-    public async secondVerFlagGet(options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminResultBoolean>> {
-        return SysAuthApiFp(this.configuration).secondVerFlagGet(options).then((request) => request(this.axios, this.basePath));
+    public async loginConfigGet(options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminResultBoolean>> {
+        return SysAuthApiFp(this.configuration).loginConfigGet(options).then((request) => request(this.axios, this.basePath));
     }
     /**
      * 

+ 6 - 4
Web/src/views/login/component/account.vue

@@ -21,7 +21,7 @@
 				</template>
 			</el-input>
 		</el-form-item>
-		<el-form-item class="login-animation3" prop="captcha">
+		<el-form-item class="login-animation3" prop="captcha" v-show="state.captchaEnabled">
 			<el-col :span="15">
 				<el-input text maxlength="4" :placeholder="$t('message.account.accountPlaceholder3')" v-model="state.ruleForm.code" clearable autocomplete="off">
 					<template #prefix>
@@ -105,12 +105,14 @@ const state = reactive({
 	secondVerEnabled: true,
 	rotateVerifyVisible: false,
 	rotateVerifyImg: verifyImg,
+	captchaEnabled: true,
 	isPassRotate: false,
 });
 onMounted(async () => {
-	// 是否开启二次验证
-	var res1 = await getAPI(SysAuthApi).secondVerFlagGet();
-	state.secondVerEnabled = res1.data.result ?? true;
+	// 登录配置
+	var res1 = await getAPI(SysAuthApi).loginConfigGet();
+	state.secondVerEnabled = res1.data.result.secondVerEnabled ?? true;
+	state.captchaEnabled = res1.data.result.captchaEnabled ?? true;
 
 	getCaptcha();
 });