mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-22 02:50:00 +08:00
1、新增前端登录页面注册开关接口
2、密码最大错误次数与锁定时间:从读取配置文件变更为读取数据库配置 3、短信开关与验证码模板id:从读取配置文件变更为读取数据库配置
This commit is contained in:
parent
3832dc933d
commit
1895240186
@ -62,8 +62,8 @@ public class CaptchaController {
|
||||
String key = CacheConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||
String templateId = "";
|
||||
// 验证码模板id
|
||||
String templateId = configService.selectConfigByKey("sys.account.templateId");
|
||||
Map<String, String> map = new HashMap<>(1);
|
||||
map.put("code", code);
|
||||
SmsTemplate smsTemplate = SpringUtils.getBean(SmsTemplate.class);
|
||||
|
||||
@ -8,10 +8,14 @@ import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.SysRegisterService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 注册验证
|
||||
*
|
||||
@ -25,6 +29,15 @@ public class SysRegisterController extends BaseController {
|
||||
private final SysRegisterService registerService;
|
||||
private final ISysConfigService configService;
|
||||
|
||||
@SaIgnore
|
||||
@GetMapping("/registerEnabled")
|
||||
public R<Map<String, Object>> registerEnabled() {
|
||||
Map<String, Object> ajax = new HashMap<>();
|
||||
String register = configService.selectConfigByKey("sys.account.registerUser");
|
||||
ajax.put("register", register);
|
||||
return R.ok(ajax);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
|
||||
@ -53,14 +53,6 @@ logging:
|
||||
org.springframework: warn
|
||||
config: classpath:logback.xml
|
||||
|
||||
# 用户配置
|
||||
user:
|
||||
password:
|
||||
# 密码最大错误次数
|
||||
maxRetryCount: 5
|
||||
# 密码锁定时间(默认10分钟)
|
||||
lockTime: 10
|
||||
|
||||
# Spring配置
|
||||
spring:
|
||||
application:
|
||||
|
||||
@ -4,13 +4,14 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.event.LogininforEvent;
|
||||
import com.ruoyi.common.core.domain.dto.RoleDTO;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.event.LogininforEvent;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.domain.model.XcxLoginUser;
|
||||
import com.ruoyi.common.enums.DeviceType;
|
||||
@ -29,7 +30,6 @@ import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -51,12 +51,6 @@ public class SysLoginService {
|
||||
private final ISysConfigService configService;
|
||||
private final SysPermissionService permissionService;
|
||||
|
||||
@Value("${user.password.maxRetryCount}")
|
||||
private Integer maxRetryCount;
|
||||
|
||||
@Value("${user.password.lockTime}")
|
||||
private Integer lockTime;
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
@ -266,6 +260,10 @@ public class SysLoginService {
|
||||
|
||||
// 获取用户登录错误次数(可自定义限制策略 例如: key + username + ip)
|
||||
Integer errorNumber = RedisUtils.getCacheObject(errorKey);
|
||||
//密码最大错误次数
|
||||
Integer maxRetryCount = Convert.toInt(configService.selectConfigByKey("sys.user.maxRetryCount"));
|
||||
//密码锁定时间
|
||||
Integer lockTime = Convert.toInt(configService.selectConfigByKey("sys.user.lockTime"));
|
||||
// 锁定时间内登录 则踢出
|
||||
if (ObjectUtil.isNotNull(errorNumber) && errorNumber.equals(maxRetryCount)) {
|
||||
recordLogininfor(username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user