blob: 34bbb9690fca4ac772599fd944b189cba124a72f [file] [log] [blame]
package com.example.g8backend.controller;
import com.example.g8backend.dto.PasswordChangeDTO;
import com.example.g8backend.service.IUserSecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/user/security")
public class UserSecurityController {
@Autowired
private IUserSecurityService userSecurityService;
@PutMapping("/change-password")
public ResponseEntity<?> changePassword(@RequestBody PasswordChangeDTO dto) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Long userId = (Long) authentication.getPrincipal();
userSecurityService.changePassword(userId, dto.getOldPassword(), dto.getNewPassword());
return ResponseEntity.ok("密码修改成功");
}
}