diff --git a/src/main/java/im/zhaojun/zfile/controller/admin/LoginController.java b/src/main/java/im/zhaojun/zfile/controller/admin/LoginController.java index c864c91..9a61a78 100644 --- a/src/main/java/im/zhaojun/zfile/controller/admin/LoginController.java +++ b/src/main/java/im/zhaojun/zfile/controller/admin/LoginController.java @@ -1 +1 @@ -package im.zhaojun.zfile.controller.admin; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.crypto.SecureUtil; import im.zhaojun.zfile.model.dto.SystemConfigDTO; import im.zhaojun.zfile.model.support.ResultBean; import im.zhaojun.zfile.service.SystemConfigService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.Objects; @RestController public class LoginController { @Resource private SystemConfigService systemConfigService; @PostMapping("/login") public ResultBean doLogin(String username, String password) { SystemConfigDTO systemConfig = systemConfigService.getSystemConfig(); if (Objects.equals(username, systemConfig.getUsername()) && Objects.equals(SecureUtil.md5(password), systemConfig.getPassword())) { StpUtil.login("admin"); return ResultBean.success("登录成功"); } return ResultBean.error("登录失败"); } @GetMapping("/logout") public ResultBean logout() { StpUtil.logout(); return ResultBean.success("注销成功"); } } \ No newline at end of file +package im.zhaojun.zfile.controller.admin; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.crypto.SecureUtil; import im.zhaojun.zfile.model.dto.SystemConfigDTO; import im.zhaojun.zfile.model.support.ResultBean; import im.zhaojun.zfile.service.SystemConfigService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.Objects; @RestController public class LoginController { @Resource private SystemConfigService systemConfigService; @PostMapping("/doLogin") public ResultBean doLogin(String username, String password) { SystemConfigDTO systemConfig = systemConfigService.getSystemConfig(); if (Objects.equals(username, systemConfig.getUsername()) && Objects.equals(SecureUtil.md5(password), systemConfig.getPassword())) { StpUtil.login("admin"); return ResultBean.success("登录成功"); } return ResultBean.error("登录失败"); } @GetMapping("/logout") public ResultBean logout() { StpUtil.logout(); return ResultBean.success("注销成功"); } } \ No newline at end of file