From fd5414f82e6305eaf35297f63f9e7c95615f99e3 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期二, 13 七月 2021 13:34:10 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java         |    7 +++
 ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java |   47 ++++++++++++++++-------
 ruoyi-ui/src/components/Editor/index.vue                                           |   16 ++++----
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java   |   12 ++++--
 ruoyi-ui/src/components/ImageUpload/index.vue                                      |    2 
 sql/ry_20210713.sql                                                                |    7 ++-
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java |   13 ++++++
 ruoyi-ui/src/views/login.vue                                                       |   14 ++++---
 8 files changed, 82 insertions(+), 36 deletions(-)

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 2f303ba..4654516 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.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 @@
 /**
  * 楠岃瘉鐮佹搷浣滃鐞�
  *
- * @author Lion Li
+ * @author ruoyi
  */
 @RestController
 public class CaptchaController {
@@ -47,15 +48,18 @@
 	@Autowired
 	private CaptchaProperties captchaProperties;
 
+	@Autowired
+	private ISysConfigService configService;
+
 	/**
 	 * 鐢熸垚楠岃瘉鐮�
 	 */
 	@GetMapping("/captchaImage")
 	public AjaxResult getCode() {
 		Map<String, Object> 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 d0b9511..47258dd 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.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;
@@ -47,6 +48,9 @@
     private ISysUserService userService;
 
 	@Autowired
+	private ISysConfigService configService;
+
+	@Autowired
 	private AsyncService asyncService;
 
     /**
@@ -60,20 +64,12 @@
      */
     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
@@ -103,6 +99,29 @@
     }
 
     /**
+     * 鏍¢獙楠岃瘉鐮�
+     *
+     * @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();
+		}
+    }
+
+    /**
      * 璁板綍鐧诲綍淇℃伅
      */
     public void recordLoginInfo(SysUser user)
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 429559b..b649c7f 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
@@ -33,6 +33,13 @@
     public String selectConfigByKey(String configKey);
 
     /**
+     * 鑾峰彇楠岃瘉鐮佸紑鍏�
+     *
+     * @return true寮�鍚紝false鍏抽棴
+     */
+    public boolean selectCaptchaOnOff();
+
+    /**
      * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃
      *
      * @param config 鍙傛暟閰嶇疆淇℃伅
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 dd7321a..41be807 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
@@ -94,6 +94,19 @@
 	}
 
 	/**
+	 * 鑾峰彇楠岃瘉鐮佸紑鍏�
+	 *
+	 * @return true寮�鍚紝false鍏抽棴
+	 */
+	public boolean selectCaptchaOnOff() {
+		String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
+		if (StrUtil.isEmpty(captchaOnOff)) {
+			return true;
+		}
+		return Convert.toBool(captchaOnOff);
+	}
+
+	/**
 	 * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃
 	 *
 	 * @param config 鍙傛暟閰嶇疆淇℃伅
diff --git a/ruoyi-ui/src/components/Editor/index.vue b/ruoyi-ui/src/components/Editor/index.vue
index 98b9fa7..f78dfcc 100644
--- a/ruoyi-ui/src/components/Editor/index.vue
+++ b/ruoyi-ui/src/components/Editor/index.vue
@@ -130,14 +130,14 @@
             this.quill.format("image", false);
           }
         });
-        toolbar.addHandler("video", (value) => {
-          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 f2a7402..31940af 100644
--- a/ruoyi-ui/src/components/ImageUpload/index.vue
+++ b/ruoyi-ui/src/components/ImageUpload/index.vue
@@ -116,7 +116,7 @@
   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 e8da56b..a87cb9d 100644
--- a/ruoyi-ui/src/views/login.vue
+++ b/ruoyi-ui/src/views/login.vue
@@ -18,7 +18,7 @@
           <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
         </el-input>
       </el-form-item>
-      <el-form-item prop="code" v-if="captchaEnabled">
+      <el-form-item prop="code" v-if="captchaOnOff">
         <el-input
           v-model="loginForm.code"
           auto-complete="off"
@@ -81,8 +81,8 @@
         code: [{ required: true, trigger: "change", message: "楠岃瘉鐮佷笉鑳戒负绌�" }]
       },
       loading: false,
-      redirect: undefined,
-      captchaEnabled:false
+      captchaOnOff: true,
+      redirect: undefined
     };
   },
   watch: {
@@ -100,8 +100,8 @@
   methods: {
     getCode() {
       getCodeImg().then(res => {
-        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 @@
             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 59a55f1..088960e 100644
--- a/sql/ry_20210210.sql
+++ b/sql/ry_20210713.sql
@@ -537,9 +537,10 @@
   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锛屾祬鑹蹭富棰榯heme-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锛屾祬鑹蹭富棰榯heme-light' );
+insert into sys_config values(4, '璐﹀彿鑷姪-楠岃瘉鐮佸紑鍏�',       'sys.account.captchaOnOff',      'true',          'Y', 'admin', sysdate(), '', null, '鏄惁寮�鍚櫥褰曢獙璇佺爜鍔熻兘锛坱rue寮�鍚紝false鍏抽棴锛�');
 
 
 -- ----------------------------

--
Gitblit v1.9.3