Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/main/java/com/back/domain/user/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
Expand Down Expand Up @@ -50,7 +49,7 @@ public ResponseEntity<RsData<UserResponse>> verifyEmail(
// 인증 메일 재발송
@PostMapping("/email/verify")
public ResponseEntity<RsData<Void>> resendVerificationEmail(
@Valid @RequestBody ResendVerificationRequest request
@Valid @RequestBody SendEmailRequest request
) {
authService.resendVerificationEmail(request.email());
return ResponseEntity
Expand Down Expand Up @@ -100,4 +99,43 @@ public ResponseEntity<RsData<Map<String, String>>> refreshToken(
Map.of("accessToken", newAccessToken)
));
}

// 아이디 찾기
@PostMapping("/username/recover")
public ResponseEntity<RsData<Void>> recoverUsername(
@Valid @RequestBody SendEmailRequest request
) {
authService.recoverUsername(request.email());
return ResponseEntity
.ok(RsData.success(
"아이디를 이메일로 전송했습니다.",
null
));
}

// 비밀번호 재설정 요청
@PostMapping("/password/recover")
public ResponseEntity<RsData<Void>> recoverPassword(
@Valid @RequestBody SendEmailRequest request
) {
authService.recoverPassword(request.email());
return ResponseEntity
.ok(RsData.success(
"비밀번호 재설정 링크를 이메일로 전송했습니다.",
null
));
}

// 비밀번호 재설정
@PostMapping("/password/reset")
public ResponseEntity<RsData<Void>> resetPassword(
@Valid @RequestBody PasswordResetRequest request
) {
authService.resetPassword(request.token(), request.newPassword());
return ResponseEntity
.ok(RsData.success(
"비밀번호가 성공적으로 재설정되었습니다.",
null
));
}
}
231 changes: 230 additions & 1 deletion src/main/java/com/back/domain/user/controller/AuthControllerDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

Expand Down Expand Up @@ -305,7 +306,7 @@ ResponseEntity<RsData<UserResponse>> verifyEmail(
)
})
ResponseEntity<RsData<Void>> resendVerificationEmail(
@Valid @RequestBody ResendVerificationRequest request
@Valid @RequestBody SendEmailRequest request
);

@Operation(
Expand Down Expand Up @@ -690,4 +691,232 @@ ResponseEntity<RsData<Map<String, String>>> refreshToken(
HttpServletRequest request,
HttpServletResponse response
);

@Operation(
summary = "아이디 찾기",
description = "사용자가 이메일을 입력하면, 해당 이메일로 가입된 계정의 아이디(username)를 일부 마스킹 처리하여 이메일로 전송합니다."
)
@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "아이디 찾기 성공",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": true,
"code": "SUCCESS_200",
"message": "아이디를 이메일로 전송했습니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "404",
description = "존재하지 않는 사용자",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "USER_001",
"message": "존재하지 않는 사용자입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청 (이메일 누락 등)",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "COMMON_400",
"message": "잘못된 요청입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "COMMON_500",
"message": "서버 오류가 발생했습니다.",
"data": null
}
""")
)
)
})
@PostMapping("/username/recover")
ResponseEntity<RsData<Void>> recoverUsername(
@Valid @RequestBody SendEmailRequest request
);

@Operation(
summary = "비밀번호 재설정 요청",
description = "사용자가 가입한 이메일을 입력하면, 해당 이메일로 비밀번호 재설정 링크가 발송됩니다."
)
@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "비밀번호 재설정 메일 발송 성공",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": true,
"code": "SUCCESS_200",
"message": "비밀번호 재설정 메일을 전송했습니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "404",
description = "존재하지 않는 사용자",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "USER_001",
"message": "존재하지 않는 사용자입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청 (이메일 누락 등)",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "COMMON_400",
"message": "잘못된 요청입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "COMMON_500",
"message": "서버 오류가 발생했습니다.",
"data": null
}
""")
)
)
})
@PostMapping("/password/recover")
ResponseEntity<RsData<Void>> recoverPassword(
@Valid @RequestBody SendEmailRequest request
);

@Operation(
summary = "비밀번호 재설정",
description = "비밀번호 재설정 토큰과 새로운 비밀번호를 입력받아 계정 비밀번호를 변경합니다. 토큰은 1시간 동안만 유효합니다."
)
@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "비밀번호 재설정 성공",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": true,
"code": "SUCCESS_200",
"message": "비밀번호가 성공적으로 재설정되었습니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청 (필드 누락, 비밀번호 정책 위반)",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "COMMON_400",
"message": "잘못된 요청입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "401",
description = "유효하지 않은 비밀번호 재설정 토큰",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "TOKEN_003",
"message": "유효하지 않은 비밀번호 재설정 토큰입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "404",
description = "존재하지 않는 사용자",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "USER_001",
"message": "존재하지 않는 사용자입니다.",
"data": null
}
""")
)
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(value = """
{
"success": false,
"code": "COMMON_500",
"message": "서버 오류가 발생했습니다.",
"data": null
}
""")
)
)
})
@PostMapping("/password/reset")
ResponseEntity<RsData<Void>> resetPassword(
@Valid @RequestBody PasswordResetRequest request
);
}
6 changes: 6 additions & 0 deletions src/main/java/com/back/domain/user/dto/LoginResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.back.domain.user.dto;

/**
* 사용자 로그인 응답을 나타내는 DTO
*
* @param accessToken 사용자 인증에 사용되는 JWT 토큰
* @param user 로그인한 사용자 정보
*/
public record LoginResponse(
String accessToken,
UserResponse user
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/back/domain/user/dto/PasswordResetRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.back.domain.user.dto;

import jakarta.validation.constraints.NotBlank;

/**
* 비밀번호 재설정 요청 DTO
*
* @param token 비밀번호 재설정 토큰
* @param newPassword 새 비밀번호
*/
public record PasswordResetRequest(
@NotBlank String token,
@NotBlank String newPassword
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

public record ResendVerificationRequest(
/**
* 이메일 전송 요청을 나타내는 DTO
*
* @param email 이메일 주소
*/
public record SendEmailRequest(
@NotBlank @Email String email
) {
}
Loading