代码提交

This commit is contained in:
2023-06-27 10:18:13 +08:00
parent 77adf7b42c
commit fdb0e3fdd2
7 changed files with 45 additions and 43 deletions

View File

@@ -2,8 +2,10 @@ package com.njcn.auth.security.granter;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.njcn.auth.security.token.SmsCodeAuthenticationToken; import com.njcn.auth.security.token.SmsCodeAuthenticationToken;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.common.pojo.constant.SecurityConstants; import com.njcn.common.pojo.constant.SecurityConstants;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.redis.pojo.enums.RedisKeyEnum; import com.njcn.redis.pojo.enums.RedisKeyEnum;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.user.enums.UserResponseEnum; import com.njcn.user.enums.UserResponseEnum;
@@ -45,7 +47,7 @@ public class SmsTokenGranter extends AbstractTokenGranter {
Map<String, String> parameters = new LinkedHashMap<>(tokenRequest.getRequestParameters()); Map<String, String> parameters = new LinkedHashMap<>(tokenRequest.getRequestParameters());
String phone = parameters.get(SecurityConstants.PHONE); String phone = parameters.get(SecurityConstants.PHONE);
String smsCode = parameters.get(SecurityConstants.SMS_CODE); String smsCode = parameters.get(SecurityConstants.SMS_CODE);
if (StrUtil.isBlank(phone)) { if (StrUtil.isBlank(phone) || !PubUtils.match(PatternRegex.PHONE_REGEX, phone)) {
throw new BusinessException(UserResponseEnum.REGISTER_PHONE_WRONG); throw new BusinessException(UserResponseEnum.REGISTER_PHONE_WRONG);
} }
if (!judgeSmsCode(phone, smsCode)) { if (!judgeSmsCode(phone, smsCode)) {

View File

@@ -23,10 +23,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -323,8 +320,20 @@ public class PubUtils {
return matcher.matches(); return matcher.matches();
} }
public static boolean patternPasswordPhone(String password) { /**
return match(PatternRegex.PASSWORD_PHONE_REGEX, password); * 生成随机推荐码
*/
public static String getCode(Integer number){
final String BASIC = "123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZZ";
char[] basicArray = BASIC.toCharArray();
Random random = new Random();
char[] result = new char[number];
for (int i = 0; i < result.length; i++) {
int index = random.nextInt(100) % (basicArray.length);
result[i] = basicArray[index];
} }
return new String(result);
}
//***************************************************添加结束******************************************************** //***************************************************添加结束********************************************************
} }

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.user.enums.UserResponseEnum; import com.njcn.user.enums.UserResponseEnum;
import com.njcn.user.pojo.po.UserRole; import com.njcn.user.pojo.po.UserRole;
@@ -53,7 +54,7 @@ public class AppRoleServiceImpl implements IAppRoleService {
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>(); LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map.Entry<String, String> entry : map.entrySet()) {
if (Objects.equals(entry.getKey(),referralCode)){ if (Objects.equals(entry.getKey(),referralCode)){
roleMap.put(ReferralCodeServiceImpl.getCode(),entry.getValue()); roleMap.put(PubUtils.getCode(6),entry.getValue());
} else { } else {
roleMap.put(entry.getKey(),entry.getValue()); roleMap.put(entry.getKey(),entry.getValue());
} }

View File

@@ -259,7 +259,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
} }
private void judgeCode(String phone, String code, String devCode) { private void judgeCode(String phone, String code, String devCode) {
String key = phone + devCode; String key = RedisKeyEnum.SMS_LOGIN_KEY.getKey() + phone;
String redisCode = redisUtil.getStringByKey(key); String redisCode = redisUtil.getStringByKey(key);
if (StringUtils.isEmpty(redisCode) || !code.equalsIgnoreCase(redisCode)) { if (StringUtils.isEmpty(redisCode) || !code.equalsIgnoreCase(redisCode)) {
throw new BusinessException(UserResponseEnum.LOGIN_WRONG_CODE); throw new BusinessException(UserResponseEnum.LOGIN_WRONG_CODE);
@@ -286,7 +286,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
user.setState(UserState.ENABLE); user.setState(UserState.ENABLE);
user.setOrigin(UserState.NORMAL_ORIGIN); user.setOrigin(UserState.NORMAL_ORIGIN);
user.setCasualUser(UserType.OFFICIAL); user.setCasualUser(UserType.OFFICIAL);
user.setPwdState(UserState.NEED); user.setPwdState(UserState.NEEDLESS);
user.setRegisterTime(LocalDateTime.now()); user.setRegisterTime(LocalDateTime.now());
user.setLoginTime(LocalDateTime.now()); user.setLoginTime(LocalDateTime.now());
user.setPwdValidity(LocalDateTime.now()); user.setPwdValidity(LocalDateTime.now());

View File

@@ -1,5 +1,6 @@
package com.njcn.user.service.impl; package com.njcn.user.service.impl;
import com.njcn.common.utils.PubUtils;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.user.pojo.vo.app.RoleReferralCodeVO; import com.njcn.user.pojo.vo.app.RoleReferralCodeVO;
import com.njcn.user.service.IReferralCodeService; import com.njcn.user.service.IReferralCodeService;
@@ -22,8 +23,6 @@ import java.util.*;
@AllArgsConstructor @AllArgsConstructor
public class ReferralCodeServiceImpl implements IReferralCodeService { public class ReferralCodeServiceImpl implements IReferralCodeService {
private static final String BASIC = "123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZZ";
private final RedisUtil redisUtil; private final RedisUtil redisUtil;
private final IRoleService roleService; private final IRoleService roleService;
@@ -34,9 +33,9 @@ public class ReferralCodeServiceImpl implements IReferralCodeService {
Object object = redisUtil.getObjectByKey("roleReferralCode"); Object object = redisUtil.getObjectByKey("roleReferralCode");
if (Objects.isNull(object)){ if (Objects.isNull(object)){
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>(); LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
String code1 = getCode(); String code1 = PubUtils.getCode(6);
String code2 = getCode(); String code2 = PubUtils.getCode(6);
String code3 = getCode(); String code3 = PubUtils.getCode(6);
roleMap.put(code1,"market_user"); roleMap.put(code1,"market_user");
roleMap.put(code2,"engineering_user"); roleMap.put(code2,"engineering_user");
roleMap.put(code3,"app_user"); roleMap.put(code3,"app_user");
@@ -66,9 +65,9 @@ public class ReferralCodeServiceImpl implements IReferralCodeService {
@Override @Override
public List<RoleReferralCodeVO> refreshReferralCode() { public List<RoleReferralCodeVO> refreshReferralCode() {
LinkedHashMap<String,String> roleMap = new LinkedHashMap<>(); LinkedHashMap<String,String> roleMap = new LinkedHashMap<>();
String code1 = getCode(); String code1 = PubUtils.getCode(6);
String code2 = getCode(); String code2 = PubUtils.getCode(6);
String code3 = getCode(); String code3 = PubUtils.getCode(6);
roleMap.put(code1,"market_user"); roleMap.put(code1,"market_user");
roleMap.put(code2,"engineering_user"); roleMap.put(code2,"engineering_user");
roleMap.put(code3,"app_user"); roleMap.put(code3,"app_user");
@@ -82,21 +81,8 @@ public class ReferralCodeServiceImpl implements IReferralCodeService {
RoleReferralCodeVO vo3 = new RoleReferralCodeVO(); RoleReferralCodeVO vo3 = new RoleReferralCodeVO();
vo3.setRoleName(roleService.getRoleByCode("app_user").getName()); vo3.setRoleName(roleService.getRoleByCode("app_user").getName());
vo3.setRoleReferralCode(code3); vo3.setRoleReferralCode(code3);
return Arrays.asList(vo1,vo2,vo3); return Arrays.asList(vo1,vo2,vo3);
} }
/**
* 生成随机推荐码
*/
public static String getCode(){
char[] basicArray = BASIC.toCharArray();
Random random = new Random();
char[] result = new char[6];
for (int i = 0; i < result.length; i++) {
int index = random.nextInt(100) % (basicArray.length);
result[i] = basicArray[index];
}
return new String(result);
}
} }

View File

@@ -251,6 +251,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
return null; return null;
} }
BeanUtil.copyProperties(user, userVO); BeanUtil.copyProperties(user, userVO);
if (!Objects.isNull(user.getDeptId())){
Dept dept = deptService.getDeptById(user.getDeptId()); Dept dept = deptService.getDeptById(user.getDeptId());
//非自定义部门 //非自定义部门
if (Objects.equals(dept.getType(),0)){ if (Objects.equals(dept.getType(),0)){
@@ -261,9 +262,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
userVO.setAreaName(deptService.getNameByDeptId(user.getDeptId())); userVO.setAreaName(deptService.getNameByDeptId(user.getDeptId()));
} }
userVO.setDeptName(deptService.getNameByDeptId(user.getDeptId())); userVO.setDeptName(deptService.getNameByDeptId(user.getDeptId()));
userVO.setDeptLevel(dept.getPids().split(StrUtil.COMMA).length);
}
userVO.setRoleList(roleService.getIdByUserId(id)); userVO.setRoleList(roleService.getIdByUserId(id));
userVO.setRole(roleService.getNameByUserId(id)); userVO.setRole(roleService.getNameByUserId(id));
userVO.setDeptLevel(dept.getPids().split(StrUtil.COMMA).length);
return userVO; return userVO;
} }

View File

@@ -53,8 +53,10 @@ public class UserSetServiceImpl extends ServiceImpl<UserSetMapper, UserSet> impl
String secretKey = PubUtils.randomCode(16); String secretKey = PubUtils.randomCode(16);
userSet.setSecretKey(secretKey); userSet.setSecretKey(secretKey);
Sm4Utils sm4 = new Sm4Utils(secretKey); Sm4Utils sm4 = new Sm4Utils(secretKey);
String password = PubUtils.getCode(8);
System.out.println("password==:" + password);
//SM4加密初始默认密码 //SM4加密初始默认密码
String strSm4 = sm4.encryptData_ECB(UserDefaultPassword.DEFAULT_PASSWORD); String strSm4 = sm4.encryptData_ECB(password);
userSet.setStandBy(strSm4); userSet.setStandBy(strSm4);
this.save(userSet); this.save(userSet);
return userSet; return userSet;