|
|
@@ -39,11 +39,14 @@ import com.tuoren.forward.util.ResultPage;
|
|
|
import com.tuoren.forward.util.UUIDUtil;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.Hutool;
|
|
|
import cn.hutool.captcha.generator.MathGenerator;
|
|
|
+import cn.hutool.core.util.ReUtil;
|
|
|
|
|
|
@Service
|
|
|
public class UserService {
|
|
|
-
|
|
|
+ private final Integer MAXCOUNT = 5;
|
|
|
+ private final Integer PWDLEN = 8;
|
|
|
@Autowired
|
|
|
RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
@@ -81,9 +84,25 @@ public class UserService {
|
|
|
if(!mg.verify(verifyCode, captchaCode)) {
|
|
|
return ResultData.failNull("验证码错误");
|
|
|
}
|
|
|
+ if(req.getPassword().length()<8) {
|
|
|
+ return ResultData.failNull("密码长度不得小于8位");
|
|
|
+ }
|
|
|
+ if(!ReUtil.isMatch("^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).+$", req.getPassword())) {
|
|
|
+ return ResultData.failNull("密码要包含特殊字符字母和数字");
|
|
|
+ }
|
|
|
User loginUser = userMapper.selectByUsername(req.getUsername());
|
|
|
- if(loginUser == null || !MD5Util.encode32(req.getPassword()).equals(loginUser.getPassword())) {
|
|
|
- return ResultData.failNull("用户名或密码错误");
|
|
|
+ if(loginUser == null) {
|
|
|
+ return ResultData.failNull("用户不存在");
|
|
|
+ }
|
|
|
+ if(!MD5Util.encode32(req.getPassword()).equals(loginUser.getPassword())) {
|
|
|
+ Integer invalidCount = loginUser.getInvalidCount()+1;
|
|
|
+ if(invalidCount > MAXCOUNT) {
|
|
|
+ return ResultData.failNull("密码次数太多,请联系管理员解锁");
|
|
|
+ }else {
|
|
|
+ loginUser.setInvalidCount(invalidCount);
|
|
|
+ userMapper.updateByPrimaryKeySelective(loginUser);
|
|
|
+ return ResultData.failNull("密码错误,还有"+(MAXCOUNT-invalidCount)+"次机会");
|
|
|
+ }
|
|
|
}
|
|
|
Date date= new Date();
|
|
|
List<String> roleIds = roleMapper.selectIdByUserId(loginUser.getId());
|
|
|
@@ -97,6 +116,7 @@ public class UserService {
|
|
|
user.setId(loginUser.getId());
|
|
|
user.setLasttime(date);
|
|
|
user.setToken(token);
|
|
|
+ user.setInvalidCount(0);
|
|
|
userMapper.updateByPrimaryKeySelective(user);
|
|
|
|
|
|
if(logMapper.existLoginTodayByUseid(user.getId()) == null) {
|
|
|
@@ -354,6 +374,12 @@ public class UserService {
|
|
|
User user = new User();
|
|
|
BeanUtils.copyProperties(req, user);
|
|
|
if(!StringUtils.isEmpty(user.getPassword())) {
|
|
|
+ if(req.getPassword().length()<8) {
|
|
|
+ return ResultData.failNull("密码长度不得小于8位");
|
|
|
+ }
|
|
|
+ if(!ReUtil.isMatch("^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).+$", req.getPassword())) {
|
|
|
+ return ResultData.failNull("密码要包含特殊字符字母和数字");
|
|
|
+ }
|
|
|
user.setPassword(MD5Util.encode32(user.getPassword()));
|
|
|
}
|
|
|
userMapper.updateByPrimaryKeySelective(user);
|