|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.model.User;
|
|
|
|
|
import com.supervision.pojo.vo.UserAccountCheckResVo;
|
|
|
|
|
import com.supervision.pojo.vo.UserInfoReqVo;
|
|
|
|
|
import com.supervision.pojo.vo.UserInfoResVo;
|
|
|
|
|
import com.supervision.service.UserManageService;
|
|
|
|
@ -11,6 +12,10 @@ import com.supervision.service.UserService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
@ -18,36 +23,12 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
public class UserManageServiceImpl implements UserManageService {
|
|
|
|
|
|
|
|
|
|
private final UserService userService;
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateUserInfo(UserInfoReqVo userInfo) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(userInfo.getId(),"用户id不能为空");
|
|
|
|
|
if (StrUtil.isNotEmpty(userInfo.getNewPassword())){
|
|
|
|
|
//todo:密码复杂度规则匹配
|
|
|
|
|
Assert.notEmpty(userInfo.getOldPassword(),"旧密码不允许为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User user = userService.getById(userInfo.getId());
|
|
|
|
|
Assert.notNull(user,"用户信息不存在");
|
|
|
|
|
|
|
|
|
|
boolean change = false;
|
|
|
|
|
if (StrUtil.isNotEmpty(userInfo.getName())){
|
|
|
|
|
user.setName(userInfo.getName());
|
|
|
|
|
change = true;
|
|
|
|
|
}
|
|
|
|
|
String newPassword = userInfo.getNewPassword();
|
|
|
|
|
String oldPassword = userInfo.getOldPassword();
|
|
|
|
|
if (StrUtil.isAllNotEmpty(newPassword,oldPassword)){
|
|
|
|
|
Assert.isTrue(user.getPassword().equals(oldPassword),"密码不正确");
|
|
|
|
|
user.setPassword(newPassword);
|
|
|
|
|
change = true;
|
|
|
|
|
}
|
|
|
|
|
// 密码6-18位 不包含中文特殊字符和空格
|
|
|
|
|
private static final String passwordRegex = "^(?![\\u4e00-\\u9fa5\\s])[\\x21-\\x7e]{6,18}$";
|
|
|
|
|
|
|
|
|
|
if (!change){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return userService.updateById(user);
|
|
|
|
|
}
|
|
|
|
|
// 账号校验正则 6-18位 英文或者数字
|
|
|
|
|
private static final String accountRegex = "^[a-zA-Z0-9]{6,18}$";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public UserInfoResVo getUserAccountInfo(String userId) {
|
|
|
|
@ -58,4 +39,97 @@ public class UserManageServiceImpl implements UserManageService {
|
|
|
|
|
|
|
|
|
|
return BeanUtil.toBean(user,UserInfoResVo.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public boolean changePassWord(UserInfoReqVo userInfo) {
|
|
|
|
|
Assert.notEmpty(userInfo.getAccount(),"账号不能为空");
|
|
|
|
|
Assert.notEmpty(userInfo.getPassword(),"密码不能为空");
|
|
|
|
|
String match = passwordRegexMatch(userInfo.getPassword());
|
|
|
|
|
Assert.isFalse(StrUtil.isNotEmpty(match),match);
|
|
|
|
|
|
|
|
|
|
Long count = userService.lambdaQuery().eq(User::getAccount, userInfo.getAccount()).count();
|
|
|
|
|
Assert.isFalse(count==0,"密码设置失败");
|
|
|
|
|
userService.lambdaUpdate().eq(User::getAccount, userInfo.getAccount()).set(User::getPassword,userInfo.getPassword()).update();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public boolean register(UserInfoReqVo userInfo) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(userInfo.getAccount(),"账号不能为空");
|
|
|
|
|
Assert.notEmpty(userInfo.getName(),"用户名不能为空");
|
|
|
|
|
|
|
|
|
|
// 用户规则校验
|
|
|
|
|
String accountRegexMatch = accountRegexMatch(userInfo.getAccount());
|
|
|
|
|
Assert.isFalse(StrUtil.isNotEmpty(accountRegexMatch),accountRegexMatch);
|
|
|
|
|
|
|
|
|
|
// 校验账号是否已存在
|
|
|
|
|
Long count = userService.lambdaQuery().eq(User::getAccount, userInfo.getAccount()).count();
|
|
|
|
|
Assert.isTrue(count==0,"账号已存在");
|
|
|
|
|
|
|
|
|
|
// 密码强度校验
|
|
|
|
|
String passwordRegexMatch = passwordRegexMatch(userInfo.getPassword());
|
|
|
|
|
Assert.isFalse(StrUtil.isNotEmpty(passwordRegexMatch),passwordRegexMatch);
|
|
|
|
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
user.setAccount(userInfo.getAccount());
|
|
|
|
|
user.setName(userInfo.getName());
|
|
|
|
|
user.setPassword(userInfo.getPassword());
|
|
|
|
|
user.setRoleCode("1");
|
|
|
|
|
user.setStatus(0);
|
|
|
|
|
userService.save(user);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public UserAccountCheckResVo checkAccount(String account) {
|
|
|
|
|
|
|
|
|
|
UserAccountCheckResVo checkResult = new UserAccountCheckResVo();
|
|
|
|
|
if (StrUtil.isEmpty(account)){
|
|
|
|
|
checkResult.setCode("1");
|
|
|
|
|
checkResult.setMessage("账号不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//复杂度校验
|
|
|
|
|
String accountRegexMatch = accountRegexMatch(account);
|
|
|
|
|
if (StrUtil.isNotEmpty(accountRegexMatch)){
|
|
|
|
|
checkResult.setCode("1");
|
|
|
|
|
checkResult.setMessage(accountRegexMatch);
|
|
|
|
|
return checkResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long count = userService.lambdaQuery().eq(User::getAccount, account).count();
|
|
|
|
|
if (count > 0){
|
|
|
|
|
checkResult.setCode("1");
|
|
|
|
|
checkResult.setMessage("账号已存在");
|
|
|
|
|
}
|
|
|
|
|
checkResult.setCode("0");
|
|
|
|
|
return checkResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String passwordRegexMatch(String password){
|
|
|
|
|
if (StrUtil.isEmpty(password)){
|
|
|
|
|
return "密码不能为空";
|
|
|
|
|
}
|
|
|
|
|
Pattern pattern = Pattern.compile(passwordRegex);
|
|
|
|
|
Matcher matcher = pattern.matcher(password);
|
|
|
|
|
if (!matcher.matches()){
|
|
|
|
|
return "密码强度不符合要求";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String accountRegexMatch(String account){
|
|
|
|
|
if (StrUtil.isEmpty(account)){
|
|
|
|
|
return "账号不能为空";
|
|
|
|
|
}
|
|
|
|
|
Pattern pattern = Pattern.compile(accountRegex);
|
|
|
|
|
Matcher matcher = pattern.matcher(account);
|
|
|
|
|
if (!matcher.matches()){
|
|
|
|
|
return "账号格式不符合要求";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|