重写复现方法
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.mini.capi.biz.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/biz/apiUser")
|
||||
public class ApiUserController {
|
||||
|
||||
}
|
||||
86
src/main/java/com/mini/capi/biz/domain/ApiUser.java
Normal file
86
src/main/java/com/mini/capi/biz/domain/ApiUser.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.mini.capi.biz.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("biz_api_user")
|
||||
public class ApiUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
@TableId(value = "user_id", type = IdType.AUTO)
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 登录名称
|
||||
*/
|
||||
@TableField("api_user")
|
||||
private String apiUser;
|
||||
|
||||
/**
|
||||
* 登录密码
|
||||
*/
|
||||
@TableField("api_pswd")
|
||||
private String apiPswd;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
@TableField("uname")
|
||||
private String uname;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@TableField("ustatus")
|
||||
private String ustatus;
|
||||
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@TableField("f_tenant_id")
|
||||
private String fTenantId;
|
||||
|
||||
/**
|
||||
* 流程id
|
||||
*/
|
||||
@TableField("f_flow_id")
|
||||
private String fFlowId;
|
||||
|
||||
/**
|
||||
* 流程任务主键
|
||||
*/
|
||||
@TableField("f_flow_task_id")
|
||||
private String fFlowTaskId;
|
||||
|
||||
/**
|
||||
* 流程任务状态
|
||||
*/
|
||||
@TableField("f_flow_state")
|
||||
private Integer fFlowState;
|
||||
}
|
||||
16
src/main/java/com/mini/capi/biz/mapper/ApiUserMapper.java
Normal file
16
src/main/java/com/mini/capi/biz/mapper/ApiUserMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.mini.capi.biz.mapper;
|
||||
|
||||
import com.mini.capi.biz.domain.ApiUser;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
public interface ApiUserMapper extends BaseMapper<ApiUser> {
|
||||
|
||||
}
|
||||
16
src/main/java/com/mini/capi/biz/service/ApiUserService.java
Normal file
16
src/main/java/com/mini/capi/biz/service/ApiUserService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.mini.capi.biz.service;
|
||||
|
||||
import com.mini.capi.biz.domain.ApiUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
public interface ApiUserService extends IService<ApiUser> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mini.capi.biz.service.impl;
|
||||
|
||||
import com.mini.capi.biz.domain.ApiUser;
|
||||
import com.mini.capi.biz.mapper.ApiUserMapper;
|
||||
import com.mini.capi.biz.service.ApiUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-08-28
|
||||
*/
|
||||
@Service
|
||||
public class ApiUserServiceImpl extends ServiceImpl<ApiUserMapper, ApiUser> implements ApiUserService {
|
||||
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.mini.capi.config;
|
||||
|
||||
import com.mini.capi.utils.vToken;
|
||||
import com.mini.capi.biz.domain.ApiUser;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
@Component
|
||||
public class AuthInterceptor implements HandlerInterceptor {
|
||||
@@ -13,9 +14,9 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
public boolean preHandle(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
Object handler) throws Exception {
|
||||
|
||||
String token = request.getHeader("Authorization");
|
||||
if (token == null || !vToken.isValidToken(token)) {
|
||||
HttpSession session = request.getSession();
|
||||
ApiUser apiUser = (ApiUser) session.getAttribute("Authorization");
|
||||
if (apiUser == null) {
|
||||
response.sendRedirect(request.getContextPath() + "/login");
|
||||
return false;
|
||||
}
|
||||
|
||||
52
src/main/java/com/mini/capi/model/auth/Result.java
Normal file
52
src/main/java/com/mini/capi/model/auth/Result.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.mini.capi.model.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class Result implements Serializable {
|
||||
|
||||
// 状态码:200表示成功,其他表示错误
|
||||
private int code;
|
||||
// 响应信息
|
||||
private String msg;
|
||||
// 响应数据(可选)
|
||||
private Object data;
|
||||
|
||||
// 私有构造方法,防止直接创建实例
|
||||
private Result() {}
|
||||
|
||||
// 成功响应
|
||||
public static Result success(String msg) {
|
||||
Result result = new Result();
|
||||
result.code = 200;
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 带数据的成功响应
|
||||
public static Result success(String msg, Object data) {
|
||||
Result result = new Result();
|
||||
result.code = 200;
|
||||
result.msg = msg;
|
||||
result.data = data;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 错误响应
|
||||
public static Result error(String msg) {
|
||||
Result result = new Result();
|
||||
result.code = 500; // 500表示服务器错误,也可以根据实际情况使用其他错误码
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 带自定义错误码的错误响应
|
||||
public static Result error(int code, String msg) {
|
||||
Result result = new Result();
|
||||
result.code = code;
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class demo {
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper"));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude("biz_sync_task_log")
|
||||
builder.addInclude("biz_api_user")
|
||||
.addTablePrefix("biz_")
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mini.capi.sys.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mini.capi.biz.domain.ApiUser;
|
||||
import com.mini.capi.biz.service.ApiUserService;
|
||||
import com.mini.capi.model.auth.Result;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import lombok.Data;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/Sys/login")
|
||||
public class LoginController {
|
||||
|
||||
|
||||
@Resource
|
||||
private ApiUserService userService;
|
||||
|
||||
|
||||
@Data
|
||||
public static class LoginRequest implements Serializable {
|
||||
private String username;
|
||||
private String password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 密码校验(生产环境需替换为加密比对)
|
||||
*/
|
||||
private boolean verifyPassword(String rawPassword, String encodedPassword) {
|
||||
return Objects.equals(rawPassword, encodedPassword);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
@PostMapping("/userLogin")
|
||||
public Result login(@RequestBody LoginRequest user, HttpSession session) {
|
||||
try {
|
||||
QueryWrapper<ApiUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("api_user", user.getUsername())
|
||||
.eq("ustatus", 1);
|
||||
ApiUser apiUser = userService.getOne(queryWrapper);
|
||||
if (apiUser == null) {
|
||||
return Result.error("账户不存在");
|
||||
}
|
||||
if (!verifyPassword(user.getPassword(), apiUser.getApiPswd())) {
|
||||
// 可记录登录失败日志,用于后续风控
|
||||
return Result.error("账户或密码错误");
|
||||
}
|
||||
session.setAttribute("Authorization", apiUser);
|
||||
return Result.success("登录成功");
|
||||
} catch (Exception e) {
|
||||
return Result.error("登录失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,13 @@ public class LoginPageController {
|
||||
public String loginPage() {
|
||||
return "forward:/index.html";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 首页
|
||||
*/
|
||||
@GetMapping("/welcome")
|
||||
public String welcomePage() {
|
||||
return "forward:/views/demo.html";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user