|
@@ -9,10 +9,8 @@ import com.abi.qms.platform.dao.enums.FactoryTypeEnum;
|
|
|
import com.abi.qms.platform.dao.enums.TrueFalseEnum;
|
|
|
import com.abi.qms.platform.dao.mapper.UserInfoMapper;
|
|
|
import com.abi.qms.platform.dao.mapper.UserRoleMapper;
|
|
|
-import com.abi.qms.platform.dto.req.LoginReq;
|
|
|
-import com.abi.qms.platform.dto.req.ResetPasswordReq;
|
|
|
-import com.abi.qms.platform.dto.req.TokenReq;
|
|
|
-import com.abi.qms.platform.dto.req.UpdatePasswordReq;
|
|
|
+import com.abi.qms.platform.dto.req.*;
|
|
|
+import com.abi.qms.platform.dto.res.GetLoginUserInfoRes;
|
|
|
import com.abi.qms.platform.dto.res.LoginActivateRes;
|
|
|
import com.abi.qms.platform.dto.res.LoginRes;
|
|
|
import com.abi.qms.platform.infrastructure.util.UserUtil;
|
|
@@ -20,6 +18,7 @@ import com.abi.qms.platform.service.LoginService;
|
|
|
import com.abi.qms.platform.service.RoleManagerService;
|
|
|
import com.abi.task.common.api.exception.BusinessException;
|
|
|
import com.abi.task.common.utils.AESEncodeTwoUtil;
|
|
|
+import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -198,25 +197,29 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
}
|
|
|
|
|
|
UserInfo userInfo = userInfoMapper.selectById(req.getId());
|
|
|
- if (ObjectUtil.isNotEmpty(userInfo)) {
|
|
|
- if(TrueFalseEnum.TRUE.is(req.getIsDefaultPassword())){
|
|
|
- userInfo.setPassword(DEFAULT_PASSWORD);
|
|
|
- }else{
|
|
|
- userInfo.setPassword(req.getPassword());
|
|
|
- }
|
|
|
- userInfoMapper.updateById(userInfo);
|
|
|
- userUtil.releaseUser();
|
|
|
- //删除redis用户token信息
|
|
|
- String userToken = TOKEN_KEY_USER_ID + userInfo.getId();
|
|
|
- if (!redisClient.hasKey(userToken)) {
|
|
|
- return ;
|
|
|
- }
|
|
|
- String token = redisClient.get(userToken);
|
|
|
- redisClient.delete(TOKEN_KEY_USER_ID + userInfo.getId());
|
|
|
- if (!StringUtils.isEmpty(token)){
|
|
|
- String redisTokenKey = MessageFormat.format("{0}:{1}",TOKEN_KEY,token);
|
|
|
- redisClient.delete(redisTokenKey);
|
|
|
- }
|
|
|
+ if (ObjectUtil.isEmpty(userInfo)) {
|
|
|
+ throw new BusinessException("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果前端灭有传重置得密码,则用默认密码
|
|
|
+ if(TrueFalseEnum.TRUE.is(req.getIsDefaultPassword())){
|
|
|
+ userInfo.setPassword(DEFAULT_PASSWORD);
|
|
|
+ }else{
|
|
|
+ userInfo.setPassword(req.getPassword());
|
|
|
+ }
|
|
|
+ userInfoMapper.updateById(userInfo);
|
|
|
+ userUtil.releaseUser();
|
|
|
+
|
|
|
+ //删除redis用户token信息
|
|
|
+ String userToken = TOKEN_KEY_USER_ID + userInfo.getId();
|
|
|
+ if (!redisClient.hasKey(userToken)) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ String token = redisClient.get(userToken);
|
|
|
+ redisClient.delete(TOKEN_KEY_USER_ID + userInfo.getId());
|
|
|
+ if (!StringUtils.isEmpty(token)){
|
|
|
+ String redisTokenKey = MessageFormat.format("{0}:{1}",TOKEN_KEY,token);
|
|
|
+ redisClient.delete(redisTokenKey);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -224,28 +227,60 @@ public class LoginServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> impl
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updatePassword(UpdatePasswordReq req) {
|
|
|
UserInfo userInfo = userInfoMapper.selectById(req.getId());
|
|
|
+
|
|
|
+ //校验旧密码
|
|
|
String oldPassword = AESEncodeTwoUtil.encrypt(req.getOldPassword());
|
|
|
- if (oldPassword.equals(userInfo.getPassword())) {
|
|
|
- userInfo.setPassword(req.getNewPassword());
|
|
|
- userInfoMapper.updateById(userInfo);
|
|
|
- String userToken = TOKEN_KEY_USER_ID + userInfo.getId();
|
|
|
- if (!redisClient.hasKey(userToken)) {
|
|
|
- return ;
|
|
|
- }
|
|
|
- String token = redisClient.get(userToken);
|
|
|
- redisClient.delete(TOKEN_KEY_USER_ID + userInfo.getId());
|
|
|
- if (!StringUtils.isEmpty(token)){
|
|
|
- String redisTokenKey = MessageFormat.format("{0}:{1}",TOKEN_KEY,token);
|
|
|
- redisClient.delete(redisTokenKey);
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new BusinessException("请输入正确的密码");
|
|
|
+ if (!oldPassword.equals(userInfo.getPassword())) {
|
|
|
+ throw new BusinessException("原密码不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改密码
|
|
|
+ userInfo.setPassword(req.getNewPassword());
|
|
|
+ userInfoMapper.updateById(userInfo);
|
|
|
+
|
|
|
+ //清空用户token
|
|
|
+ userUtil.releaseUser();
|
|
|
+ //删除redis用户token信息
|
|
|
+ String userToken = TOKEN_KEY_USER_ID + userInfo.getId();
|
|
|
+ if (!redisClient.hasKey(userToken)) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ String token = redisClient.get(userToken);
|
|
|
+ redisClient.delete(TOKEN_KEY_USER_ID + userInfo.getId());
|
|
|
+ if (!StringUtils.isEmpty(token)){
|
|
|
+ String redisTokenKey = MessageFormat.format("{0}:{1}",TOKEN_KEY,token);
|
|
|
+ redisClient.delete(redisTokenKey);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修改登录用户邮箱
|
|
|
+ **/
|
|
|
@Override
|
|
|
- public UserInfo validateToken(TokenReq req) {
|
|
|
+ public void updateLoginUserEmail(UpdateLoginUserEmailReq req) {
|
|
|
+ UserInfo userInfo = userInfoMapper.selectById(userUtil.getUser().getId());
|
|
|
+ if(userInfo == null){
|
|
|
+ throw new BusinessException("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ userInfo.setEmail(req.getEmail());
|
|
|
+ userInfoMapper.updateById(userInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询登录用户信息
|
|
|
+ **/
|
|
|
+ @Override
|
|
|
+ public GetLoginUserInfoRes getLoginUserInfo(GetLoginUserInfoReq req) {
|
|
|
+ UserInfo userInfo = userInfoMapper.selectById(userUtil.getUser().getId());
|
|
|
+ if(userInfo == null){
|
|
|
+ throw new BusinessException("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ GetLoginUserInfoRes res = PojoConverterUtils.copy(userInfo,GetLoginUserInfoRes.class);
|
|
|
|
|
|
- return null;
|
|
|
+ return res;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|