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,8 +5,6 @@ import io.swagger.annotations.Api; | ||
5 | import io.swagger.annotations.ApiOperation; | 5 | import io.swagger.annotations.ApiOperation; |
6 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
7 | import org.jetbrains.annotations.NotNull; | 7 | import org.jetbrains.annotations.NotNull; |
8 | -import org.springframework.http.HttpStatus; | ||
9 | -import org.springframework.http.ResponseEntity; | ||
10 | import org.springframework.validation.annotation.Validated; | 8 | import org.springframework.validation.annotation.Validated; |
11 | import org.springframework.web.bind.annotation.*; | 9 | import org.springframework.web.bind.annotation.*; |
12 | import org.thingsboard.server.common.data.StringUtils; | 10 | import org.thingsboard.server.common.data.StringUtils; |
@@ -15,7 +13,6 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; | @@ -15,7 +13,6 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
15 | import org.thingsboard.server.common.data.id.UserId; | 13 | import org.thingsboard.server.common.data.id.UserId; |
16 | import org.thingsboard.server.common.data.security.UserCredentials; | 14 | import org.thingsboard.server.common.data.security.UserCredentials; |
17 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | 15 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
18 | -import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
19 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | 16 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; |
20 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; | 17 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
21 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 18 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
@@ -25,6 +22,7 @@ import org.thingsboard.server.controller.BaseController; | @@ -25,6 +22,7 @@ import org.thingsboard.server.controller.BaseController; | ||
25 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; | 22 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
26 | import org.thingsboard.server.dao.yunteng.service.YtThirdPlatformService; | 23 | import org.thingsboard.server.dao.yunteng.service.YtThirdPlatformService; |
27 | import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; | 24 | import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; |
25 | +import org.thingsboard.server.service.security.auth.yunteng.YtLoginResponse; | ||
28 | import org.thingsboard.server.service.security.model.JwtTokenPair; | 26 | import org.thingsboard.server.service.security.model.JwtTokenPair; |
29 | import org.thingsboard.server.service.security.model.SecurityUser; | 27 | import org.thingsboard.server.service.security.model.SecurityUser; |
30 | import org.thingsboard.server.service.security.model.UserPrincipal; | 28 | import org.thingsboard.server.service.security.model.UserPrincipal; |
@@ -65,10 +63,10 @@ public class YtThirdPlatformController extends BaseController { | @@ -65,10 +63,10 @@ public class YtThirdPlatformController extends BaseController { | ||
65 | 63 | ||
66 | @PostMapping("bind") | 64 | @PostMapping("bind") |
67 | @ApiOperation("绑定") | 65 | @ApiOperation("绑定") |
68 | - public JwtTokenPair saveOrUpdateAlarmProfile( | 66 | + public YtLoginResponse saveOrUpdateAlarmProfile( |
69 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { | 67 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { |
70 | UserDTO userDto = thirdService.bindUser(dto); | 68 | UserDTO userDto = thirdService.bindUser(dto); |
71 | - return buildJwtToken(userDto); | 69 | + return buildJwtToken(userDto,dto.getThirdUserId()); |
72 | } | 70 | } |
73 | 71 | ||
74 | @DeleteMapping | 72 | @DeleteMapping |
@@ -80,18 +78,18 @@ public class YtThirdPlatformController extends BaseController { | @@ -80,18 +78,18 @@ public class YtThirdPlatformController extends BaseController { | ||
80 | 78 | ||
81 | @GetMapping("login/{loginCode}") | 79 | @GetMapping("login/{loginCode}") |
82 | @ApiOperation("第三方登录") | 80 | @ApiOperation("第三方登录") |
83 | - public JwtTokenPair login(@PathVariable("loginCode") String loginCode) | 81 | + public YtLoginResponse login(@PathVariable("loginCode") String loginCode) |
84 | throws ThingsboardException { | 82 | throws ThingsboardException { |
85 | String thirdUserId = thirdService.thirdLogin(loginCode); | 83 | String thirdUserId = thirdService.thirdLogin(loginCode); |
86 | UserDTO userDto = thirdService.login(thirdUserId); | 84 | UserDTO userDto = thirdService.login(thirdUserId); |
87 | if(userDto == null){ | 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 | @NotNull | 91 | @NotNull |
94 | - private JwtTokenPair buildJwtToken(UserDTO userDto) { | 92 | + private YtLoginResponse buildJwtToken(UserDTO userDto,String thirdUserId) { |
95 | String accessToken = ""; | 93 | String accessToken = ""; |
96 | String refreshToken = ""; | 94 | String refreshToken = ""; |
97 | if (userDto != null && StringUtils.isNotEmpty(userDto.getTbUser())) { | 95 | if (userDto != null && StringUtils.isNotEmpty(userDto.getTbUser())) { |
@@ -108,7 +106,10 @@ public class YtThirdPlatformController extends BaseController { | @@ -108,7 +106,10 @@ public class YtThirdPlatformController extends BaseController { | ||
108 | refreshToken = refreshTokenRepository.requestRefreshToken(securityUser).getToken(); | 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 |