|
@@ -9,10 +9,13 @@ import cn.seecoder.seecoderportalserver.mapper.UserMapper;
|
|
|
import cn.seecoder.seecoderportalserver.security.DomainUserDetails;
|
|
import cn.seecoder.seecoderportalserver.security.DomainUserDetails;
|
|
|
import cn.seecoder.seecoderportalserver.security.SecurityUtils;
|
|
import cn.seecoder.seecoderportalserver.security.SecurityUtils;
|
|
|
import cn.seecoder.seecoderportalserver.security.jwt.TokenProvider;
|
|
import cn.seecoder.seecoderportalserver.security.jwt.TokenProvider;
|
|
|
|
|
+import cn.seecoder.seecoderportalserver.service.HttpService;
|
|
|
import cn.seecoder.seecoderportalserver.service.SuperService;
|
|
import cn.seecoder.seecoderportalserver.service.SuperService;
|
|
|
import cn.seecoder.seecoderportalserver.service.UserService;
|
|
import cn.seecoder.seecoderportalserver.service.UserService;
|
|
|
import cn.seecoder.seecoderportalserver.utility.OkResponse;
|
|
import cn.seecoder.seecoderportalserver.utility.OkResponse;
|
|
|
import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
|
|
import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
|
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
|
@@ -32,31 +35,25 @@ import javax.validation.Valid;
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api")
|
|
@RequestMapping("/api")
|
|
|
public class UserJWTController {
|
|
public class UserJWTController {
|
|
|
-
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(UserJWTController.class);
|
|
private static final Logger log = LoggerFactory.getLogger(UserJWTController.class);
|
|
|
-
|
|
|
|
|
private static final int ONE_DAY = 86400;
|
|
private static final int ONE_DAY = 86400;
|
|
|
-
|
|
|
|
|
private static final int THIRTY_DAY = 2592000;
|
|
private static final int THIRTY_DAY = 2592000;
|
|
|
-
|
|
|
|
|
private final TokenProvider tokenProvider;
|
|
private final TokenProvider tokenProvider;
|
|
|
-
|
|
|
|
|
private final AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
private final AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
|
-
|
|
|
|
|
private final UserService userService;
|
|
private final UserService userService;
|
|
|
-
|
|
|
|
|
private final UserMapper userMapper;
|
|
private final UserMapper userMapper;
|
|
|
-
|
|
|
|
|
private final SuperService superService;
|
|
private final SuperService superService;
|
|
|
|
|
+ private final HttpService httpService;
|
|
|
|
|
|
|
|
public UserJWTController(
|
|
public UserJWTController(
|
|
|
TokenProvider tokenProvider,
|
|
TokenProvider tokenProvider,
|
|
|
- AuthenticationManagerBuilder authenticationManagerBuilder, UserService userService, UserMapper userMapper, SuperService superService) {
|
|
|
|
|
|
|
+ AuthenticationManagerBuilder authenticationManagerBuilder, UserService userService, UserMapper userMapper, SuperService superService, HttpService httpService) {
|
|
|
this.tokenProvider = tokenProvider;
|
|
this.tokenProvider = tokenProvider;
|
|
|
this.authenticationManagerBuilder = authenticationManagerBuilder;
|
|
this.authenticationManagerBuilder = authenticationManagerBuilder;
|
|
|
this.userService = userService;
|
|
this.userService = userService;
|
|
|
this.userMapper = userMapper;
|
|
this.userMapper = userMapper;
|
|
|
this.superService = superService;
|
|
this.superService = superService;
|
|
|
|
|
+ this.httpService = httpService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/user/login")
|
|
@PostMapping("/user/login")
|
|
@@ -90,14 +87,30 @@ public class UserJWTController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/user/login/platform")
|
|
@PostMapping("/user/login/platform")
|
|
|
- public OkResponse<TokenVO> authorizePlatformUser(@RequestBody ValidateCodeDTO validateCodeDTO) {
|
|
|
|
|
- // todo: 验证code
|
|
|
|
|
- String jwt = tokenProvider.createPlatformToken(validateCodeDTO.getUserId());
|
|
|
|
|
- TokenVO tokenVO = new TokenVO();
|
|
|
|
|
- tokenVO.setToken(jwt);
|
|
|
|
|
- UserVO userVO = userService.findUserByUsername(validateCodeDTO.getUsername());
|
|
|
|
|
- tokenVO.setName(userVO.getName());
|
|
|
|
|
- tokenVO.setUser(userVO);
|
|
|
|
|
- return OkResponse.of(tokenVO);
|
|
|
|
|
|
|
+ public OkResponse<TokenVO> authorizePlatformUser(@RequestBody ValidateCodeDTO validateCodeDTO) throws CustomErrorException{
|
|
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
|
|
+ requestBody.put("userId", validateCodeDTO.getUserId());
|
|
|
|
|
+ requestBody.put("code", validateCodeDTO.getCode());
|
|
|
|
|
+ JSONObject httpResult;
|
|
|
|
|
+ try {
|
|
|
|
|
+ httpResult = JSON.parseObject(
|
|
|
|
|
+ httpService.sendPost("https://www.yuantusoft.com:8600/user/api/v1/external/verify/code",
|
|
|
|
|
+ requestBody, null, null)
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] keys = new String[]{"res", "code"};
|
|
|
|
|
+ if (httpResult.getInteger(keys[1]) == 0) {
|
|
|
|
|
+ String jwt = tokenProvider.createPlatformToken(validateCodeDTO.getUserId());
|
|
|
|
|
+ TokenVO tokenVO = new TokenVO();
|
|
|
|
|
+ tokenVO.setToken(jwt);
|
|
|
|
|
+ UserVO userVO = userService.findUserByUsername(validateCodeDTO.getUsername());
|
|
|
|
|
+ tokenVO.setName(userVO.getName());
|
|
|
|
|
+ tokenVO.setUser(userVO);
|
|
|
|
|
+ return OkResponse.of(tokenVO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new CustomErrorException(httpResult.getString(keys[0]));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|