|
@@ -3,10 +3,7 @@ package cn.cslg.permission.service;
|
|
|
import cn.cslg.permission.common.core.base.RedisConf;
|
|
|
import cn.cslg.permission.common.core.business.LoginCacheKeyUtil;
|
|
|
import cn.cslg.permission.common.core.business.SmsService;
|
|
|
-import cn.cslg.permission.common.model.dto.EncryptionFunctionDTO;
|
|
|
-import cn.cslg.permission.common.model.dto.EncryptionLoginDTO;
|
|
|
-import cn.cslg.permission.common.model.dto.PhoneLoginDTO;
|
|
|
-import cn.cslg.permission.common.model.dto.SendCodeDTO;
|
|
|
+import cn.cslg.permission.common.model.dto.*;
|
|
|
import cn.cslg.permission.common.model.vo.*;
|
|
|
import cn.cslg.permission.common.utils.*;
|
|
|
import cn.cslg.permission.common.utils.message.MessageUtils;
|
|
@@ -350,7 +347,12 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
}
|
|
|
|
|
|
//校验登录时参数
|
|
|
- public void checkRational(String machineCode, String sign, String appKey, long timeMillis) {
|
|
|
+ public EncryptionLoginVO loginCommonMethod(LoginCommonDTO vo,Personnel personnel) throws Exception {
|
|
|
+ Integer personnelId = personnel.getId();
|
|
|
+ Long timeMillis = vo.getCurrentTimeMillis();
|
|
|
+ String appKey = vo.getAppKey();
|
|
|
+ String sign = vo.getSign();
|
|
|
+ String machineCode = vo.getMachineCode();
|
|
|
long currentTimeMillis = timeMillis / 1000;
|
|
|
long currentTimeSecond = System.currentTimeMillis() / 1000;
|
|
|
final long second = currentTimeSecond - currentTimeMillis;
|
|
@@ -362,11 +364,36 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
if (Boolean.TRUE.equals(StringUtils.isEmpty(sign)) || !sign.equals(md5Sign)) {
|
|
|
throw new XiaoShiException(ExceptionEnum.THE_SIGN_IS_NOT_SAME);
|
|
|
}
|
|
|
-
|
|
|
if (Boolean.TRUE.equals(StringUtils.isEmpty(machineCode))) {
|
|
|
throw new XiaoShiException(ExceptionEnum.THE_MACHINE_CODE_IS_NULL);
|
|
|
}
|
|
|
+
|
|
|
+ //人员信息中私钥或公钥为空则添加进去
|
|
|
+ this.updatePersonnel(personnel.getPrivateKey(), personnel.getPublicKey(), personnel.getSymmetryKey(), personnelId);
|
|
|
+
|
|
|
+ personnel = personnelMapper.selectById(personnel.getId());
|
|
|
+ List<AssoPersonnelMachine> machineList = assoPersonnelMachineMapper.selectList(new LambdaQueryWrapper<AssoPersonnelMachine>()
|
|
|
+ .eq(AssoPersonnelMachine::getPersonnelId, personnelId)
|
|
|
+ .ne(AssoPersonnelMachine::getMachineCode, SecureUtil.md5(machineCode)));
|
|
|
+ if (machineList.size() > 1) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.DO_NOT_LOG_IN_TO_MORE_THAN_TWO_NEW_MACHINES_WITH_THE_SAME_ACCOUNT);
|
|
|
+ }
|
|
|
+ this.addOrUpdatePersonnelMachine(machineCode, personnel);
|
|
|
+
|
|
|
+ EncryptionLoginVO loginVO = new EncryptionLoginVO();
|
|
|
+ loginVO.setPrivateKey(personnel.getPrivateKey());
|
|
|
+ loginVO.setPersonId(personnelId);
|
|
|
+ loginVO.setPersonnelName(personnel.getPersonnelName());
|
|
|
+ loginVO.setPersonnelUserName(personnel.getPersonnelUserName());
|
|
|
+ loginVO.setPersonnelPhone(personnel.getPersonnelPhone());
|
|
|
+ loginVO.setMachineCode(vo.getMachineCode());
|
|
|
+ loginVO.setPersonnelConfig(personnel.getPersonConfig());
|
|
|
+ //Sa-token 登录方法 登录后 生成Token 如果集成了Redis的话 会自动存入Redis
|
|
|
+ StpUtil.login(personnel.getId());
|
|
|
+ loginVO.setToken(StpUtil.getTokenValue());
|
|
|
+ return loginVO;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 登录加密
|
|
|
*
|
|
@@ -378,8 +405,6 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
public String loginByEncryption(EncryptionLoginDTO vo) throws Exception {
|
|
|
final String username = vo.getUsername();
|
|
|
final String password = vo.getPassword();
|
|
|
- String machineCode = vo.getMachineCode();
|
|
|
- this.checkRational(machineCode, vo.getSign(), vo.getAppKey(), vo.getCurrentTimeMillis());
|
|
|
//用用户名查询人员信息
|
|
|
LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(Personnel::getPersonnelPhone, username)
|
|
@@ -389,7 +414,6 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
.eq(Personnel::getPersonnelUserName, username);
|
|
|
//获取一条
|
|
|
Personnel personnel = this.getOne(queryWrapper, false);
|
|
|
- final Integer personId = personnel.getId();
|
|
|
//如果查不到 报错 用户名不存在
|
|
|
if (ObjectUtils.isEmpty(personnel)) {
|
|
|
throw new XiaoShiException(ExceptionEnum.THE_PERSONNEL_IS_NOT_EXIST);
|
|
@@ -403,31 +427,12 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
//登录日志记录登录是否成功
|
|
|
throw new XiaoShiException(ExceptionEnum.LOGIN_PASSWORD_MISTAKE);
|
|
|
}
|
|
|
- //人员信息中私钥或公钥为空则添加进去
|
|
|
- updatePersonnel(personnel.getPrivateKey(), personnel.getPublicKey(), personnel.getSymmetryKey(), personId);
|
|
|
-
|
|
|
- personnel = personnelMapper.selectById(personnel.getId());
|
|
|
- List<AssoPersonnelMachine> machineList = assoPersonnelMachineMapper.selectList(new LambdaQueryWrapper<AssoPersonnelMachine>()
|
|
|
- .eq(AssoPersonnelMachine::getPersonnelId, personId)
|
|
|
- .ne(AssoPersonnelMachine::getMachineCode, SecureUtil.md5(machineCode)));
|
|
|
- if (machineList.size() > 1) {
|
|
|
- throw new XiaoShiException(ExceptionEnum.DO_NOT_LOG_IN_TO_MORE_THAN_TWO_NEW_MACHINES_WITH_THE_SAME_ACCOUNT);
|
|
|
- }
|
|
|
- boolean flag = addOrUpdatePersonnelMachine(machineCode, personnel);
|
|
|
- EncryptionLoginVO loginVO = new EncryptionLoginVO();
|
|
|
-// if (flag) {
|
|
|
-// loginVO.setPrivateKey(personnel.getPrivateKey());
|
|
|
-// }
|
|
|
- loginVO.setPrivateKey(personnel.getPrivateKey());
|
|
|
- loginVO.setPersonId(personId);
|
|
|
- loginVO.setPersonnelName(personnel.getPersonnelName());
|
|
|
- loginVO.setPersonnelUserName(personnel.getPersonnelUserName());
|
|
|
- loginVO.setPersonnelPhone(personnel.getPersonnelPhone());
|
|
|
- loginVO.setMachineCode(vo.getMachineCode());
|
|
|
- loginVO.setPersonnelConfig(personnel.getPersonConfig());
|
|
|
- //Sa-token 登录方法 登录后 生成Token 如果集成了Redis的话 会自动存入Redis
|
|
|
- StpUtil.login(personnel.getId());
|
|
|
- loginVO.setToken(StpUtil.getTokenValue());
|
|
|
+ LoginCommonDTO commonDTO = new LoginCommonDTO();
|
|
|
+ commonDTO.setAppKey(vo.getAppKey());
|
|
|
+ commonDTO.setSign(vo.getSign());
|
|
|
+ commonDTO.setCurrentTimeMillis(vo.getCurrentTimeMillis());
|
|
|
+ commonDTO.setMachineCode(vo.getMachineCode());
|
|
|
+ EncryptionLoginVO loginVO = this.loginCommonMethod(commonDTO, personnel);
|
|
|
return Response.success(loginVO);
|
|
|
}
|
|
|
|
|
@@ -606,15 +611,12 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
- public PhoneLoginVO loginByPhone(PhoneLoginDTO dto) throws Exception {
|
|
|
- String machineCode = dto.getMachineCode();
|
|
|
- this.checkRational(machineCode, dto.getSign(), dto.getAppKey(), dto.getCurrentTimeMillis());
|
|
|
+ public String loginByPhone(PhoneLoginDTO dto) throws Exception {
|
|
|
//获取缓存中验证码
|
|
|
String code = redisUtil.get(LoginCacheKeyUtil.getLoginCaptcha(dto.getPhoneNum()));
|
|
|
if (Boolean.TRUE.equals(StringUtils.isEmpty(code))) {
|
|
|
throw new XiaoShiException(ExceptionEnum.THE_PHONE_CODE_IS_INVALID);
|
|
|
}
|
|
|
-
|
|
|
//校验验证码
|
|
|
if (Boolean.TRUE.equals(StringUtils.isEmpty(dto.getPhoneCode()))) {
|
|
|
throw new XiaoShiException(ExceptionEnum.THE_PHONE_CODE_IS_NOT_NULL);
|
|
@@ -637,28 +639,13 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
if (person.getPersonnelStatus().equals(0)) {
|
|
|
throw new XiaoShiException(ExceptionEnum.THE_PERSONNEL_IS_FORBIDDEN);
|
|
|
}
|
|
|
- //人员信息中私钥或公钥为空则添加进去
|
|
|
- this.updatePersonnel(person.getPrivateKey(), person.getPublicKey(), person.getSymmetryKey(), person.getId());
|
|
|
- person = personnelMapper.selectById(person.getId());
|
|
|
- List<AssoPersonnelMachine> machineList = assoPersonnelMachineMapper.selectList(new LambdaQueryWrapper<AssoPersonnelMachine>()
|
|
|
- .eq(AssoPersonnelMachine::getPersonnelId, person.getId())
|
|
|
- .ne(AssoPersonnelMachine::getMachineCode, SecureUtil.md5(machineCode)));
|
|
|
- if (machineList.size() > 1) {
|
|
|
- throw new XiaoShiException(ExceptionEnum.DO_NOT_LOG_IN_TO_MORE_THAN_TWO_NEW_MACHINES_WITH_THE_SAME_ACCOUNT);
|
|
|
- }
|
|
|
- addOrUpdatePersonnelMachine(machineCode, person);
|
|
|
- PhoneLoginVO loginVO = new PhoneLoginVO();
|
|
|
- loginVO.setPersonId(person.getId());
|
|
|
- loginVO.setPersonnelUserName(person.getPersonnelUserName());
|
|
|
- loginVO.setPersonnelName(person.getPersonnelName());
|
|
|
- loginVO.setPersonnelPhone(person.getPersonnelPhone());
|
|
|
- loginVO.setPrivateKey(person.getPrivateKey());
|
|
|
- loginVO.setPersonnelConfig(person.getPersonConfig());
|
|
|
- loginVO.setMachineCode(loginVO.getMachineCode());
|
|
|
- //Sa-token 登录方法 登录后 生成Token 如果集成了Redis的话 会自动存入Redis
|
|
|
- StpUtil.login(person.getId());
|
|
|
- loginVO.setToken(StpUtil.getTokenValue());
|
|
|
- return loginVO;
|
|
|
+ LoginCommonDTO commonDTO = new LoginCommonDTO();
|
|
|
+ commonDTO.setAppKey(dto.getAppKey());
|
|
|
+ commonDTO.setSign(dto.getSign());
|
|
|
+ commonDTO.setCurrentTimeMillis(dto.getCurrentTimeMillis());
|
|
|
+ commonDTO.setMachineCode(dto.getMachineCode());
|
|
|
+ EncryptionLoginVO loginVO = this.loginCommonMethod(commonDTO, person);
|
|
|
+ return Response.success(loginVO);
|
|
|
}
|
|
|
|
|
|
public String generateInvitationCode() {
|