fix - 调整登陆成功后的页面地址
This commit is contained in:
parent
e9e2c026ad
commit
84cc69dad3
@ -234,8 +234,12 @@ public class DangerOperationController {
|
||||
@GetMapping("/web/process/dingtalk-callback")
|
||||
public String dingTalkCallback(@RequestParam("authCode") String authCode, HttpSession session, Model model, javax.servlet.http.HttpServletRequest request) {
|
||||
log.info("收到钉钉登录回调, authCode: {}", authCode);
|
||||
String myPodNamespace = environment.getProperty(K8S_POD_NAME_SPACE);
|
||||
String baseUrl = StringUtils.hasText(myPodNamespace) ? "/workflow-engine" : "";
|
||||
model.addAttribute("apiBaseUrl", baseUrl);
|
||||
model.addAttribute("dingTalkAppKey", appKey);
|
||||
|
||||
// 如果没有配置 AppSecret,则无法进行后续交互,直接返回错误(或者为了测试方便这里可以留个后门? 不,严格处理)
|
||||
// 如果没有配置 AppSecret,则无法进行后续交互
|
||||
if (!StringUtils.hasText(appSecret)) {
|
||||
log.error("DingTalk AppSecret not configured");
|
||||
model.addAttribute("authError", "服务端未配置 AppSecret,无法登录");
|
||||
@ -244,7 +248,6 @@ public class DangerOperationController {
|
||||
|
||||
try {
|
||||
// 1. 获取 AccessToken
|
||||
// 文档: https://open.dingtalk.com/document/isvapp/obtain-user-token
|
||||
JSONObject tokenParams = new JSONObject();
|
||||
tokenParams.put("clientId", appKey);
|
||||
tokenParams.put("clientSecret", appSecret);
|
||||
@ -268,7 +271,6 @@ public class DangerOperationController {
|
||||
}
|
||||
|
||||
// 2. 获取用户详情
|
||||
// 文档: https://open.dingtalk.com/document/isvapp/obtain-user-information
|
||||
String userInfoResponse = HttpRequest.get("https://api.dingtalk.com/v1.0/contact/users/me")
|
||||
.header("x-acs-dingtalk-access-token", accessToken)
|
||||
.timeout(5000)
|
||||
@ -292,12 +294,16 @@ public class DangerOperationController {
|
||||
return "form";
|
||||
}
|
||||
|
||||
|
||||
// 3. 登录成功
|
||||
log.info("DingTalk Login Success: nick={}, mobile={}", nick, mobile);
|
||||
session.setAttribute("isAuthenticated", true);
|
||||
// 可以把用户信息也存进去
|
||||
session.setAttribute("dingUser", userJson);
|
||||
model.addAttribute("userNick", nick);
|
||||
model.addAttribute("isAuthenticated", true);
|
||||
|
||||
// 新增:添加重定向URL到Model,让前端JS执行跳转
|
||||
model.addAttribute("redirectUrl", baseUrl + "/web/process/form");
|
||||
|
||||
return "form";
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -303,6 +303,14 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script th:inline="javascript">
|
||||
// 检查并执行重定向
|
||||
const redirectUrl = /*[[${redirectUrl}]]*/ null;
|
||||
if (redirectUrl) {
|
||||
window.location.replace(redirectUrl);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// 获取DOM元素
|
||||
const operationType = document.getElementById('operationType');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user