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:
疯狂的狮子li 2021-07-13 13:34:10 +08:00
commit fd5414f82e
8 changed files with 82 additions and 36 deletions

View File

@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.captcha.UnsignedMathGenerator; import com.ruoyi.framework.captcha.UnsignedMathGenerator;
import com.ruoyi.framework.config.properties.CaptchaProperties; import com.ruoyi.framework.config.properties.CaptchaProperties;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* 验证码操作处理 * 验证码操作处理
* *
* @author Lion Li * @author ruoyi
*/ */
@RestController @RestController
public class CaptchaController { public class CaptchaController {
@ -47,15 +48,18 @@ public class CaptchaController {
@Autowired @Autowired
private CaptchaProperties captchaProperties; private CaptchaProperties captchaProperties;
@Autowired
private ISysConfigService configService;
/** /**
* 生成验证码 * 生成验证码
*/ */
@GetMapping("/captchaImage") @GetMapping("/captchaImage")
public AjaxResult getCode() { public AjaxResult getCode() {
Map<String, Object> ajax = new HashMap<>(); Map<String, Object> ajax = new HashMap<>();
Boolean enabled = captchaProperties.getEnabled(); boolean captchaOnOff = configService.selectCaptchaOnOff();
ajax.put("enabled", enabled); ajax.put("captchaOnOff", captchaOnOff);
if (!enabled) { if (!captchaOnOff) {
return AjaxResult.success(ajax); return AjaxResult.success(ajax);
} }
// 保存验证码信息 // 保存验证码信息

View File

@ -12,6 +12,7 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils; import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.config.properties.CaptchaProperties; import com.ruoyi.framework.config.properties.CaptchaProperties;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
@ -46,6 +47,9 @@ public class SysLoginService
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired
private ISysConfigService configService;
@Autowired @Autowired
private AsyncService asyncService; private AsyncService asyncService;
@ -60,20 +64,12 @@ public class SysLoginService
*/ */
public String login(String username, String password, String code, String uuid) public String login(String username, String password, String code, String uuid)
{ {
HttpServletRequest request = ServletUtils.getRequest(); boolean captchaOnOff = configService.selectCaptchaOnOff();
if(captchaProperties.getEnabled()) { // 验证码开关
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; if (captchaOnOff)
String captcha = redisCache.getCacheObject(verifyKey); {
redisCache.deleteObject(verifyKey); validateCapcha(username, code, uuid);
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();
}
}
// 用户验证 // 用户验证
Authentication authentication = null; Authentication authentication = null;
try try
@ -102,6 +98,29 @@ public class SysLoginService
return tokenService.createToken(loginUser); 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();
}
}
/** /**
* 记录登录信息 * 记录登录信息
*/ */

View File

@ -32,6 +32,13 @@ public interface ISysConfigService extends IServicePlus<SysConfig> {
*/ */
public String selectConfigByKey(String configKey); public String selectConfigByKey(String configKey);
/**
* 获取验证码开关
*
* @return true开启false关闭
*/
public boolean selectCaptchaOnOff();
/** /**
* 查询参数配置列表 * 查询参数配置列表
* *

View File

@ -93,6 +93,19 @@ public class SysConfigServiceImpl extends ServicePlusImpl<SysConfigMapper, SysCo
return StrUtil.EMPTY; 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);
}
/** /**
* 查询参数配置列表 * 查询参数配置列表
* *

View File

@ -130,14 +130,14 @@ export default {
this.quill.format("image", false); this.quill.format("image", false);
} }
}); });
toolbar.addHandler("video", (value) => { // toolbar.addHandler("video", (value) => {
this.uploadType = "video"; // this.uploadType = "video";
if (value) { // if (value) {
this.$refs.upload.$children[0].$refs.input.click(); // this.$refs.upload.$children[0].$refs.input.click();
} else { // } else {
this.quill.format("video", false); // this.quill.format("video", false);
} // }
}); // });
} }
this.Quill.pasteHTML(this.currentValue); this.Quill.pasteHTML(this.currentValue);
this.Quill.on("text-change", (delta, oldDelta, source) => { this.Quill.on("text-change", (delta, oldDelta, source) => {

View File

@ -116,7 +116,7 @@ export default {
methods: { methods: {
// //
handleRemove(file, fileList) { 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.fileList.splice(findex, 1);
this.$emit("input", this.listToString(this.fileList)); this.$emit("input", this.listToString(this.fileList));
}, },

View File

@ -18,7 +18,7 @@
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item prop="code" v-if="captchaEnabled"> <el-form-item prop="code" v-if="captchaOnOff">
<el-input <el-input
v-model="loginForm.code" v-model="loginForm.code"
auto-complete="off" auto-complete="off"
@ -81,8 +81,8 @@ export default {
code: [{ required: true, trigger: "change", message: "验证码不能为空" }] code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
}, },
loading: false, loading: false,
redirect: undefined, captchaOnOff: true,
captchaEnabled:false redirect: undefined
}; };
}, },
watch: { watch: {
@ -100,8 +100,8 @@ export default {
methods: { methods: {
getCode() { getCode() {
getCodeImg().then(res => { getCodeImg().then(res => {
this.captchaEnabled = res.data.enabled; this.captchaOnOff = res.data.captchaOnOff === undefined ? true : res.data.captchaOnOff;
if(res.data.enabled){ if (this.captchaOnOff) {
this.codeUrl = "data:image/gif;base64," + res.data.img; this.codeUrl = "data:image/gif;base64," + res.data.img;
this.loginForm.uuid = res.data.uuid; this.loginForm.uuid = res.data.uuid;
} }
@ -134,7 +134,9 @@ export default {
this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
}).catch(() => { }).catch(() => {
this.loading = false; this.loading = false;
this.getCode(); if (this.captchaOnOff) {
this.getCode();
}
}); });
} }
}); });

View File

@ -537,9 +537,10 @@ create table sys_config (
primary key (config_id) primary key (config_id)
) engine=innodb auto_increment=100 comment = '参数配置表'; ) 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(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(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(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关闭');
-- ---------------------------- -- ----------------------------