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:
commit
fd5414f82e
|
@ -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);
|
||||||
}
|
}
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
|
|
|
@ -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,19 +64,11 @@ 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;
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录登录信息
|
* 记录登录信息
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询参数配置列表
|
* 查询参数配置列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询参数配置列表
|
* 查询参数配置列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -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) => {
|
||||||
|
|
|
@ -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));
|
||||||
},
|
},
|
||||||
|
|
|
@ -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;
|
||||||
|
if (this.captchaOnOff) {
|
||||||
this.getCode();
|
this.getCode();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -540,6 +540,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(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关闭)');
|
||||||
|
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
Loading…
Reference in New Issue