Ver código fonte

AccountCodeController.java 合并到 HomeController.java

reghao 6 meses atrás
pai
commit
c23e9c2876

+ 0 - 52
mgr/src/main/java/cn/reghao/devops/mgr/admin/controller/AccountCodeController.java

@@ -1,52 +0,0 @@
-package cn.reghao.devops.mgr.admin.controller;
-
-import cn.reghao.devops.mgr.admin.model.dto.RsaPubkey;
-import cn.reghao.devops.mgr.admin.service.CodeService;
-import cn.reghao.devops.mgr.admin.service.PubkeyService;
-import cn.reghao.jutil.jdk.result.WebResult;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.security.NoSuchAlgorithmException;
-import java.util.Base64;
-
-/**
- * @author reghao
- * @date 2022-02-18 16:05:30
- */
-@Api(tags = "验证码接口")
-@RestController
-@RequestMapping("/api/account/code")
-public class AccountCodeController {
-    private final CodeService codeService;
-    private final PubkeyService pubkeyService;
-
-    public AccountCodeController(CodeService codeService, PubkeyService pubkeyService) {
-        this.codeService = codeService;
-        this.pubkeyService = pubkeyService;
-    }
-
-    @ApiOperation(value = "获取公钥", notes = "N")
-    @GetMapping(value = "/pubkey", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getPubkey() throws NoSuchAlgorithmException {
-        RsaPubkey rsaPubkey = pubkeyService.getPubkey();
-        return WebResult.success(rsaPubkey);
-    }
-
-    @ApiOperation(value = "获取图形验证码", notes = "N")
-    @GetMapping(value = "/captcha", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getCaptcha() throws IOException {
-        InputStream in = codeService.generateCaptcha();
-        byte[] base64Bytes = Base64.getEncoder().encode(in.readAllBytes());
-        String base64Str = new String(base64Bytes, StandardCharsets.UTF_8);
-        String imageStr = String.format("data:image/jpeg;base64,%s", base64Str);
-        return WebResult.success(imageStr);
-    }
-}

+ 34 - 5
mgr/src/main/java/cn/reghao/devops/mgr/admin/controller/HomeController.java

@@ -3,23 +3,29 @@ package cn.reghao.devops.mgr.admin.controller;
 import cn.reghao.devops.common.util.NotAvailable;
 import cn.reghao.devops.common.version.AppVersion;
 import cn.reghao.devops.mgr.admin.model.constant.RoleType;
+import cn.reghao.devops.mgr.admin.model.dto.RsaPubkey;
 import cn.reghao.devops.mgr.admin.model.po.Menu;
 import cn.reghao.devops.mgr.admin.model.po.User;
-import cn.reghao.devops.mgr.admin.service.HomeService;
-import cn.reghao.devops.mgr.admin.service.UserContext;
-import cn.reghao.devops.mgr.admin.service.SysMessageService;
+import cn.reghao.devops.mgr.admin.service.*;
 import cn.reghao.devops.mgr.machine.service.MachineQuery;
 import cn.reghao.devops.mgr.machine.model.vo.MachineStat;
 import cn.reghao.jutil.jdk.jvm.JVM;
 import cn.reghao.jutil.jdk.jvm.model.JvmInfo;
 import cn.reghao.jutil.jdk.machine.id.MachineIdLinux;
+import cn.reghao.jutil.web.WebResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -38,15 +44,19 @@ public class HomeController {
     private final HomeService homeService;
     private final SysMessageService sysMessageService;
     private final MachineQuery machineQuery;
+    private final CodeService codeService;
+    private final PubkeyService pubkeyService;
 
-    public HomeController(HomeService homeService, SysMessageService sysMessageService,
-                          MachineQuery machineQuery) {
+    public HomeController(HomeService homeService, SysMessageService sysMessageService, MachineQuery machineQuery,
+                          CodeService codeService, PubkeyService pubkeyService) {
         this.jvm = new JVM();
         this.machineId = new MachineIdLinux();
         this.appVersion = AppVersion.getVersion();
         this.homeService = homeService;
         this.sysMessageService = sysMessageService;
         this.machineQuery = machineQuery;
+        this.codeService = codeService;
+        this.pubkeyService = pubkeyService;
     }
 
     @ApiOperation(value = "帐号登入页面", notes = "N")
@@ -106,4 +116,23 @@ public class HomeController {
 
         return "/home/index";
     }
+
+    @ApiOperation(value = "获取公钥", notes = "N")
+    @GetMapping(value = "/api/account/code/pubkey", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ResponseBody
+    public String getPubkey() throws NoSuchAlgorithmException {
+        RsaPubkey rsaPubkey = pubkeyService.getPubkey();
+        return WebResult.success(rsaPubkey);
+    }
+
+    @ApiOperation(value = "获取图形验证码", notes = "N")
+    @GetMapping(value = "/api/account/code/captcha", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ResponseBody
+    public String getCaptcha() throws IOException {
+        InputStream in = codeService.generateCaptcha();
+        byte[] base64Bytes = Base64.getEncoder().encode(in.readAllBytes());
+        String base64Str = new String(base64Bytes, StandardCharsets.UTF_8);
+        String imageStr = String.format("data:image/jpeg;base64,%s", base64Str);
+        return WebResult.success(imageStr);
+    }
 }