mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev
Conflicts: ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java ruoyi-ui/src/components/ImageUpload/index.vue ruoyi-ui/src/views/login.vue sql/ry_20210713.sql
This commit is contained in:
		@@ -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<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);
 | 
			
		||||
		}
 | 
			
		||||
		// 保存验证码信息
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 记录登录信息
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,13 @@ public interface ISysConfigService extends IServicePlus<SysConfig> {
 | 
			
		||||
     */
 | 
			
		||||
    public String selectConfigByKey(String configKey);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取验证码开关
 | 
			
		||||
     *
 | 
			
		||||
     * @return true开启,false关闭
 | 
			
		||||
     */
 | 
			
		||||
    public boolean selectCaptchaOnOff();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 查询参数配置列表
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -93,6 +93,19 @@ public class SysConfigServiceImpl extends ServicePlusImpl<SysConfigMapper, SysCo
 | 
			
		||||
		return StrUtil.EMPTY;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 获取验证码开关
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return true开启,false关闭
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean selectCaptchaOnOff() {
 | 
			
		||||
		String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
 | 
			
		||||
		if (StrUtil.isEmpty(captchaOnOff)) {
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		return Convert.toBool(captchaOnOff);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 查询参数配置列表
 | 
			
		||||
	 *
 | 
			
		||||
 
 | 
			
		||||
@@ -130,14 +130,14 @@ export default {
 | 
			
		||||
            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) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -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 @@ export default {
 | 
			
		||||
        code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
 | 
			
		||||
      },
 | 
			
		||||
      loading: false,
 | 
			
		||||
      redirect: undefined,
 | 
			
		||||
      captchaEnabled:false
 | 
			
		||||
      captchaOnOff: true,
 | 
			
		||||
      redirect: undefined
 | 
			
		||||
    };
 | 
			
		||||
  },
 | 
			
		||||
  watch: {
 | 
			
		||||
@@ -100,8 +100,8 @@ export default {
 | 
			
		||||
  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 @@ export default {
 | 
			
		||||
            this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
 | 
			
		||||
          }).catch(() => {
 | 
			
		||||
            this.loading = false;
 | 
			
		||||
            this.getCode();
 | 
			
		||||
            if (this.captchaOnOff) {
 | 
			
		||||
              this.getCode();
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
 
 | 
			
		||||
@@ -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关闭)');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- ----------------------------
 | 
			
		||||
		Reference in New Issue
	
	Block a user