diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java index 2f303ba9..46545165 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java @@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.framework.captcha.UnsignedMathGenerator; import com.ruoyi.framework.config.properties.CaptchaProperties; +import com.ruoyi.system.service.ISysConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit; /** * 验证码操作处理 * - * @author Lion Li + * @author ruoyi */ @RestController public class CaptchaController { @@ -47,15 +48,18 @@ public class CaptchaController { @Autowired private CaptchaProperties captchaProperties; + @Autowired + private ISysConfigService configService; + /** * 生成验证码 */ @GetMapping("/captchaImage") public AjaxResult getCode() { Map ajax = new HashMap<>(); - Boolean enabled = captchaProperties.getEnabled(); - ajax.put("enabled", enabled); - if (!enabled) { + boolean captchaOnOff = configService.selectCaptchaOnOff(); + ajax.put("captchaOnOff", captchaOnOff); + if (!captchaOnOff) { return AjaxResult.success(ajax); } // 保存验证码信息 diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index d0b9511e..47258ddd 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -12,6 +12,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.MessageUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.framework.config.properties.CaptchaProperties; +import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; @@ -46,6 +47,9 @@ public class SysLoginService @Autowired private ISysUserService userService; + @Autowired + private ISysConfigService configService; + @Autowired private AsyncService asyncService; @@ -60,20 +64,12 @@ public class SysLoginService */ public String login(String username, String password, String code, String uuid) { - HttpServletRequest request = ServletUtils.getRequest(); - if(captchaProperties.getEnabled()) { - String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; - String captcha = redisCache.getCacheObject(verifyKey); - redisCache.deleteObject(verifyKey); - if (captcha == null) { - asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request); - throw new CaptchaExpireException(); - } - if (!code.equalsIgnoreCase(captcha)) { - asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"), request); - throw new CaptchaException(); - } - } + boolean captchaOnOff = configService.selectCaptchaOnOff(); + // 验证码开关 + if (captchaOnOff) + { + validateCapcha(username, code, uuid); + } // 用户验证 Authentication authentication = null; try @@ -102,6 +98,29 @@ public class SysLoginService return tokenService.createToken(loginUser); } + /** + * 校验验证码 + * + * @param username 用户名 + * @param code 验证码 + * @param uuid 唯一标识 + * @return 结果 + */ + public void validateCapcha(String username, String code, String uuid) { + HttpServletRequest request = ServletUtils.getRequest(); + String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; + String captcha = redisCache.getCacheObject(verifyKey); + redisCache.deleteObject(verifyKey); + if (captcha == null) { + asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request); + throw new CaptchaExpireException(); + } + if (!code.equalsIgnoreCase(captcha)) { + asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"), request); + throw new CaptchaException(); + } + } + /** * 记录登录信息 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java index 429559b3..b649c7f8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java @@ -32,6 +32,13 @@ public interface ISysConfigService extends IServicePlus { */ public String selectConfigByKey(String configKey); + /** + * 获取验证码开关 + * + * @return true开启,false关闭 + */ + public boolean selectCaptchaOnOff(); + /** * 查询参数配置列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java index dd7321ad..41be8077 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java @@ -93,6 +93,19 @@ public class SysConfigServiceImpl extends ServicePlusImpl { - this.uploadType = "video"; - if (value) { - this.$refs.upload.$children[0].$refs.input.click(); - } else { - this.quill.format("video", false); - } - }); + // toolbar.addHandler("video", (value) => { + // this.uploadType = "video"; + // if (value) { + // this.$refs.upload.$children[0].$refs.input.click(); + // } else { + // this.quill.format("video", false); + // } + // }); } this.Quill.pasteHTML(this.currentValue); this.Quill.on("text-change", (delta, oldDelta, source) => { diff --git a/ruoyi-ui/src/components/ImageUpload/index.vue b/ruoyi-ui/src/components/ImageUpload/index.vue index f2a7402b..31940af2 100644 --- a/ruoyi-ui/src/components/ImageUpload/index.vue +++ b/ruoyi-ui/src/components/ImageUpload/index.vue @@ -116,7 +116,7 @@ export default { methods: { // 删除图片 handleRemove(file, fileList) { - const findex = this.fileList.indexOf(file.name); + const findex = this.fileList.map(f => f.name).indexOf(file.name); this.fileList.splice(findex, 1); this.$emit("input", this.listToString(this.fileList)); }, diff --git a/ruoyi-ui/src/views/login.vue b/ruoyi-ui/src/views/login.vue index e8da56b7..a87cb9df 100644 --- a/ruoyi-ui/src/views/login.vue +++ b/ruoyi-ui/src/views/login.vue @@ -18,7 +18,7 @@ - + { - this.captchaEnabled = res.data.enabled; - if(res.data.enabled){ + this.captchaOnOff = res.data.captchaOnOff === undefined ? true : res.data.captchaOnOff; + if (this.captchaOnOff) { this.codeUrl = "data:image/gif;base64," + res.data.img; this.loginForm.uuid = res.data.uuid; } @@ -134,7 +134,9 @@ export default { this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); }).catch(() => { this.loading = false; - this.getCode(); + if (this.captchaOnOff) { + this.getCode(); + } }); } }); diff --git a/sql/ry_20210210.sql b/sql/ry_20210713.sql similarity index 98% rename from sql/ry_20210210.sql rename to sql/ry_20210713.sql index 59a55f12..088960ef 100644 --- a/sql/ry_20210210.sql +++ b/sql/ry_20210713.sql @@ -537,9 +537,10 @@ create table sys_config ( primary key (config_id) ) engine=innodb auto_increment=100 comment = '参数配置表'; -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(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关闭)'); -- ----------------------------