|
|
@@ -1,23 +1,22 @@
|
|
|
-package com.zswl.dataservice.controller;
|
|
|
+package com.zswl.dataservice.controller.user;
|
|
|
|
|
|
-import com.zswl.dataservice.model.TokenModel;
|
|
|
import com.zswl.dataservice.model.params.LoginModel;
|
|
|
-import com.zswl.dataservice.model.params.TokenParam;
|
|
|
-import com.zswl.dataservice.service.AppInfoService;
|
|
|
-import com.zswl.dataservice.service.AuthService;
|
|
|
-import com.zswl.dataservice.service.UserService;
|
|
|
+import com.zswl.dataservice.model.user.LoginUser;
|
|
|
+import com.zswl.dataservice.service.user.AuthService;
|
|
|
+import com.zswl.dataservice.service.user.UserService;
|
|
|
import com.zswl.dataservice.utils.result.ResultContent;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import jakarta.servlet.http.Cookie;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
/**
|
|
|
* 访问令牌 服务
|
|
|
*
|
|
|
@@ -27,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
@RequestMapping("/oauth")
|
|
|
@RestController
|
|
|
@Validated
|
|
|
+@Tag(name = "登录")
|
|
|
public class OauthController {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -43,14 +43,23 @@ public class OauthController {
|
|
|
|
|
|
@Operation(summary = "创建Token,需要提供登录名和密码!")
|
|
|
@RequestMapping(value = "/free/token", method = {RequestMethod.POST})
|
|
|
- public ResultContent createToken(LoginModel data) {
|
|
|
+ public ResultContent createToken(LoginModel data, HttpServletRequest request, HttpServletResponse response) {
|
|
|
if (StringUtils.isEmpty(data.getLoginName())) {
|
|
|
return ResultContent.buildFail("登录名不能为空");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(data.getPassWord())) {
|
|
|
return ResultContent.buildFail("密码名不能为空");
|
|
|
}
|
|
|
- return authService.createToken(data);
|
|
|
+ ResultContent<LoginUser> resultContent = authService.createToken(data);
|
|
|
+ if (resultContent.isSuccess()) {
|
|
|
+ LoginUser loginUser = resultContent.getContent();
|
|
|
+ response.setHeader("accessToken", loginUser.getToken());
|
|
|
+ Cookie cookie = new Cookie("accessToken", loginUser.getToken());
|
|
|
+ cookie.setMaxAge(60 * 60 * 24 * 3);
|
|
|
+ cookie.setPath("/");
|
|
|
+ response.addCookie(cookie);
|
|
|
+ }
|
|
|
+ return resultContent;
|
|
|
}
|
|
|
|
|
|
}
|