@@ -118,63 +118,42 @@ public ResponseEntity<?> getUser(
118118
119119 @ Operation (
120120 summary = "비밀번호 변경" ,
121- description = "특정 유저의 비밀번호 변경 (인증 필요)" ,
122- security = @ SecurityRequirement (name = "Bearer Authentication" )
121+ description = "특정 유저의 비밀번호 변경 (인증 없음)"
123122 )
124123 @ ApiResponse (responseCode = "200" , description = "비밀번호 변경 성공" )
125124 @ ApiResponse (responseCode = "400" , description = "잘못된 요청" )
126- @ ApiResponse (responseCode = "401" , description = "인증 실패" )
127- @ ApiResponse (responseCode = "403" , description = "권한 없음" )
128125 @ PatchMapping ("/password" )
129126 public ResponseEntity <?> updatePassword (
130- @ RequestBody PasswordUpdateRequest passwordUpdateRequest ,
131- @ RequestAttribute (name = "username" , required = false ) String tokenUsername ) {
127+ @ RequestBody PasswordUpdateRequest passwordUpdateRequest ) {
132128
133129 String username = passwordUpdateRequest .getUsername ();
134-
135- if (tokenUsername == null ) {
136- return ResponseEntity .status (HttpStatus .UNAUTHORIZED ).body (
137- Map .of ("message" , "인증이 필요합니다." )
138- );
139- }
140-
141- if (!tokenUsername .equals (username )) {
142- return ResponseEntity .status (HttpStatus .FORBIDDEN ).body (
143- Map .of ("message" , "비밀번호 변경 권한이 없습니다." )
144- );
145- }
146-
147130 String oldPassword = passwordUpdateRequest .getOld_password ();
148131 String newPassword = passwordUpdateRequest .getNew_password ();
149132
150- oldPassword = oldPassword .trim ();
151- newPassword = newPassword .trim ();
152-
153- // 입력값 null 또는 공백만 있는 경우 예외 처리
133+ // null 체크 후 trim
154134 if (oldPassword == null || oldPassword .trim ().isEmpty ()) {
155135 return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body ("현재 비밀번호를 입력해주세요." );
156136 }
157-
158137 if (newPassword == null || newPassword .trim ().isEmpty ()) {
159138 return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body ("새 비밀번호를 입력해주세요." );
160139 }
161140
162- // 사용자 정보 조회 및 현재 비밀번호 검증
141+ oldPassword = oldPassword .trim ();
142+ newPassword = newPassword .trim ();
143+
144+ // 사용자 정보 조회
163145 User user = userService .getUserByUsername (username );
164146 String currentPassword = user .getPassword ();
165147
166148 if (!oldPassword .equals (currentPassword )) {
167- return ResponseEntity .status (HttpStatus .FORBIDDEN ).body ("현재 비밀번호가 일치하지 않습니다." );
149+ return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body ("현재 비밀번호가 일치하지 않습니다." );
168150 }
169151
170152 if (oldPassword .equals (newPassword )) {
171153 return ResponseEntity .status (HttpStatus .BAD_REQUEST ).body ("새 비밀번호가 현재 비밀번호와 동일합니다." );
172154 }
173155
174- // 비밀번호 변경 수행
175156 userService .updatePassword (username , newPassword );
176- Map <String , String > response = new HashMap <>();
177- response .put ("message" , "비밀번호 변경에 성공했습니다." );
178- return ResponseEntity .ok (response );
157+ return ResponseEntity .ok (Map .of ("message" , "비밀번호 변경에 성공했습니다." ));
179158 }
180159}
0 commit comments