Showing
5 changed files
with
37 additions
and
44 deletions
... | ... | @@ -14,6 +14,7 @@ import org.thingsboard.server.common.data.id.UserId; |
14 | 14 | import org.thingsboard.server.common.data.security.UserCredentials; |
15 | 15 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
17 | +import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | |
17 | 18 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
18 | 19 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
19 | 20 | import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; |
... | ... | @@ -64,8 +65,8 @@ public class YtThirdPlatformController extends BaseController { |
64 | 65 | @ApiOperation("绑定") |
65 | 66 | public JwtTokenPair saveOrUpdateAlarmProfile( |
66 | 67 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { |
67 | - String tbUserId = thirdService.saveOrUpdate(dto); | |
68 | - return buildJwtToken(tbUserId); | |
68 | + UserDTO userDto = thirdService.saveOrUpdate(dto); | |
69 | + return buildJwtToken(userDto); | |
69 | 70 | } |
70 | 71 | |
71 | 72 | @DeleteMapping |
... | ... | @@ -80,22 +81,24 @@ public class YtThirdPlatformController extends BaseController { |
80 | 81 | @ApiOperation("第三方登录") |
81 | 82 | public JwtTokenPair login(@PathVariable("thirdId") String thirdId) |
82 | 83 | throws ThingsboardException { |
83 | - String tbUserId = thirdService.login(thirdId); | |
84 | - return buildJwtToken(tbUserId); | |
84 | + UserDTO userDto = thirdService.login(thirdId); | |
85 | + return buildJwtToken(userDto); | |
85 | 86 | } |
86 | 87 | |
87 | 88 | @NotNull |
88 | - private JwtTokenPair buildJwtToken(String tbUserId) { | |
89 | + private JwtTokenPair buildJwtToken(UserDTO userDto) { | |
89 | 90 | String accessToken = ""; |
90 | 91 | String refreshToken = ""; |
91 | - if (StringUtils.isNotEmpty(tbUserId)) { | |
92 | - UserId userId = new UserId(UUID.fromString(tbUserId)); | |
92 | + if (userDto != null && StringUtils.isNotEmpty(userDto.getTbUser())) { | |
93 | + UserId userId = new UserId(UUID.fromString(userDto.getTbUser())); | |
93 | 94 | User user = userService.findUserById(null, userId); |
94 | 95 | UserCredentials credentials = userService.findUserCredentialsByUserId(user.getTenantId(), userId); |
95 | 96 | String email = user.getEmail(); |
96 | 97 | int emailIndex = email.indexOf("@"); |
97 | 98 | UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.USER_NAME, emailIndex > 0 ? email.substring(0, emailIndex) : email); |
98 | 99 | SecurityUser securityUser = new SecurityUser(user, credentials.isEnabled(), principal); |
100 | + securityUser.setCurrentUserId(userDto.getId()); | |
101 | + securityUser.setPlatformUserName(userDto.getUsername()); | |
99 | 102 | accessToken = tokenFactory.createAccessJwtToken(securityUser).getToken(); |
100 | 103 | refreshToken = refreshTokenRepository.requestRefreshToken(securityUser).getToken(); |
101 | 104 | ... | ... |
... | ... | @@ -6,26 +6,18 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
6 | 6 | import com.fasterxml.jackson.databind.JsonNode; |
7 | 7 | import lombok.RequiredArgsConstructor; |
8 | 8 | import lombok.extern.slf4j.Slf4j; |
9 | -import org.springframework.beans.factory.annotation.Autowired; | |
10 | 9 | import org.springframework.security.authentication.BadCredentialsException; |
11 | -import org.springframework.security.authentication.InsufficientAuthenticationException; | |
12 | -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | |
13 | 10 | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
14 | 11 | import org.springframework.security.crypto.password.PasswordEncoder; |
15 | 12 | import org.springframework.stereotype.Service; |
16 | 13 | import org.springframework.transaction.annotation.Transactional; |
17 | 14 | import org.thingsboard.server.common.data.StringUtils; |
18 | -import org.thingsboard.server.common.data.audit.ActionType; | |
19 | -import org.thingsboard.server.common.data.id.EntityId; | |
20 | -import org.thingsboard.server.common.data.id.TenantId; | |
21 | -import org.thingsboard.server.common.data.id.UserId; | |
22 | -import org.thingsboard.server.common.data.security.Authority; | |
23 | 15 | import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils; |
24 | 16 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
25 | 17 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
26 | 18 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
19 | +import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | |
27 | 20 | import org.thingsboard.server.common.data.yunteng.dto.UserDetailsDTO; |
28 | -import org.thingsboard.server.common.data.yunteng.dto.YtOpinionDTO; | |
29 | 21 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
30 | 22 | import org.thingsboard.server.common.data.yunteng.dto.request.CodeTTL; |
31 | 23 | import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum; |
... | ... | @@ -33,17 +25,14 @@ import org.thingsboard.server.common.data.yunteng.enums.MsgTemplatePurposeEnum; |
33 | 25 | import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; |
34 | 26 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
35 | 27 | import org.thingsboard.server.dao.yunteng.entities.User; |
36 | -import org.thingsboard.server.dao.yunteng.entities.YtOpinionEntity; | |
37 | 28 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
38 | 29 | import org.thingsboard.server.dao.yunteng.mapper.UserMapper; |
39 | -import org.thingsboard.server.dao.yunteng.mapper.YtOpinionMapper; | |
40 | 30 | import org.thingsboard.server.dao.yunteng.mapper.YtThirdPlatformMapper; |
41 | -import org.thingsboard.server.dao.yunteng.service.*; | |
31 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
32 | +import org.thingsboard.server.dao.yunteng.service.YtThirdPlatformService; | |
42 | 33 | |
43 | -import java.util.List; | |
44 | 34 | import java.util.Objects; |
45 | 35 | import java.util.Optional; |
46 | -import java.util.UUID; | |
47 | 36 | |
48 | 37 | import static org.thingsboard.server.common.data.yunteng.constant.FastIotConstants.CacheConfigKey.MOBILE_LOGIN_SMS_CODE; |
49 | 38 | import static org.thingsboard.server.common.data.yunteng.constant.FastIotConstants.DEFAULT_DELIMITER; |
... | ... | @@ -71,7 +60,7 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf |
71 | 60 | |
72 | 61 | @Override |
73 | 62 | @Transactional(rollbackFor = Exception.class) |
74 | - public String saveOrUpdate(YtThirdUserDTO dto) { | |
63 | + public UserDTO saveOrUpdate(YtThirdUserDTO dto) { | |
75 | 64 | User user = null; |
76 | 65 | switch (dto.getLoginMethod()) { |
77 | 66 | case PHONE: |
... | ... | @@ -99,7 +88,7 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf |
99 | 88 | dto.setId(oldVideo.getId()); |
100 | 89 | baseMapper.updateById(dto.getEntity(YtThirdUserEntity.class)); |
101 | 90 | } |
102 | - return user.getTbUser(); | |
91 | + return user.getDTO(UserDTO.class); | |
103 | 92 | } |
104 | 93 | |
105 | 94 | /** |
... | ... | @@ -177,8 +166,9 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf |
177 | 166 | } |
178 | 167 | |
179 | 168 | @Override |
180 | - public String login(String thirdUserId) { | |
181 | - return baseMapper.login(thirdUserId); | |
169 | + public UserDTO login(String thirdUserId) { | |
170 | + return baseMapper.login(thirdUserId) | |
171 | + .getDTO(UserDTO.class); | |
182 | 172 | } |
183 | 173 | |
184 | 174 | @Override | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.mapper; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | -import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | 4 | import org.apache.ibatis.annotations.Mapper; |
6 | 5 | import org.apache.ibatis.annotations.Param; |
7 | -import org.thingsboard.server.common.data.yunteng.dto.YtVideoDTO; | |
6 | +import org.thingsboard.server.dao.yunteng.entities.User; | |
8 | 7 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
9 | 8 | |
10 | -import java.util.List; | |
11 | - | |
12 | 9 | /** |
13 | 10 | * @author Administrator |
14 | 11 | */ |
... | ... | @@ -20,5 +17,5 @@ public interface YtThirdPlatformMapper extends BaseMapper<YtThirdUserEntity> { |
20 | 17 | * @param thirdId |
21 | 18 | * @return |
22 | 19 | */ |
23 | - String login(@Param("thirdId") String thirdId); | |
20 | + User login(@Param("thirdId") String thirdId); | |
24 | 21 | } | ... | ... |
... | ... | @@ -3,34 +3,36 @@ package org.thingsboard.server.dao.yunteng.service; |
3 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; |
4 | 4 | import com.fasterxml.jackson.databind.JsonNode; |
5 | 5 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
6 | -import org.thingsboard.server.common.data.yunteng.dto.YtOpinionDTO; | |
6 | +import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | |
7 | 7 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
10 | -import org.thingsboard.server.dao.yunteng.entities.YtOpinionEntity; | |
10 | +import org.thingsboard.server.dao.yunteng.entities.User; | |
11 | 11 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * 第三方平台用户管理相关接口 |
15 | 15 | * 例如:微信小程序、钉钉等。 |
16 | + * | |
16 | 17 | * @author Administrator |
17 | 18 | */ |
18 | 19 | public interface YtThirdPlatformService extends BaseService<YtThirdUserEntity> { |
19 | 20 | |
20 | 21 | /** |
21 | - * @param pageInfrom 分页配置信息 | |
22 | - * @param name 第三方平台用户昵称 | |
22 | + * @param pageInfrom 分页配置信息 | |
23 | + * @param name 第三方平台用户昵称 | |
23 | 24 | * @return |
24 | 25 | */ |
25 | - YtPageData<YtThirdUserDTO> pageDatas(IPage<YtThirdUserEntity> pageInfrom, ThirdPlatformEnum platformName,String name); | |
26 | + YtPageData<YtThirdUserDTO> pageDatas(IPage<YtThirdUserEntity> pageInfrom, ThirdPlatformEnum platformName, String name); | |
26 | 27 | |
27 | 28 | |
28 | - | |
29 | - /** 第三方平台用户与系统用户绑定 | |
29 | + /** | |
30 | + * 第三方平台用户与系统用户绑定 | |
31 | + * | |
30 | 32 | * @param dto |
31 | 33 | * @return |
32 | 34 | */ |
33 | - String saveOrUpdate(YtThirdUserDTO dto); | |
35 | + UserDTO saveOrUpdate(YtThirdUserDTO dto); | |
34 | 36 | |
35 | 37 | /** |
36 | 38 | * @param deleteDTO |
... | ... | @@ -40,16 +42,16 @@ public interface YtThirdPlatformService extends BaseService<YtThirdUserEntity> { |
40 | 42 | |
41 | 43 | /** |
42 | 44 | * 第三方登录 |
45 | + * | |
43 | 46 | * @param thirdUserId |
44 | 47 | * @return |
45 | 48 | */ |
46 | - String login(String thirdUserId); | |
47 | - | |
48 | - | |
49 | + UserDTO login(String thirdUserId); | |
49 | 50 | |
50 | 51 | |
51 | 52 | /** |
52 | 53 | * 访问令牌 |
54 | + * | |
53 | 55 | * @param appKey |
54 | 56 | * @param appSecret |
55 | 57 | * @return |
... | ... | @@ -58,10 +60,11 @@ public interface YtThirdPlatformService extends BaseService<YtThirdUserEntity> { |
58 | 60 | |
59 | 61 | /** |
60 | 62 | * 推送第三方程序消息 |
63 | + * | |
61 | 64 | * @param receiver |
62 | 65 | * @param message |
63 | 66 | * @return |
64 | 67 | */ |
65 | - JsonNode message(String receiver,JsonNode message); | |
68 | + JsonNode message(String receiver, JsonNode message); | |
66 | 69 | |
67 | 70 | } | ... | ... |
... | ... | @@ -3,8 +3,8 @@ |
3 | 3 | |
4 | 4 | <mapper namespace="org.thingsboard.server.dao.yunteng.mapper.YtThirdPlatformMapper"> |
5 | 5 | |
6 | - <select id="login" resultType="string"> | |
7 | - SELECT sus.tb_user | |
6 | + <select id="login" resultType="org.thingsboard.server.dao.yunteng.entities.User"> | |
7 | + SELECT sus.* | |
8 | 8 | FROM iotfs_third_user base |
9 | 9 | LEFT JOIN sys_user sus ON base.app_user_id = sus.id |
10 | 10 | <where> | ... | ... |