xyc
4 天以前 e4a55083ff3a59a6393e95abafd3cdca86ac2cda
traffic-audit-server/src/main/java/com/trafficaudit/security/controller/LoginController.java
@@ -9,6 +9,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
@@ -31,6 +32,9 @@
    @Resource
    private PasswordEncoder passwordEncoder;
    @Value("${app.captcha.required:true}")
    private boolean captchaRequired;
    @PostMapping("/login")
    public Result<Map<String, Object>> login(@RequestBody Map<String, Object> params) {
        String username = (String) params.get("username");
@@ -38,15 +42,17 @@
        String captchaId = (String) params.get("captchaId");
        List<String> clickIds = strList(params.get("captchaClickIds"));
        CaptchaService.ConsumeResult cr = captchaService.consume(captchaId, clickIds);
        if (cr == CaptchaService.ConsumeResult.NOT_FOUND) {
            return Result.error(4002, "验证码不存在或已过期,请刷新重试");
        }
        if (cr == CaptchaService.ConsumeResult.NOT_VERIFIED) {
            return Result.error(4003, "请先完成行为验证");
        }
        if (cr == CaptchaService.ConsumeResult.WRONG) {
            return Result.error(4001, "行为验证未通过,请重新验证");
        if (captchaRequired) {
            CaptchaService.ConsumeResult cr = captchaService.consume(captchaId, clickIds);
            if (cr == CaptchaService.ConsumeResult.NOT_FOUND) {
                return Result.error(4002, "验证码不存在或已过期,请刷新重试");
            }
            if (cr == CaptchaService.ConsumeResult.NOT_VERIFIED) {
                return Result.error(4003, "请先完成行为验证");
            }
            if (cr == CaptchaService.ConsumeResult.WRONG) {
                return Result.error(4001, "行为验证未通过,请重新验证");
            }
        }
        if (username == null || username.trim().isEmpty() || password == null || password.isEmpty()) {
@@ -77,6 +83,13 @@
        return Result.ok(data);
    }
    @GetMapping("/captcha-config")
    public Result<Map<String, Object>> captchaConfig() {
        Map<String, Object> data = new HashMap<>();
        data.put("required", captchaRequired);
        return Result.ok(data);
    }
    @SuppressWarnings("unchecked")
    private List<String> strList(Object o) {
        if (o instanceof List) {