代码优化

This commit is contained in:
2025-10-13 10:43:08 +08:00
parent b6818b179c
commit bc3ed2d872
40 changed files with 3189 additions and 788 deletions
@@ -6,10 +6,14 @@ import com.emotion.dto.request.RegisterRequest;
import com.emotion.dto.request.RefreshTokenRequest;
import com.emotion.dto.response.AuthResponse;
import com.emotion.dto.response.CaptchaResponse;
import com.emotion.dto.response.SmsCodeResponse;
import com.emotion.dto.response.UserInfoResponse;
import com.emotion.service.AuthService;
import com.emotion.service.TokenService;
import com.emotion.util.UserContextUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -24,6 +28,7 @@ import javax.validation.Valid;
*/
@RestController
@RequestMapping("/auth")
@Tag(name = "认证管理", description = "用户注册、登录、验证码等认证相关接口")
public class AuthController {
@Autowired
@@ -33,18 +38,20 @@ public class AuthController {
private TokenService tokenService;
/**
* 用户登录
* 用户登录(简化版:手机号+验证码,不存在则自动注册)
*/
@PostMapping("/login")
@Operation(summary = "用户登录", description = "使用手机号和短信验证码登录,若用户不存在则自动注册")
public Result<AuthResponse> login(@Valid @RequestBody LoginRequest request) {
AuthResponse response = authService.login(request);
return Result.success("登录成功", response);
}
/**
* 用户注册
* 用户注册(简化版:仅需手机号、密码和短信验证码)
*/
@PostMapping("/register")
@Operation(summary = "用户注册", description = "使用手机号、密码和短信验证码进行注册")
public Result<AuthResponse> register(@Valid @RequestBody RegisterRequest request) {
AuthResponse response = authService.register(request);
return Result.success("注册成功", response);
@@ -60,14 +67,27 @@ public class AuthController {
}
/**
* 生成验证码
* 生成验证码(图形验证码,用于登录)
*/
@GetMapping("/captcha")
@Operation(summary = "获取图形验证码", description = "用于登录时的图形验证码")
public Result<CaptchaResponse> generateCaptcha() {
CaptchaResponse response = authService.generateCaptcha();
return Result.success(response);
}
/**
* 获取短信验证码(用于注册)
*/
@GetMapping("/sms-code")
@Operation(summary = "获取短信验证码", description = "用于注册时的短信验证码")
public Result<SmsCodeResponse> getSmsCode(
@Parameter(description = "手机号", required = true)
@RequestParam String phone) {
SmsCodeResponse response = authService.sendSmsCode(phone);
return Result.success("验证码已发送", response);
}
/**
* 用户登出
*/