diff --git a/dinky-admin/src/main/java/org/dinky/aop/exception/WebExceptionHandler.java b/dinky-admin/src/main/java/org/dinky/aop/exception/WebExceptionHandler.java index 219f62c063..cc498e7d98 100644 --- a/dinky-admin/src/main/java/org/dinky/aop/exception/WebExceptionHandler.java +++ b/dinky-admin/src/main/java/org/dinky/aop/exception/WebExceptionHandler.java @@ -77,6 +77,7 @@ public Result busException(BusException e) { @ExceptionHandler @ResponseBody + @ResponseStatus(HttpStatus.UNAUTHORIZED) public Result notLoginException(NotLoginException notLoginException) { ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); @@ -91,7 +92,7 @@ public Result notLoginException(NotLoginException notLoginException) { } /** - * 参数异常处理程序 设置状态码为 400 + * Parameter exception handler sets status code to 400 * * @param e e * @return {@link Result}<{@link String}> @@ -101,11 +102,11 @@ public Result notLoginException(NotLoginException notLoginException) { @ResponseBody public Result paramExceptionHandler(MethodArgumentNotValidException e) { BindingResult exceptions = e.getBindingResult(); - // 判断异常中是否有错误信息,如果存在就使用异常中的消息,否则使用默认消息 + // Check if there is any error message in the exception. If there is, use the message in the exception. Otherwise, use the default message if (exceptions.hasErrors()) { List errors = exceptions.getAllErrors(); if (!errors.isEmpty()) { - // 这里列出了全部错误参数,按正常逻辑,只需要第一条错误即可 + // All incorrect parameters are listed here. According to normal logic, only the first error is needed FieldError fieldError = (FieldError) errors.get(0); if (StringUtils.isNotBlank(fieldError.getDefaultMessage())) { return Result.paramsError( diff --git a/dinky-admin/src/main/java/org/dinky/controller/APIController.java b/dinky-admin/src/main/java/org/dinky/controller/APIController.java index bcc8d223c7..eba78256ea 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/APIController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/APIController.java @@ -47,6 +47,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -62,6 +63,7 @@ @Api(tags = "OpenAPI & Task API Controller") @RequestMapping("/openapi") @RequiredArgsConstructor +@SaCheckLogin public class APIController { private final TaskService taskService; @@ -70,7 +72,7 @@ public class APIController { @GetMapping("/version") @ApiOperation(value = "Query Service Version", notes = "Query Dinky Service Version Number") public Result getVersionInfo() { - return Result.succeed(DinkyVersion.getVersion(), "Get success"); + return Result.succeed(DinkyVersion.getVersion(), Status.QUERY_SUCCESS); } @PostMapping("/submitTask") @@ -200,6 +202,6 @@ public Result exportSql(@RequestParam Integer id) { dataTypeClass = Integer.class) public Result getTaskLineage(@RequestParam Integer id) { taskService.initTenantByTaskId(id); - return Result.succeed(taskService.getTaskLineage(id), "获取成功"); + return Result.succeed(taskService.getTaskLineage(id), Status.QUERY_SUCCESS); } } diff --git a/dinky-admin/src/main/java/org/dinky/controller/AdminController.java b/dinky-admin/src/main/java/org/dinky/controller/AdminController.java index 6f6c401fc1..327768c20d 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AdminController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AdminController.java @@ -27,6 +27,7 @@ import org.dinky.data.result.Result; import org.dinky.service.UserService; +import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -35,7 +36,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaIgnore; +import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.stp.SaTokenInfo; import cn.dev33.satoken.stp.StpUtil; import io.swagger.annotations.Api; @@ -92,8 +95,13 @@ public Result outLogin() { */ @GetMapping("/current") @ApiOperation(value = "Current User Info", notes = "Current User Info") - public Result getCurrentUserInfo() { - return userService.queryCurrentUserInfo(); + @SaCheckLogin + public Result getCurrentUserInfo(@CookieValue(name = "tenantId") Integer tenantId) { + if (tenantId == null) { + throw NotLoginException.newInstance( + "LOCAL", NotLoginException.NOT_TOKEN, NotLoginException.NOT_TOKEN_MESSAGE, null); + } + return userService.queryCurrentUserInfo(tenantId); } /** @@ -105,6 +113,7 @@ public Result getCurrentUserInfo() { @PostMapping("/chooseTenant") @ApiImplicitParam(name = "tenantId", value = "tenantId", required = true, dataTypeClass = Integer.class) @ApiOperation(value = "Choose Tenant To Login", notes = "Choose Tenant To Login") + @SaCheckLogin public Result switchingTenant(@RequestParam("tenantId") Integer tenantId) { return userService.chooseTenant(tenantId); } @@ -116,12 +125,14 @@ public Result switchingTenant(@RequestParam("tenantId") Integer tenantId */ @GetMapping("/tokenInfo") @ApiOperation(value = "Query Current User Token Info", notes = "Query Current User Token Info") + @SaCheckLogin public Result getTokenInfo() { return Result.succeed(StpUtil.getTokenInfo()); } @GetMapping("/version") @ApiOperation(value = "Query Service Version", notes = "Query Dinky Service Version Number") + @SaCheckLogin public Result getVersionInfo() { return Result.succeed((Object) DinkyVersion.getVersion()); } diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertGroupController.java b/dinky-admin/src/main/java/org/dinky/controller/AlertGroupController.java index 4c141e8a60..29555b4e4f 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertGroupController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertGroupController.java @@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -51,6 +52,7 @@ @Api(tags = "Alert Group Controller") @RequestMapping("/api/alertGroup") @RequiredArgsConstructor +@SaCheckLogin public class AlertGroupController { private final AlertGroupService alertGroupService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertHistoryController.java b/dinky-admin/src/main/java/org/dinky/controller/AlertHistoryController.java index 8be8c6c61e..c3e49acd3f 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertHistoryController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertHistoryController.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -50,6 +51,7 @@ @Api(tags = "Alert History Controller") @RequestMapping("/api/alertHistory") @RequiredArgsConstructor +@SaCheckLogin public class AlertHistoryController { private final AlertHistoryService alertHistoryService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertInstanceController.java b/dinky-admin/src/main/java/org/dinky/controller/AlertInstanceController.java index b4334dee9b..8a2428c236 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertInstanceController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertInstanceController.java @@ -44,6 +44,7 @@ import com.github.xiaoymin.knife4j.annotations.DynamicParameter; import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -60,6 +61,7 @@ @Api(tags = "Alert Instance Controller") @RequestMapping("/api/alertInstance") @RequiredArgsConstructor +@SaCheckLogin public class AlertInstanceController { private final AlertInstanceService alertInstanceService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java b/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java index c4b9cf610b..ade53ee7a1 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertRuleController.java @@ -42,6 +42,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -53,6 +54,7 @@ @RestController @RequestMapping("/api/alertRule") @Api(tags = "Alert Rule Controller") +@SaCheckLogin public class AlertRuleController { private final AlertRuleService alertRuleService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateController.java b/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateController.java index ed8d902a12..3affd81e20 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/AlertTemplateController.java @@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -48,6 +49,7 @@ @RestController @RequestMapping("/api/alertTemplate") @Api(tags = "Alert Template Controller") +@SaCheckLogin public class AlertTemplateController { private final AlertTemplateService alertTemplateService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java b/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java index a32ac1860c..69c4cfe973 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java @@ -41,6 +41,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ZipUtil; import io.swagger.annotations.Api; @@ -60,6 +61,7 @@ @Api(tags = "Catalogue Controller") @RequestMapping("/api/catalogue") @RequiredArgsConstructor +@SaCheckLogin public class CatalogueController { private final CatalogueService catalogueService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/ClusterConfigurationController.java b/dinky-admin/src/main/java/org/dinky/controller/ClusterConfigurationController.java index cc41ff2fcd..fc11825f32 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/ClusterConfigurationController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/ClusterConfigurationController.java @@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -58,6 +59,7 @@ @Api(tags = "Cluster Config Controller") @RequestMapping("/api/clusterConfiguration") @RequiredArgsConstructor +@SaCheckLogin public class ClusterConfigurationController { private final ClusterConfigurationService clusterConfigurationService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/ClusterInstanceController.java b/dinky-admin/src/main/java/org/dinky/controller/ClusterInstanceController.java index fbd2f7922c..b69b3d6006 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/ClusterInstanceController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/ClusterInstanceController.java @@ -42,6 +42,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -56,6 +57,7 @@ @Api(tags = "ClusterInstance Instance Controller") @RequestMapping("/api/cluster") @RequiredArgsConstructor +@SaCheckLogin public class ClusterInstanceController { private final ClusterInstanceService clusterInstanceService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java b/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java index e221437987..0e8563dd7e 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/DataSourceController.java @@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -68,6 +69,7 @@ @Api(tags = "DataSource Controller") @RequestMapping("/api/database") @RequiredArgsConstructor +@SaCheckLogin public class DataSourceController { private final DataBaseService databaseService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/DocumentController.java b/dinky-admin/src/main/java/org/dinky/controller/DocumentController.java index 6044472230..e644566008 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/DocumentController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/DocumentController.java @@ -41,6 +41,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -55,6 +56,7 @@ @Api(tags = "Document Controller") @RequestMapping("/api/document") @RequiredArgsConstructor +@SaCheckLogin public class DocumentController { private final DocumentService documentService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/FlinkController.java b/dinky-admin/src/main/java/org/dinky/controller/FlinkController.java index df2c545bc7..f50e2178f2 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/FlinkController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/FlinkController.java @@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -41,6 +42,7 @@ @Slf4j @Api(tags = "Flink Conf Controller", hidden = true) @RequestMapping("/api/flinkConf") +@SaCheckLogin @RequiredArgsConstructor public class FlinkController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/FlinkProxyController.java b/dinky-admin/src/main/java/org/dinky/controller/FlinkProxyController.java index b6709ea62b..e00b77b255 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/FlinkProxyController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/FlinkProxyController.java @@ -29,6 +29,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; import cn.hutool.http.HttpRequest; @@ -42,6 +43,7 @@ @Controller @Api(tags = "Flink Proxy Controller", hidden = true, description = "Flink Proxy API") @RequestMapping(FlinkProxyController.API) +@SaCheckLogin public class FlinkProxyController { public static final String API = "/api/flink/"; diff --git a/dinky-admin/src/main/java/org/dinky/controller/FragmentController.java b/dinky-admin/src/main/java/org/dinky/controller/FragmentController.java index 201ac2de6c..927c2034f5 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/FragmentController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/FragmentController.java @@ -39,6 +39,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -53,6 +54,7 @@ @Api(tags = "Fragment Controller") @RequestMapping("/api/fragment") @RequiredArgsConstructor +@SaCheckLogin public class FragmentController { private final FragmentVariableService fragmentVariableService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/GitController.java b/dinky-admin/src/main/java/org/dinky/controller/GitController.java index a523b2a5a0..f35799695f 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/GitController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/GitController.java @@ -53,6 +53,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import cn.hutool.core.bean.BeanUtil; @@ -71,6 +72,7 @@ @Api(tags = "Git Project Controller") @RequestMapping("/api/git") @AllArgsConstructor +@SaCheckLogin public class GitController { final GitProjectService gitProjectService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/HistoryController.java b/dinky-admin/src/main/java/org/dinky/controller/HistoryController.java index 3871670415..4a7bcc7573 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/HistoryController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/HistoryController.java @@ -33,6 +33,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -49,6 +50,7 @@ @RestController @RequestMapping("/api/history") @RequiredArgsConstructor +@SaCheckLogin public class HistoryController { private final HistoryService historyService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/HomeController.java b/dinky-admin/src/main/java/org/dinky/controller/HomeController.java index 3e5fef9898..b243154da5 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/HomeController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/HomeController.java @@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -43,6 +44,7 @@ @Api(tags = "Home Controller") @RequestMapping("/api/home") @RequiredArgsConstructor +@SaCheckLogin public class HomeController { private final HomeService homeService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/JarController.java b/dinky-admin/src/main/java/org/dinky/controller/JarController.java index bad026c07a..eee5788962 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/JarController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/JarController.java @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.hutool.core.util.StrUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -52,6 +53,7 @@ @Api(tags = "Jar Controller") @RequestMapping("/api/jar") @RequiredArgsConstructor +@SaCheckLogin public class JarController { private final TaskService taskService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/JobInstanceController.java b/dinky-admin/src/main/java/org/dinky/controller/JobInstanceController.java index c7eee0a44e..134e87b3d3 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/JobInstanceController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/JobInstanceController.java @@ -49,6 +49,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.lang.Dict; import io.swagger.annotations.Api; @@ -68,6 +69,7 @@ @Api(tags = "Job Instance Controller") @RequestMapping("/api/jobInstance") @RequiredArgsConstructor +@SaCheckLogin public class JobInstanceController { private final JobInstanceService jobInstanceService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/LdapController.java b/dinky-admin/src/main/java/org/dinky/controller/LdapController.java index 54e8c1d62a..3c7b830114 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/LdapController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/LdapController.java @@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaIgnore; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -71,6 +72,7 @@ public Result ldapStatus() { @GetMapping("/testConnection") @ApiOperation("Test connection to LDAP server") + @SaCheckLogin @Log(title = "Test connection to LDAP server", businessType = BusinessType.TEST) public Result testConnection() { List users = ldapService.listUsers(); @@ -83,6 +85,7 @@ public Result testConnection() { @GetMapping("/listUser") @ApiOperation("List user from LDAP server") + @SaCheckLogin public Result> listUser() { List users = ldapService.listUsers(); List localUsers = userService.list(); @@ -98,6 +101,7 @@ public Result> listUser() { @PostMapping("/importUsers") @ApiOperation("Import users from LDAP server") + @SaCheckLogin @Log(title = "Import users from LDAP server", businessType = BusinessType.IMPORT) @ApiImplicitParam(name = "users", value = "User list", required = true, dataType = "List") public Result importUsers(@RequestBody List users) { @@ -115,6 +119,7 @@ public Result importUsers(@RequestBody List users) { * @return {@link Result}{@link UserDTO} obtain the user's UserDTO */ @PostMapping("/testLogin") + @SaCheckLogin @ApiOperation("Test login to LDAP server") @Log(title = "Test login to LDAP server", businessType = BusinessType.TEST) @ApiImplicitParam(name = "loginDTO", value = "Login information", required = true, dataType = "LoginDTO") diff --git a/dinky-admin/src/main/java/org/dinky/controller/LogController.java b/dinky-admin/src/main/java/org/dinky/controller/LogController.java index 344aade11d..a8fb041bdf 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/LogController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/LogController.java @@ -37,6 +37,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -48,6 +49,7 @@ @RestController @Api(tags = "Log Controller") @RequestMapping("/api/log") +@SaCheckLogin @RequiredArgsConstructor public class LogController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/MenuController.java b/dinky-admin/src/main/java/org/dinky/controller/MenuController.java index 48c5dc0b20..5b056d1406 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/MenuController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/MenuController.java @@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -53,6 +54,7 @@ @Api(tags = "Menu Controller") @RequestMapping("/api/menu") @RequiredArgsConstructor +@SaCheckLogin public class MenuController { private final MenuService menuService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/MonitorController.java b/dinky-admin/src/main/java/org/dinky/controller/MonitorController.java index 49c597012c..fc1c38453a 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/MonitorController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/MonitorController.java @@ -44,6 +44,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Opt; @@ -59,6 +60,7 @@ @Api(tags = "Monitor Controller") @RequestMapping("/api/monitor") @RequiredArgsConstructor +@SaCheckLogin public class MonitorController { private final MonitorService monitorService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/PrintTableController.java b/dinky-admin/src/main/java/org/dinky/controller/PrintTableController.java index d0dccec254..43b1a9f034 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/PrintTableController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/PrintTableController.java @@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -41,6 +42,7 @@ @Api(tags = "Print Table Controller") @AllArgsConstructor @RequestMapping("/api/printTable") +@SaCheckLogin public class PrintTableController { private final PrintTableService printTableService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/ProcessController.java b/dinky-admin/src/main/java/org/dinky/controller/ProcessController.java index 455db993d7..1be637c74d 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/ProcessController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/ProcessController.java @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -44,6 +45,7 @@ @RestController @Api(tags = "Process Controller") @RequestMapping("/api/process") +@SaCheckLogin @RequiredArgsConstructor public class ProcessController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/ResourceController.java b/dinky-admin/src/main/java/org/dinky/controller/ResourceController.java index 7a666a3fb3..c66276c6ac 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/ResourceController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/ResourceController.java @@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -53,6 +54,7 @@ @Api(tags = "Resource Controller") @RequestMapping("/api/resource") @RequiredArgsConstructor +@SaCheckLogin public class ResourceController { private final ResourcesService resourcesService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/RoleController.java b/dinky-admin/src/main/java/org/dinky/controller/RoleController.java index fb1be3b59d..5d7614e632 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/RoleController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/RoleController.java @@ -45,6 +45,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import cn.hutool.core.lang.Dict; @@ -58,6 +59,7 @@ @RestController @Api(tags = "Role Controller") @RequestMapping("/api/role") +@SaCheckLogin @RequiredArgsConstructor public class RoleController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/RoleMenuController.java b/dinky-admin/src/main/java/org/dinky/controller/RoleMenuController.java index 8fd172de6a..f9d2f4ded4 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/RoleMenuController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/RoleMenuController.java @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -42,6 +43,7 @@ @RestController @Api(tags = "Role Menu Controller") @RequestMapping("/api/roleMenu") +@SaCheckLogin @RequiredArgsConstructor public class RoleMenuController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/RowPermissionsController.java b/dinky-admin/src/main/java/org/dinky/controller/RowPermissionsController.java index 90d63ffcd9..fd2fa5e315 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/RowPermissionsController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/RowPermissionsController.java @@ -39,6 +39,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import io.swagger.annotations.Api; @@ -50,6 +51,7 @@ @Api(tags = "RowPermissions Controller") @RestController @RequestMapping("/api/rowPermissions") +@SaCheckLogin public class RowPermissionsController { @Autowired diff --git a/dinky-admin/src/main/java/org/dinky/controller/SavePointsController.java b/dinky-admin/src/main/java/org/dinky/controller/SavePointsController.java index 00823638c4..fa30f351c0 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SavePointsController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SavePointsController.java @@ -35,6 +35,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -50,6 +51,7 @@ @RestController @Api(tags = "SavePoints Controller") @RequestMapping("/api/savepoints") +@SaCheckLogin @RequiredArgsConstructor public class SavePointsController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/SchedulerController.java b/dinky-admin/src/main/java/org/dinky/controller/SchedulerController.java index 85eeff6748..d60c549da9 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SchedulerController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SchedulerController.java @@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -44,6 +45,7 @@ @RestController @RequestMapping("/api/scheduler") @Api(tags = "DolphinScheduler Controller") +@SaCheckLogin @RequiredArgsConstructor public class SchedulerController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/StudioController.java b/dinky-admin/src/main/java/org/dinky/controller/StudioController.java index b5052e1108..fe5a2bbe5a 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/StudioController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/StudioController.java @@ -46,6 +46,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -62,6 +63,7 @@ @RestController @Api(tags = "Data Studio Controller") @RequestMapping("/api/studio") +@SaCheckLogin @RequiredArgsConstructor public class StudioController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java b/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java index cf136814cc..6357cfc60d 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SuggestionController.java @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -41,6 +42,7 @@ @RestController @Api(tags = "Suggestion Controller") @RequestMapping("/api/suggestion") +@SaCheckLogin @RequiredArgsConstructor public class SuggestionController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/SysConfigController.java b/dinky-admin/src/main/java/org/dinky/controller/SysConfigController.java index 6daaa0368e..f3c9e8dfe9 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SysConfigController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SysConfigController.java @@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.lang.Dict; import cn.hutool.core.map.MapUtil; @@ -54,6 +55,7 @@ @Slf4j @RestController @Api(tags = "System Config Controller") +@SaCheckLogin @RequestMapping("/api/sysConfig") @RequiredArgsConstructor public class SysConfigController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/SystemController.java b/dinky-admin/src/main/java/org/dinky/controller/SystemController.java index df42d87c87..47e5dcb559 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SystemController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SystemController.java @@ -44,6 +44,7 @@ @RestController @Api(tags = "System Controller") @RequestMapping("/api/system") +@SaCheckLogin @RequiredArgsConstructor public class SystemController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/TaskController.java b/dinky-admin/src/main/java/org/dinky/controller/TaskController.java index 2b009910f6..75f0966e43 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/TaskController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/TaskController.java @@ -55,6 +55,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.hutool.core.lang.tree.Tree; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -66,6 +67,7 @@ @RestController @Api(tags = "Task Controller") @RequestMapping("/api/task") +@SaCheckLogin @RequiredArgsConstructor public class TaskController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/TaskVersionController.java b/dinky-admin/src/main/java/org/dinky/controller/TaskVersionController.java index 952fea1617..2a6d2ccef1 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/TaskVersionController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/TaskVersionController.java @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.hutool.core.bean.BeanUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -52,6 +53,7 @@ @RestController @Api(tags = "Task Version Controller") @RequestMapping("/api/task/version") +@SaCheckLogin @RequiredArgsConstructor public class TaskVersionController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/TenantController.java b/dinky-admin/src/main/java/org/dinky/controller/TenantController.java index 7137e64279..2e785a0e93 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/TenantController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/TenantController.java @@ -43,6 +43,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import cn.hutool.core.lang.Dict; @@ -57,6 +58,7 @@ @RestController @Api(tags = "Tenant Controller") @RequestMapping("/api/tenant") +@SaCheckLogin @RequiredArgsConstructor public class TenantController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/TokenController.java b/dinky-admin/src/main/java/org/dinky/controller/TokenController.java index ddf312cf34..d8b5fc9614 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/TokenController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/TokenController.java @@ -40,6 +40,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import cn.dev33.satoken.stp.StpLogic; @@ -56,6 +57,7 @@ @Api(tags = "Token Controller") @RestController @RequestMapping("/api/token") +@SaCheckLogin @RequiredArgsConstructor public class TokenController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/ToolsController.java b/dinky-admin/src/main/java/org/dinky/controller/ToolsController.java index b2b24011eb..8e44f4dafa 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/ToolsController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/ToolsController.java @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -37,6 +38,7 @@ @RestController @Api(tags = "Tools Controller") @RequestMapping("/api/tools") +@SaCheckLogin @RequiredArgsConstructor public class ToolsController { @PostMapping("/jsonToFlinkSql") diff --git a/dinky-admin/src/main/java/org/dinky/controller/UDFController.java b/dinky-admin/src/main/java/org/dinky/controller/UDFController.java index 9bbe5970ea..6925a897a4 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/UDFController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/UDFController.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import cn.dev33.satoken.annotation.SaCheckLogin; import io.swagger.annotations.Api; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -45,6 +46,7 @@ @Api(tags = "UDF Controller") @RestController @RequestMapping("/api/udf") +@SaCheckLogin @RequiredArgsConstructor public class UDFController { private final UDFService udfService; diff --git a/dinky-admin/src/main/java/org/dinky/controller/UDFTemplateController.java b/dinky-admin/src/main/java/org/dinky/controller/UDFTemplateController.java index 8dabfb67e2..d876379cfe 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/UDFTemplateController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/UDFTemplateController.java @@ -46,6 +46,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import cn.hutool.core.collection.CollUtil; @@ -62,6 +63,7 @@ @Api(tags = "UDF Controller") @RestController @RequestMapping("/api/udf/template") +@SaCheckLogin @RequiredArgsConstructor public class UDFTemplateController { diff --git a/dinky-admin/src/main/java/org/dinky/controller/UserController.java b/dinky-admin/src/main/java/org/dinky/controller/UserController.java index a521409353..d39819854a 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/UserController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/UserController.java @@ -45,6 +45,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import cn.dev33.satoken.annotation.SaCheckLogin; import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaMode; import cn.hutool.core.lang.Dict; @@ -64,6 +65,7 @@ @RestController @Api(tags = "User Controller") @RequestMapping("/api/user") +@SaCheckLogin @RequiredArgsConstructor public class UserController { diff --git a/dinky-admin/src/main/java/org/dinky/service/UserService.java b/dinky-admin/src/main/java/org/dinky/service/UserService.java index 7d5c6749b9..b428dc5246 100644 --- a/dinky-admin/src/main/java/org/dinky/service/UserService.java +++ b/dinky-admin/src/main/java/org/dinky/service/UserService.java @@ -109,7 +109,7 @@ public interface UserService extends ISuperService { * * @return {@link Result}{@link UserDTO} obtain the current user's UserDTO */ - Result queryCurrentUserInfo(); + Result queryCurrentUserInfo(Integer tenantId); /** * user enable or disable diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index 11b867efad..e280b9f510 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -363,13 +363,18 @@ public Result chooseTenant(Integer tenantId) { } @Override - public Result queryCurrentUserInfo() { + public Result queryCurrentUserInfo(Integer tenantId) { UserDTO userInfo = UserInfoContextHolder.get(StpUtil.getLoginIdAsInt()); + chooseTenant(tenantId); if (Asserts.isNotNull(userInfo)) { UserDTO userInfoDto = buildUserInfo(userInfo.getUser().getId()); if (userInfoDto != null) { - userInfoDto.setCurrentTenant(userInfo.getCurrentTenant()); + Tenant currentTenant = userInfo.getCurrentTenant(); + if (Asserts.isNull(currentTenant)) { + currentTenant = tenantService.getById(tenantId); + } + userInfoDto.setCurrentTenant(currentTenant); } UserInfoContextHolder.refresh(StpUtil.getLoginIdAsInt(), userInfoDto); return Result.succeed(userInfoDto); diff --git a/dinky-web/src/locales/en-US/pages.ts b/dinky-web/src/locales/en-US/pages.ts index 0971de6e77..fd473dcd6c 100644 --- a/dinky-web/src/locales/en-US/pages.ts +++ b/dinky-web/src/locales/en-US/pages.ts @@ -299,6 +299,7 @@ export default { 'login.result': '{msg}\t\t{time}', 'login.username.placeholder': 'Username', 'login.username.required': 'Please input your username!', + 'login.token.error': 'Unable to get token information/session has expired, will jump to the login page, please re-login...', /** * * menu diff --git a/dinky-web/src/locales/zh-CN/pages.ts b/dinky-web/src/locales/zh-CN/pages.ts index 52f1c2d712..e73a5f7656 100644 --- a/dinky-web/src/locales/zh-CN/pages.ts +++ b/dinky-web/src/locales/zh-CN/pages.ts @@ -287,6 +287,7 @@ export default { 'login.result': '{msg}\t\t{time}', 'login.username.placeholder': '用户名', 'login.username.required': '用户名是必填项!', + 'login.token.error': '无法获取token信息/会话已过期,即将跳转到登录页,请重新登录...', /** * * menu diff --git a/dinky-web/src/pages/Other/Login/function.tsx b/dinky-web/src/pages/Other/Login/function.tsx index a3082f3b32..6aef9f1195 100644 --- a/dinky-web/src/pages/Other/Login/function.tsx +++ b/dinky-web/src/pages/Other/Login/function.tsx @@ -24,8 +24,11 @@ import { setLocalThemeToStorage } from '@/utils/function'; import { history } from '@@/core/history'; +import {WarningMessage, WarningMessageAsync} from "@/utils/messages"; +import {Modal} from "antd"; +import {l} from "@/utils/intl"; -/** 此方法会跳转到 redirect 参数所在的位置 */ +/** This method will redirect to the location of the redirect parameter */ export const gotoRedirectUrl = () => { if (!history) return; setTimeout(() => { @@ -34,15 +37,16 @@ export const gotoRedirectUrl = () => { }, 10); }; -export const redirectToLogin = () => { - //TODO: 弹出确认框 +export const redirectToLogin = async () => { + //todo: 使用模态框提示, 但是目前会重复弹出,原因是接口每次都会调用,所以会出现重复弹出 + await WarningMessageAsync(l('login.token.error')); window.location.href = '/#/user/login'; }; export const initSomeThing = () => { - // 初始化设置主题 + // initialize setting theme setLocalThemeToStorage(); - // 取出本地存储是否有启用消息提示的 key , 没有的话设置一下 + // Retrieve the key for enabling message prompts from the local storage, and if not, set it accordingly if (hasKeyofLocalStorage(ENABLE_MODEL_TIP)) { setKeyToLocalStorage(ENABLE_MODEL_TIP, 'false'); } diff --git a/dinky-web/src/pages/Other/Login/index.tsx b/dinky-web/src/pages/Other/Login/index.tsx index 32c3cf0b98..71f43ac6b5 100644 --- a/dinky-web/src/pages/Other/Login/index.tsx +++ b/dinky-web/src/pages/Other/Login/index.tsx @@ -137,7 +137,6 @@ const Login: React.FC = () => { if (result.code === 0) { // if login success then get token info and set it to local storage await queryDataByParams(API_CONSTANTS.TOKEN_INFO).then((res) => { - console.log(res); if (res) { setLocalStorageOfToken(JSON.stringify(res)); } else { diff --git a/dinky-web/src/pages/Other/PersonCenter/index.tsx b/dinky-web/src/pages/Other/PersonCenter/index.tsx index d4d0de9657..959f5b15c4 100644 --- a/dinky-web/src/pages/Other/PersonCenter/index.tsx +++ b/dinky-web/src/pages/Other/PersonCenter/index.tsx @@ -35,6 +35,7 @@ import { SecurityScanTwoTone } from '@ant-design/icons'; import { PageContainer, PageLoading, ProCard } from '@ant-design/pro-components'; import { Descriptions, Divider, Form, Tag } from 'antd'; import { useEffect, useState } from 'react'; +import FadeIn from "@/components/Animation/FadeIn"; const PersonCenter = () => { const [form] = Form.useForm(); @@ -169,7 +170,7 @@ const PersonCenter = () => { * render */ return ( - + { /> - + ); }; diff --git a/dinky-web/src/requestErrorConfig.ts b/dinky-web/src/requestErrorConfig.ts index ee3ee7004f..64c4d8c5d4 100644 --- a/dinky-web/src/requestErrorConfig.ts +++ b/dinky-web/src/requestErrorConfig.ts @@ -18,15 +18,14 @@ */ import { ENABLE_MODEL_TIP } from '@/services/constants'; -import { API_CONSTANTS } from '@/services/endpoints'; import { getValueFromLocalStorage } from '@/utils/function'; import { l } from '@/utils/intl'; import { ErrorNotification, WarningNotification } from '@/utils/messages'; -import { history } from '@@/core/history'; import type { RequestOptions } from '@@/plugin-request/request'; import type { RequestConfig } from '@umijs/max'; +import {redirectToLogin} from "@/pages/Other/Login/function"; -// 错误处理方案: 错误类型 +// Error handling scheme: Error type enum ErrorCode { SUCCESS = 0, ERROR = 1, @@ -35,7 +34,7 @@ enum ErrorCode { AUTHORIZE_ERROR = 7 } -// 与后端约定的响应数据格式 +// Response data format agreed upon with the backend interface ResponseStructure { success: boolean; data?: any; @@ -74,61 +73,61 @@ const handleBizError = (result: ResponseStructure) => { * @doc https://umijs.org/docs/max/request#配置 */ export const errorConfig: RequestConfig = { - // 错误处理: umi@3 的错误处理方案。 + // Error handling: umi@3 Error handling plan for. errorConfig: { - // 错误抛出 + // Error thrown errorThrower: (res: ResponseStructure) => { const { success, data, msg, code } = res as ResponseStructure; if (!success) { const error: any = new Error(msg); error.name = 'BizError'; error.info = { msg, code, data }; - throw error; // 抛出自制的错误 + throw error; // Throwing self-made errors } }, - // 错误接收及处理 + // Error reception and handling errorHandler: (error: any, opts: any) => { if (opts?.skipErrorHandler) throw error; - // 我们的 errorThrower 抛出的错误。 + //The error thrown by our errorThrower. if (error.name === 'BizError') { const errorInfo: ResponseStructure = error.info; if (errorInfo) { handleBizError(errorInfo); } } else if (error.response) { - // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 - //认证错误,跳转登录页面 + //The request was successfully sent and the server also responded with a status code, but the status code exceeded the range of 2xx + //Authentication error, redirect to login page if (error.response.status === 401) { - history.push(API_CONSTANTS.LOGIN_PATH); + redirectToLogin() } else { if (getValueFromLocalStorage(ENABLE_MODEL_TIP) == 'true') { ErrorNotification(error.message, error.code); } } } else if (error.request) { - // 请求已经成功发起,但没有收到响应 + //The request has been successfully initiated, but no response has been received ErrorNotification(error.toString(), l('app.response.noresponse')); } else { - // 发送请求时出了点问题 + // There was a problem sending the request ErrorNotification(error.toString(), l('app.request.failed')); } } }, - // 请求拦截器 + // request interceptor requestInterceptors: [ (config: RequestOptions) => { - // 拦截请求配置,进行个性化处理。 + // Intercept request configuration for personalized processing. const url = config?.url; return { ...config, url }; } ], - // 响应拦截器 + // Response interceptor responseInterceptors: [ (response) => { - // 拦截响应数据,进行个性化处理 - // 不再需要异步处理读取返回体内容,可直接在data中读出,部分字段可在 config 中找到 + //Intercept response data for personalized processing + //No longer requires asynchronous processing to read the content of the return body, it can be directly read from data, and some fields can be found in config const { data = {} as any, config } = response; return response; }