blob: 34bbb9690fca4ac772599fd944b189cba124a72f [file] [log] [blame]
223010718e412ad2025-04-24 22:24:51 +08001package com.example.g8backend.controller;
2
3import com.example.g8backend.dto.PasswordChangeDTO;
4import com.example.g8backend.service.IUserSecurityService;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.http.ResponseEntity;
7import org.springframework.security.core.Authentication;
8import org.springframework.security.core.context.SecurityContextHolder;
9import org.springframework.web.bind.annotation.*;
10
11@RestController
12@RequestMapping("/user/security")
13public class UserSecurityController {
14 @Autowired
15 private IUserSecurityService userSecurityService;
16
17 @PutMapping("/change-password")
18 public ResponseEntity<?> changePassword(@RequestBody PasswordChangeDTO dto) {
19 Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
20 Long userId = (Long) authentication.getPrincipal();
21 userSecurityService.changePassword(userId, dto.getOldPassword(), dto.getNewPassword());
22 return ResponseEntity.ok("密码修改成功");
23 }
24}