diff --git a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs index 6a48e29..3bd9a6a 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysConfigController.cs @@ -17,6 +17,7 @@ using ZR.Common; using ZR.Service.System; using ZR.Model.System; using Infrastructure.Extensions; +using Microsoft.AspNetCore.Authorization; namespace ZR.Admin.WebApi.Controllers { @@ -83,6 +84,7 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpGet("configKey/{configKey}")] + [AllowAnonymous] public IActionResult GetConfigKey(string configKey) { //TODO 增加缓存 diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 13cfd24..b76f953 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -15,6 +15,7 @@ using ZR.Model.System.Dto; using ZR.Service.System.IService; using Hei.Captcha; using ZR.Common; +using ZR.Service.System; namespace ZR.Admin.WebApi.Controllers.System { @@ -30,6 +31,7 @@ namespace ZR.Admin.WebApi.Controllers.System private readonly ISysLoginService sysLoginService; private readonly ISysPermissionService permissionService; private readonly SecurityCodeHelper SecurityCodeHelper; + private readonly ISysConfigService sysConfigService; public SysLoginController( IHttpContextAccessor contextAccessor, @@ -37,6 +39,7 @@ namespace ZR.Admin.WebApi.Controllers.System ISysUserService sysUserService, ISysLoginService sysLoginService, ISysPermissionService permissionService, + ISysConfigService configService, SecurityCodeHelper captcha) { httpContextAccessor = contextAccessor; @@ -45,6 +48,7 @@ namespace ZR.Admin.WebApi.Controllers.System this.sysUserService = sysUserService; this.sysLoginService = sysLoginService; this.permissionService = permissionService; + this.sysConfigService = configService; } @@ -60,7 +64,8 @@ namespace ZR.Admin.WebApi.Controllers.System { if (loginBody == null) { throw new CustomException("请求参数错误"); } loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext); - if (CacheHelper.Get(loginBody.Uuid) is string str && !str.ToLower().Equals(loginBody.Code.ToLower())) + SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); + if (sysConfig?.ConfigValue != "off" && CacheHelper.Get(loginBody.Uuid) is string str && !str.ToLower().Equals(loginBody.Code.ToLower())) { throw new CustomException(ResultCode.CAPTCHA_ERROR, "验证码错误"); } @@ -136,8 +141,26 @@ namespace ZR.Admin.WebApi.Controllers.System public ApiResult CaptchaImage() { string uuid = Guid.NewGuid().ToString().Replace("-", ""); + + SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); var code = SecurityCodeHelper.GetRandomEnDigitalText(4); - var imgByte = SecurityCodeHelper.GetEnDigitalCodeByte(code); + byte[] imgByte; + if (sysConfig.ConfigValue == "1") + { + imgByte = SecurityCodeHelper.GetGifEnDigitalCodeByte(code);//动态gif数字字母 + } + else if (sysConfig.ConfigValue == "2") + { + imgByte = SecurityCodeHelper.GetGifBubbleCodeByte(code);//动态gif泡泡 + } + else if (sysConfig.ConfigValue == "3") + { + imgByte = SecurityCodeHelper.GetBubbleCodeByte(code);//泡泡 + } + else + { + imgByte = SecurityCodeHelper.GetEnDigitalCodeByte(code);//英文字母加数字 + } string base64Str = Convert.ToBase64String(imgByte); CacheHelper.SetCache(uuid, code); var obj = new { uuid, img = base64Str };// File(stream, "image/png") diff --git a/ZR.Service/Business/IBusService/ISysConfigService.cs b/ZR.Service/Business/IBusService/ISysConfigService.cs index 182b403..a8c68f8 100644 --- a/ZR.Service/Business/IBusService/ISysConfigService.cs +++ b/ZR.Service/Business/IBusService/ISysConfigService.cs @@ -12,5 +12,6 @@ namespace ZR.Service.System /// public interface ISysConfigService: IBaseService { + SysConfig GetSysConfigByKey(string key); } } diff --git a/ZR.Service/System/SysConfigService.cs b/ZR.Service/System/SysConfigService.cs index b477dda..9b2f8a5 100644 --- a/ZR.Service/System/SysConfigService.cs +++ b/ZR.Service/System/SysConfigService.cs @@ -18,6 +18,11 @@ namespace ZR.Service.System #region 业务逻辑代码 + public SysConfig GetSysConfigByKey(string key) + { + return _SysConfigrepository.Queryable().First(f => f.ConfigKey == key); + } + #endregion } } \ No newline at end of file diff --git a/ZR.Vue/src/utils/request.js b/ZR.Vue/src/utils/request.js index 53a54de..85dd568 100644 --- a/ZR.Vue/src/utils/request.js +++ b/ZR.Vue/src/utils/request.js @@ -54,7 +54,7 @@ service.interceptors.response.use(res => { } ).then(() => { store.dispatch('LogOut').then(() => { - location.href = process.env.VUE_APP_ROUTER_PREFIX + '/index'; + location.href = '/index'; }) }) diff --git a/ZR.Vue/src/views/login.vue b/ZR.Vue/src/views/login.vue index edfe6bc..86c89b3 100644 --- a/ZR.Vue/src/views/login.vue +++ b/ZR.Vue/src/views/login.vue @@ -12,7 +12,7 @@ - + @@ -38,7 +38,7 @@