fix(비번초기화): 키 불일치 + 입력값 무시 픽스
- Frontend: body 키를 snake_case (user_id/new_password) 로 변환 - Controller: new_password 도 추출해서 service 에 전달 - Service: 2-arg 오버로드 추가, newPassword 입력값 사용 (blank 일 때만 Welcome1! fallback), userId null/blank 시 IllegalArgumentException 증상: 사용자관리에서 비밀번호 초기화 modal 입력 → backend 가 user_id=null 로 SQL 실행 (0행) + newPassword 무시 후 항상 Welcome1! 로 덮어쓰기.
This commit is contained in:
@@ -295,7 +295,8 @@ public class AdminController {
|
||||
@PostMapping("/users/reset-password")
|
||||
public ResponseEntity<ApiResponse<Void>> resetUserPassword(@RequestBody Map<String, Object> body) {
|
||||
String userId = (String) body.get("user_id");
|
||||
adminService.resetUserPassword(userId);
|
||||
String newPassword = (String) body.get("new_password");
|
||||
adminService.resetUserPassword(userId, newPassword);
|
||||
return ResponseEntity.ok(ApiResponse.success(null, "비밀번호 초기화 성공"));
|
||||
}
|
||||
|
||||
|
||||
@@ -208,10 +208,17 @@ public class AdminService extends BaseService {
|
||||
}
|
||||
|
||||
public void resetUserPassword(String userId) {
|
||||
String defaultPw = passwordEncoder.encode("Welcome1!");
|
||||
resetUserPassword(userId, null);
|
||||
}
|
||||
|
||||
public void resetUserPassword(String userId, String newPassword) {
|
||||
if (userId == null || userId.isBlank()) {
|
||||
throw new IllegalArgumentException("user_id 는 필수입니다");
|
||||
}
|
||||
String rawPw = (newPassword != null && !newPassword.isBlank()) ? newPassword : "Welcome1!";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("user_id", userId);
|
||||
params.put("user_password", defaultPw);
|
||||
params.put("user_password", passwordEncoder.encode(rawPw));
|
||||
sqlSession.update("admin.updateUserPassword", params);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,10 @@ export async function getUserHistory(userId: string, params?: Record<string, any
|
||||
* 사용자 비밀번호 초기화
|
||||
*/
|
||||
export async function resetUserPassword(resetData: { userId: string; newPassword: string }) {
|
||||
const response = await apiClient.post("/admin/users/reset-password", resetData);
|
||||
const response = await apiClient.post("/admin/users/reset-password", {
|
||||
user_id: resetData.userId,
|
||||
new_password: resetData.newPassword,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user