新增加验证码开关
This commit is contained in:
parent
5e65941e15
commit
e5bbf0b298
@ -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
|
||||
/// <param name="configKey"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("configKey/{configKey}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetConfigKey(string configKey)
|
||||
{
|
||||
//TODO 增加缓存
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -12,5 +12,6 @@ namespace ZR.Service.System
|
||||
/// </summary>
|
||||
public interface ISysConfigService: IBaseService<SysConfig>
|
||||
{
|
||||
SysConfig GetSysConfigByKey(string key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,11 @@ namespace ZR.Service.System
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
public SysConfig GetSysConfigByKey(string key)
|
||||
{
|
||||
return _SysConfigrepository.Queryable().First(f => f.ConfigKey == key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -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';
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="code">
|
||||
<el-form-item prop="code" v-if="showCaptcha != 'off'">
|
||||
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin" ref="codeTxt">
|
||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
||||
</el-input>
|
||||
@ -38,7 +38,7 @@
|
||||
<script>
|
||||
import { getCodeImg } from "@/api/system/login";
|
||||
import Cookies from "js-cookie";
|
||||
import { encrypt, decrypt } from "@/utils/jsencrypt";
|
||||
// import { encrypt, decrypt } from "@/utils/jsencrypt";
|
||||
import defaultSettings from "@/settings";
|
||||
|
||||
export default {
|
||||
@ -66,6 +66,7 @@ export default {
|
||||
{ required: true, trigger: "change", message: "验证码不能为空" },
|
||||
],
|
||||
},
|
||||
showCaptcha: '',
|
||||
loading: false,
|
||||
redirect: undefined,
|
||||
};
|
||||
@ -81,6 +82,9 @@ export default {
|
||||
created() {
|
||||
this.getCode();
|
||||
this.getCookie();
|
||||
this.getConfigKey("sys.account.captchaOnOff").then((response) => {
|
||||
this.showCaptcha = response.data;
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
getCode() {
|
||||
|
||||
@ -525,7 +525,7 @@ CREATE TABLE `sys_user` (
|
||||
-- ----------------------------
|
||||
INSERT INTO `sys_user` VALUES (1, 0, 'admin', '管理员', '0', '', '', '0', '', 'e10adc3949ba59abbe56e057f20f883e', '0', '0', '127.0.0.1', '2021-08-23 14:03:17', 'admin', '2020-11-26 11:52:59', 'admin', '2021-08-03 10:11:24', '管理员');
|
||||
INSERT INTO `sys_user` VALUES (2, 0, 'zr', 'zr', '0', NULL, NULL, '0', '', 'e10adc3949ba59abbe56e057f20f883e', '0', '0', '', '0001-01-01 00:00:00', 'admin', '2021-07-05 17:29:13', 'admin', '2021-08-02 16:53:04', '普通用户2');
|
||||
INSERT INTO `sys_user` VALUES (3, 100, 'editor', '编辑人员', '0', NULL, NULL, '2', 'http://www.izhaorui.cn/static/pay.jpg', 'E10ADC3949BA59ABBE56E057F20F883E', '0', '0', '127.0.0.1', '2021-08-19 09:27:46', 'admin', '2021-08-18 18:24:53', '', NULL, NULL);
|
||||
INSERT INTO `sys_user` VALUES (3, 100, 'editor', '编辑人员', '0', NULL, NULL, '2', '', 'E10ADC3949BA59ABBE56E057F20F883E', '0', '0', '127.0.0.1', '2021-08-19 09:27:46', 'admin', '2021-08-18 18:24:53', '', NULL, NULL);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@ -636,7 +636,7 @@ create table sys_config (
|
||||
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'admin', sysdate(), '', null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
||||
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456' );
|
||||
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark,浅色主题theme-light' );
|
||||
-- insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能(true开启,false关闭)');
|
||||
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能(off、关闭,1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码)');
|
||||
|
||||
-- ----------------------------
|
||||
-- 18、代码生成业务表
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user