Commit 1eaf94e20adefaa5da237d869a5f4f87df6b39f3
Merge branch '20220829' into 'master'
feat: 默认密码是否需要重置 See merge request huang/thingsboard3.3.2!125
Showing
10 changed files
with
48 additions
and
22 deletions
@@ -54,12 +54,12 @@ public class YtTenantController extends AbstractUserAccount { | @@ -54,12 +54,12 @@ public class YtTenantController extends AbstractUserAccount { | ||
54 | SendResetPasswordEmailMsg msg = new SendResetPasswordEmailMsg(); | 54 | SendResetPasswordEmailMsg msg = new SendResetPasswordEmailMsg(); |
55 | msg.setUserId(userId); | 55 | msg.setUserId(userId); |
56 | msg.setMessageTypeEnum(MessageTypeEnum.PHONE_MESSAGE); | 56 | msg.setMessageTypeEnum(MessageTypeEnum.PHONE_MESSAGE); |
57 | - userService.sendRestPasswordMsg(msg); | 57 | + userService.sendRestPasswordMsg(getCurrentUser().getCurrentTenantId(),msg); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | @PostMapping("/sendRestPasswordMsg") | 61 | @PostMapping("/sendRestPasswordMsg") |
62 | - public void resetPassword(@RequestBody SendResetPasswordEmailMsg msg) { | ||
63 | - userService.sendRestPasswordMsg(msg); | 62 | + public void resetPassword(@RequestBody SendResetPasswordEmailMsg msg) throws ThingsboardException { |
63 | + userService.sendRestPasswordMsg(getCurrentUser().getCurrentTenantId(),msg); | ||
64 | } | 64 | } |
65 | } | 65 | } |
@@ -1154,6 +1154,7 @@ account: | @@ -1154,6 +1154,7 @@ account: | ||
1154 | emailSuffix: ${ACCOUNT_EMAIL_SUFFIX:yunteng.com} | 1154 | emailSuffix: ${ACCOUNT_EMAIL_SUFFIX:yunteng.com} |
1155 | # emailSuffix: thingskit.com | 1155 | # emailSuffix: thingskit.com |
1156 | defaultPassword: 123456 | 1156 | defaultPassword: 123456 |
1157 | + reset: ${ACCOUNT_PASSWORD_FORCE_RESET:true} | ||
1157 | third: | 1158 | third: |
1158 | wechat: | 1159 | wechat: |
1159 | url: https://api.weixin.qq.com | 1160 | url: https://api.weixin.qq.com |
@@ -10,6 +10,7 @@ import org.aspectj.lang.ProceedingJoinPoint; | @@ -10,6 +10,7 @@ import org.aspectj.lang.ProceedingJoinPoint; | ||
10 | import org.aspectj.lang.annotation.Around; | 10 | import org.aspectj.lang.annotation.Around; |
11 | import org.aspectj.lang.annotation.Aspect; | 11 | import org.aspectj.lang.annotation.Aspect; |
12 | import org.aspectj.lang.annotation.Pointcut; | 12 | import org.aspectj.lang.annotation.Pointcut; |
13 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; | ||
13 | import org.springframework.stereotype.Component; | 14 | import org.springframework.stereotype.Component; |
14 | import org.thingsboard.server.common.data.yunteng.common.YtCommonService; | 15 | import org.thingsboard.server.common.data.yunteng.common.YtCommonService; |
15 | import org.thingsboard.server.common.data.yunteng.common.aspect.annotation.AutoDict; | 16 | import org.thingsboard.server.common.data.yunteng.common.aspect.annotation.AutoDict; |
@@ -27,6 +28,7 @@ import java.util.List; | @@ -27,6 +28,7 @@ import java.util.List; | ||
27 | @Component | 28 | @Component |
28 | @Slf4j | 29 | @Slf4j |
29 | @RequiredArgsConstructor | 30 | @RequiredArgsConstructor |
31 | +@ConditionalOnExpression("('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core') ") | ||
30 | public class SysDictAspect { | 32 | public class SysDictAspect { |
31 | 33 | ||
32 | private final YtCommonService commonService; | 34 | private final YtCommonService commonService; |
@@ -36,7 +36,7 @@ public enum ErrorMessage { | @@ -36,7 +36,7 @@ public enum ErrorMessage { | ||
36 | USERNAME_IS_IMMUTABLE(400017,"用户账号不可变"), | 36 | USERNAME_IS_IMMUTABLE(400017,"用户账号不可变"), |
37 | CONFIG_IS_DISABLE(400018,"配置未启用"), | 37 | CONFIG_IS_DISABLE(400018,"配置未启用"), |
38 | IT_CANT_EQUAL_ITSELF(400019,"父级组织不可以为本身"), | 38 | IT_CANT_EQUAL_ITSELF(400019,"父级组织不可以为本身"), |
39 | - TARGET_TEMPLATE_NOT_EXISTS(400020,"目标模板不存在"), | 39 | + TARGET_TEMPLATE_NOT_EXISTS(400020,"不存在可用的消息模板"), |
40 | DEVICE_NOT_EXISTENCE_IN_TENANT(400021,"当前租户下不存在该设备"), | 40 | DEVICE_NOT_EXISTENCE_IN_TENANT(400021,"当前租户下不存在该设备"), |
41 | DEVICE_RELATION_IS_ABSENT(400022,"设备关联关系已不存在"), | 41 | DEVICE_RELATION_IS_ABSENT(400022,"设备关联关系已不存在"), |
42 | DATA_IS_DELETED(400023,"数据已经删除"), | 42 | DATA_IS_DELETED(400023,"数据已经删除"), |
@@ -59,7 +59,7 @@ public enum ErrorMessage { | @@ -59,7 +59,7 @@ public enum ErrorMessage { | ||
59 | DEVICE_LOSED(400039,"设备相关参数丢失"), | 59 | DEVICE_LOSED(400039,"设备相关参数丢失"), |
60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), | 60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), |
61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), | 61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), |
62 | - SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动正在使用该告警配置"), | 62 | + SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动【%s】正在使用该告警配置"), |
63 | APP_USER_BINDED(400043,"平台用户【%s】已被其它账号绑定"), | 63 | APP_USER_BINDED(400043,"平台用户【%s】已被其它账号绑定"), |
64 | THIRD_PLATFORM_EXCEPTION(400044,"【%s】,第三方异常【%s】"), | 64 | THIRD_PLATFORM_EXCEPTION(400044,"【%s】,第三方异常【%s】"), |
65 | DEVICE_NOT_EXTIED(400045,"设备不存在"), | 65 | DEVICE_NOT_EXTIED(400045,"设备不存在"), |
@@ -10,4 +10,5 @@ import org.springframework.stereotype.Component; | @@ -10,4 +10,5 @@ import org.springframework.stereotype.Component; | ||
10 | public class AccountProperties { | 10 | public class AccountProperties { |
11 | private String emailSuffix; | 11 | private String emailSuffix; |
12 | private String defaultPassword; | 12 | private String defaultPassword; |
13 | + private Boolean reset; | ||
13 | } | 14 | } |
1 | package org.thingsboard.server.dao.yunteng.impl; | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | ||
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
4 | import com.baomidou.mybatisplus.core.metadata.IPage; | 5 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
6 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
@@ -15,8 +16,10 @@ import org.thingsboard.server.common.data.yunteng.dto.*; | @@ -15,8 +16,10 @@ import org.thingsboard.server.common.data.yunteng.dto.*; | ||
15 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | 16 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
16 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
17 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; | 18 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; |
19 | +import org.thingsboard.server.dao.yunteng.entities.SceneLinkage; | ||
18 | import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; | 20 | import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; |
19 | import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | 21 | import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; |
22 | +import org.thingsboard.server.dao.yunteng.mapper.SceneLinkageMapper; | ||
20 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 23 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
21 | import org.thingsboard.server.dao.yunteng.service.AlarmProfileService; | 24 | import org.thingsboard.server.dao.yunteng.service.AlarmProfileService; |
22 | import org.thingsboard.server.dao.yunteng.service.DoActionService; | 25 | import org.thingsboard.server.dao.yunteng.service.DoActionService; |
@@ -35,6 +38,7 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | @@ -35,6 +38,7 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | ||
35 | private final UserOrganizationMappingServiceImpl userOrganizationMappingService; | 38 | private final UserOrganizationMappingServiceImpl userOrganizationMappingService; |
36 | 39 | ||
37 | private final OrganizationMapper ytOrganizationMapper; | 40 | private final OrganizationMapper ytOrganizationMapper; |
41 | + private final SceneLinkageMapper sceneLinkageMapper; | ||
38 | 42 | ||
39 | @Override | 43 | @Override |
40 | public YtPageData<AlarmProfileDTO> page( | 44 | public YtPageData<AlarmProfileDTO> page( |
@@ -74,10 +78,9 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | @@ -74,10 +78,9 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | ||
74 | if (!alarmProfile.getOrganizationId().equals(alarmProfileDTO.getOrganizationId())) { | 78 | if (!alarmProfile.getOrganizationId().equals(alarmProfileDTO.getOrganizationId())) { |
75 | Set<String> profiles = new HashSet<>(); | 79 | Set<String> profiles = new HashSet<>(); |
76 | profiles.add(alarmProfileDTO.getId()); | 80 | profiles.add(alarmProfileDTO.getId()); |
77 | - List<DoActionDTO> list = | ||
78 | - doActionService.findDoActionByAlarmProfileIds(alarmProfileDTO.getTenantId(), profiles); | ||
79 | - if (list.size() > FastIotConstants.MagicNumber.ZERO) { | ||
80 | - throw new YtDataValidationException(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage()); | 81 | + Set<String>names = alarmProfileUsed(alarmProfileDTO.getTenantId(), profiles); |
82 | + if(!names.isEmpty()){ | ||
83 | + throw new YtDataValidationException(String.format(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage(), names)); | ||
81 | } | 84 | } |
82 | } | 85 | } |
83 | baseMapper.updateById(alarmProfileDTO.getEntity(AlarmProfile.class)); | 86 | baseMapper.updateById(alarmProfileDTO.getEntity(AlarmProfile.class)); |
@@ -106,13 +109,32 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | @@ -106,13 +109,32 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | ||
106 | @Override | 109 | @Override |
107 | @Transactional | 110 | @Transactional |
108 | public boolean deleteAlarmProFile(DeleteDTO deleteDTO) { | 111 | public boolean deleteAlarmProFile(DeleteDTO deleteDTO) { |
112 | + Set<String>names = alarmProfileUsed(deleteDTO.getTenantId(), deleteDTO.getIds()); | ||
113 | + if(!names.isEmpty()){ | ||
114 | + throw new YtDataValidationException(String.format(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage(), names)); | ||
115 | + } | ||
116 | + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | ||
117 | + } | ||
118 | + | ||
119 | + private Set<String> alarmProfileUsed(String tenantId, Set<String> profileIds) { | ||
120 | + | ||
121 | + Set<String> sceneNames = new HashSet<>(); | ||
109 | // 如果有场景联动使用告警配置,则不能删除 | 122 | // 如果有场景联动使用告警配置,则不能删除 |
110 | List<DoActionDTO> list = | 123 | List<DoActionDTO> list = |
111 | - doActionService.findDoActionByAlarmProfileIds(deleteDTO.getTenantId(), deleteDTO.getIds()); | 124 | + doActionService.findDoActionByAlarmProfileIds(tenantId, profileIds); |
112 | if (list.size() > FastIotConstants.MagicNumber.ZERO) { | 125 | if (list.size() > FastIotConstants.MagicNumber.ZERO) { |
113 | - throw new YtDataValidationException(ErrorMessage.EXIST_LEADER_MEMBER_RELATION.getMessage()); | 126 | + Set<String> sceneIds = new HashSet<>(); |
127 | + for(DoActionDTO action:list){ | ||
128 | + sceneIds.add(action.getSceneLinkageId()); | ||
129 | + } | ||
130 | + List<SceneLinkage> scenes = sceneLinkageMapper.selectList(new QueryWrapper<SceneLinkage>().lambda() | ||
131 | + .eq(SceneLinkage::getId, sceneIds) | ||
132 | + ); | ||
133 | + for(SceneLinkage item: scenes){ | ||
134 | + sceneNames.add(item.getName()); | ||
135 | + } | ||
114 | } | 136 | } |
115 | - return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | 137 | + return sceneNames; |
116 | } | 138 | } |
117 | 139 | ||
118 | @Override | 140 | @Override |
@@ -6,10 +6,7 @@ import org.springframework.stereotype.Service; | @@ -6,10 +6,7 @@ import org.springframework.stereotype.Service; | ||
6 | import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | 6 | import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; |
7 | import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; | 7 | import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; |
8 | import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO; | 8 | import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO; |
9 | -import org.thingsboard.server.common.data.yunteng.enums.AssetStatusEnum; | ||
10 | -import org.thingsboard.server.common.data.yunteng.enums.EmailFormatEnum; | ||
11 | -import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum; | ||
12 | -import org.thingsboard.server.common.data.yunteng.enums.MsgTemplatePurposeEnum; | 9 | +import org.thingsboard.server.common.data.yunteng.enums.*; |
13 | import org.thingsboard.server.common.data.yunteng.utils.YtDateTimeUtils; | 10 | import org.thingsboard.server.common.data.yunteng.utils.YtDateTimeUtils; |
14 | import org.thingsboard.server.dao.yunteng.entities.*; | 11 | import org.thingsboard.server.dao.yunteng.entities.*; |
15 | import org.thingsboard.server.dao.yunteng.mapper.*; | 12 | import org.thingsboard.server.dao.yunteng.mapper.*; |
@@ -65,8 +62,10 @@ public class YtNoticeServiceImpl implements YtNoticeService { | @@ -65,8 +62,10 @@ public class YtNoticeServiceImpl implements YtNoticeService { | ||
65 | .eq(Organization::getId, device.getOrganizationId()); | 62 | .eq(Organization::getId, device.getOrganizationId()); |
66 | Organization organization = organizationMapper.selectOne(organizationQueryWrapper); | 63 | Organization organization = organizationMapper.selectOne(organizationQueryWrapper); |
67 | 64 | ||
68 | - | ||
69 | - AlarmProfile alarmProfile = alarmProfileMapper.selectById(profileId); | 65 | + QueryWrapper<AlarmProfile> profileQueryWrapper = new QueryWrapper<AlarmProfile>(); |
66 | + profileQueryWrapper.lambda() | ||
67 | + .eq(AlarmProfile::getId, profileId).eq(AlarmProfile::getStatus, StatusEnum.ENABLE.ordinal()); | ||
68 | + AlarmProfile alarmProfile = alarmProfileMapper.selectOne(profileQueryWrapper); | ||
70 | 69 | ||
71 | 70 | ||
72 | if (alarmProfile == null || alarmProfile.getAlarmContactId().isEmpty() || alarmProfile.getMessageMode().isEmpty()) { | 71 | if (alarmProfile == null || alarmProfile.getAlarmContactId().isEmpty() || alarmProfile.getMessageMode().isEmpty()) { |
@@ -145,7 +145,7 @@ public class YtSmsServiceImpl implements YtSmsService { | @@ -145,7 +145,7 @@ public class YtSmsServiceImpl implements YtSmsService { | ||
145 | .eq(MessageTemplate::getTemplatePurpose, purpose.name()) | 145 | .eq(MessageTemplate::getTemplatePurpose, purpose.name()) |
146 | .eq(MessageTemplate::getMessageType, MessageTypeEnum.PHONE_MESSAGE.name())); | 146 | .eq(MessageTemplate::getMessageType, MessageTypeEnum.PHONE_MESSAGE.name())); |
147 | if (messageTemplates.isEmpty()) { | 147 | if (messageTemplates.isEmpty()) { |
148 | - throw new YtDataValidationException("no sms provider config"); | 148 | + throw new YtDataValidationException(ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS.getMessage()); |
149 | } | 149 | } |
150 | String code = RandomStringUtils.randomNumeric(6); | 150 | String code = RandomStringUtils.randomNumeric(6); |
151 | LinkedHashMap<String, String> params = new LinkedHashMap<>(); | 151 | LinkedHashMap<String, String> params = new LinkedHashMap<>(); |
@@ -233,7 +233,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | @@ -233,7 +233,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | ||
233 | public UserInfoDTO me(String userId, String tenantId, Set<String> currentRoles) { | 233 | public UserInfoDTO me(String userId, String tenantId, Set<String> currentRoles) { |
234 | User user = baseMapper.selectById(userId); | 234 | User user = baseMapper.selectById(userId); |
235 | UserInfoDTO userInfoDTO = new UserInfoDTO(); | 235 | UserInfoDTO userInfoDTO = new UserInfoDTO(); |
236 | - if (!StringUtils.isEmpty(user.getActivateToken())) { | 236 | + if (!accountProperties.getReset() || !StringUtils.isEmpty(user.getActivateToken())) { |
237 | userInfoDTO.setNeedSetPwd(false); | 237 | userInfoDTO.setNeedSetPwd(false); |
238 | } | 238 | } |
239 | AtomicReference<LocalDateTime> expireTime = new AtomicReference<>(user.getAccountExpireTime()); | 239 | AtomicReference<LocalDateTime> expireTime = new AtomicReference<>(user.getAccountExpireTime()); |
@@ -510,7 +510,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | @@ -510,7 +510,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | ||
510 | } | 510 | } |
511 | 511 | ||
512 | @Override | 512 | @Override |
513 | - public void sendRestPasswordMsg(SendResetPasswordEmailMsg msg) { | 513 | + public void sendRestPasswordMsg(String tenantId,SendResetPasswordEmailMsg msg) { |
514 | // 通过用户ID查询用户信息 | 514 | // 通过用户ID查询用户信息 |
515 | User user = baseMapper.selectById(msg.getUserId()); | 515 | User user = baseMapper.selectById(msg.getUserId()); |
516 | if (null == user) { | 516 | if (null == user) { |
@@ -522,6 +522,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | @@ -522,6 +522,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | ||
522 | String messageType = msg.getMessageTypeEnum().name(); | 522 | String messageType = msg.getMessageTypeEnum().name(); |
523 | messageTemplateDTO.setMessageType(messageType); | 523 | messageTemplateDTO.setMessageType(messageType); |
524 | messageTemplateDTO.setTemplatePurpose(MsgTemplatePurposeEnum.FOR_SET_PASSWORD.name()); | 524 | messageTemplateDTO.setTemplatePurpose(MsgTemplatePurposeEnum.FOR_SET_PASSWORD.name()); |
525 | + messageTemplateDTO.setTenantId(tenantId); | ||
525 | messageTemplateDTO.setStatus(1); | 526 | messageTemplateDTO.setStatus(1); |
526 | List<MessageTemplateDTO> templateDTOList = | 527 | List<MessageTemplateDTO> templateDTOList = |
527 | messageTemplateService.findMessageTemplate(messageTemplateDTO); | 528 | messageTemplateService.findMessageTemplate(messageTemplateDTO); |
@@ -54,7 +54,7 @@ public interface YtUserService { | @@ -54,7 +54,7 @@ public interface YtUserService { | ||
54 | * | 54 | * |
55 | * @param msg 请求信息 | 55 | * @param msg 请求信息 |
56 | */ | 56 | */ |
57 | - void sendRestPasswordMsg(SendResetPasswordEmailMsg msg); | 57 | + void sendRestPasswordMsg(String tenantId,SendResetPasswordEmailMsg msg); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * 判断账号是否注册过 | 60 | * 判断账号是否注册过 |