“mitao”
2026-03-27 cde5977f64ff1dfa928d1076c059e8865c02d70b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.tcm.training.admin.auth.controller;
 
import com.tcm.training.admin.auth.dto.ChangePasswordRequest;
import com.tcm.training.admin.auth.dto.LoginRequest;
import com.tcm.training.admin.auth.dto.ProfileUpdateRequest;
import com.tcm.training.admin.auth.service.AuthService;
import com.tcm.training.admin.auth.service.CaptchaService;
import com.tcm.training.admin.auth.vo.CaptchaResponse;
import com.tcm.training.admin.auth.vo.LoginResponse;
import com.tcm.training.admin.auth.vo.UserVO;
import com.tcm.training.admin.common.ApiResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.validation.Valid;
 
@Validated
@RestController
@RequestMapping("/api/auth")
public class AuthController {
 
    private final AuthService authService;
    private final CaptchaService captchaService;
 
    public AuthController(AuthService authService, CaptchaService captchaService) {
        this.authService = authService;
        this.captchaService = captchaService;
    }
 
    @PostMapping("/login")
    public ApiResponse<LoginResponse> login(@Valid @RequestBody LoginRequest req) {
        return ApiResponse.ok(authService.login(req));
    }
 
    @PostMapping("/logout")
    public ApiResponse<Void> logout() {
        authService.logout();
        return ApiResponse.ok(null);
    }
 
    @GetMapping("/captcha")
    public ApiResponse<CaptchaResponse> captcha() {
        return ApiResponse.ok(captchaService.createCaptcha());
    }
 
    @GetMapping("/me")
    public ApiResponse<UserVO> me() {
        return ApiResponse.ok(authService.me());
    }
 
    @PutMapping("/profile")
    public ApiResponse<UserVO> updateProfile(@Valid @RequestBody ProfileUpdateRequest req) {
        return ApiResponse.ok(authService.updateProfile(req));
    }
 
    @PostMapping("/change-password")
    public ApiResponse<Void> changePassword(@Valid @RequestBody ChangePasswordRequest req) {
        authService.changePassword(req);
        return ApiResponse.ok(null);
    }
}