Commit 33d16703d3f5a35b6d26b052fa41b4c24198d01d
Merge branch '20220429' into 'master'
refactor: 微信小程序登录和绑定增加第三方平台用户ID See merge request huang/thingsboard3.3.2!90
Showing
1 changed file
with
11 additions
and
10 deletions
... | ... | @@ -5,8 +5,6 @@ import io.swagger.annotations.Api; |
5 | 5 | import io.swagger.annotations.ApiOperation; |
6 | 6 | import lombok.RequiredArgsConstructor; |
7 | 7 | import org.jetbrains.annotations.NotNull; |
8 | -import org.springframework.http.HttpStatus; | |
9 | -import org.springframework.http.ResponseEntity; | |
10 | 8 | import org.springframework.validation.annotation.Validated; |
11 | 9 | import org.springframework.web.bind.annotation.*; |
12 | 10 | import org.thingsboard.server.common.data.StringUtils; |
... | ... | @@ -15,7 +13,6 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
15 | 13 | import org.thingsboard.server.common.data.id.UserId; |
16 | 14 | import org.thingsboard.server.common.data.security.UserCredentials; |
17 | 15 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
18 | -import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
19 | 16 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; |
20 | 17 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
21 | 18 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
... | ... | @@ -25,6 +22,7 @@ import org.thingsboard.server.controller.BaseController; |
25 | 22 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
26 | 23 | import org.thingsboard.server.dao.yunteng.service.YtThirdPlatformService; |
27 | 24 | import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; |
25 | +import org.thingsboard.server.service.security.auth.yunteng.YtLoginResponse; | |
28 | 26 | import org.thingsboard.server.service.security.model.JwtTokenPair; |
29 | 27 | import org.thingsboard.server.service.security.model.SecurityUser; |
30 | 28 | import org.thingsboard.server.service.security.model.UserPrincipal; |
... | ... | @@ -65,10 +63,10 @@ public class YtThirdPlatformController extends BaseController { |
65 | 63 | |
66 | 64 | @PostMapping("bind") |
67 | 65 | @ApiOperation("绑定") |
68 | - public JwtTokenPair saveOrUpdateAlarmProfile( | |
66 | + public YtLoginResponse saveOrUpdateAlarmProfile( | |
69 | 67 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { |
70 | 68 | UserDTO userDto = thirdService.bindUser(dto); |
71 | - return buildJwtToken(userDto); | |
69 | + return buildJwtToken(userDto,dto.getThirdUserId()); | |
72 | 70 | } |
73 | 71 | |
74 | 72 | @DeleteMapping |
... | ... | @@ -80,18 +78,18 @@ public class YtThirdPlatformController extends BaseController { |
80 | 78 | |
81 | 79 | @GetMapping("login/{loginCode}") |
82 | 80 | @ApiOperation("第三方登录") |
83 | - public JwtTokenPair login(@PathVariable("loginCode") String loginCode) | |
81 | + public YtLoginResponse login(@PathVariable("loginCode") String loginCode) | |
84 | 82 | throws ThingsboardException { |
85 | 83 | String thirdUserId = thirdService.thirdLogin(loginCode); |
86 | 84 | UserDTO userDto = thirdService.login(thirdUserId); |
87 | 85 | if(userDto == null){ |
88 | - return new JwtTokenPair("", thirdUserId); | |
86 | + return new YtLoginResponse().setThirdUserId(thirdUserId); | |
89 | 87 | } |
90 | - return buildJwtToken(userDto); | |
88 | + return buildJwtToken(userDto,thirdUserId); | |
91 | 89 | } |
92 | 90 | |
93 | 91 | @NotNull |
94 | - private JwtTokenPair buildJwtToken(UserDTO userDto) { | |
92 | + private YtLoginResponse buildJwtToken(UserDTO userDto,String thirdUserId) { | |
95 | 93 | String accessToken = ""; |
96 | 94 | String refreshToken = ""; |
97 | 95 | if (userDto != null && StringUtils.isNotEmpty(userDto.getTbUser())) { |
... | ... | @@ -108,7 +106,10 @@ public class YtThirdPlatformController extends BaseController { |
108 | 106 | refreshToken = refreshTokenRepository.requestRefreshToken(securityUser).getToken(); |
109 | 107 | |
110 | 108 | } |
111 | - return new JwtTokenPair(accessToken, refreshToken); | |
109 | + YtLoginResponse result = new YtLoginResponse(); | |
110 | + result.setToken(accessToken); | |
111 | + result.setRefreshToken(refreshToken); | |
112 | + return result.setThirdUserId(thirdUserId); | |
112 | 113 | } |
113 | 114 | |
114 | 115 | ... | ... |