fix: 修复钉钉免登时的参数验证问题

This commit is contained in:
Your Name 2026-01-07 10:18:37 +08:00
parent 5526c7ad4e
commit 0afd1b7d17
4 changed files with 19 additions and 11 deletions

View File

@ -42,8 +42,8 @@ public class AuthController {
@Operation(summary = "用户登录", description = "支持密码登录、钉钉登录、Casdoor登录")
@PostMapping("/login")
public Result<LoginVO> login(@Valid @RequestBody LoginDTO loginDTO) {
log.info("用户登录请求: {}", loginDTO.getUsername());
public Result<LoginVO> login(@RequestBody LoginDTO loginDTO) {
log.info("用户登录请求: loginType={}, username={}", loginDTO.getLoginType(), loginDTO.getUsername());
LoginVO loginVO = userService.login(loginDTO);
return Result.success(loginVO);
}

View File

@ -1,24 +1,22 @@
package com.designhub.dto;
import lombok.Data;
import jakarta.validation.constraints.NotBlank;
/**
* 登录请求DTO
* 注:验证逻辑在Service层根据loginType进行处理
*/
@Data
public class LoginDTO {
/**
* 用户名
* 用户名(密码登录时必填)
*/
@NotBlank(message = "用户名不能为空")
private String username;
/**
* 密码
* 密码(密码登录时必填)
*/
@NotBlank(message = "密码不能为空")
private String password;
/**

View File

@ -808,7 +808,14 @@ public class UserService {
String loginType = loginDTO.getLoginType();
if ("password".equals(loginType)) {
// 用户名密码登录
// 用户名密码登录 - 验证必填参数
if (loginDTO.getUsername() == null || loginDTO.getUsername().trim().isEmpty()) {
throw new BusinessException(ResultCode.PARAM_ERROR, "用户名不能为空");
}
if (loginDTO.getPassword() == null || loginDTO.getPassword().trim().isEmpty()) {
throw new BusinessException(ResultCode.PARAM_ERROR, "密码不能为空");
}
User user = getUserByUsername(loginDTO.getUsername());
if (user == null) {
throw new BusinessException(ResultCode.USER_NOT_EXIST);
@ -836,7 +843,10 @@ public class UserService {
.roleIds(user.getRoleIds())
.build();
} else if ("dingtalk".equals(loginType)) {
// 钉钉OAuth 2.0登录
// 钉钉OAuth 2.0登录 - 验证授权码
if (loginDTO.getAuthCode() == null || loginDTO.getAuthCode().trim().isEmpty()) {
throw new BusinessException(ResultCode.PARAM_ERROR, "钉钉授权码不能为空");
}
return handleDingTalkLogin(loginDTO.getAuthCode());
} else if ("casdoor".equals(loginType)) {
// Casdoor登录 - 暂时返回错误,待后续实现

View File

@ -3,8 +3,8 @@ import request from '@/utils/request'
const API_BASE = ''
export interface LoginParams {
username: string
password: string
username?: string
password?: string
loginType?: string
authCode?: string
}