From 33dcc7eaae665c711de7190c66f66812997db237 Mon Sep 17 00:00:00 2001 From: yunhacandy Date: Tue, 13 Aug 2024 23:09:49 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=EC=9D=BC=EB=B0=98=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 확장성을 고려해서 api path 수정 - AuthService에서 RefreshTokenEntity 관련 코드 삽입 및 수정 - AuthProvider Enum을 통해 로그인 종류 구분 --- .../auth/controller/AuthController.java | 13 ++++++------- .../growingpain/auth/service/AuthService.java | 2 ++ .../growingpain/member/domain/entity/Member.java | 14 +++++++------- .../growingpain/security/oauth/AuthProvider.java | 12 ++++++++++++ src/main/resources/application-local.yml | 9 ++++----- 5 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 src/main/java/cotato/growingpain/security/oauth/AuthProvider.java diff --git a/src/main/java/cotato/growingpain/auth/controller/AuthController.java b/src/main/java/cotato/growingpain/auth/controller/AuthController.java index d8e25ae..2254124 100644 --- a/src/main/java/cotato/growingpain/auth/controller/AuthController.java +++ b/src/main/java/cotato/growingpain/auth/controller/AuthController.java @@ -38,14 +38,13 @@ public class AuthController { private final AuthService authService; - @Operation(summary = "회원가입", description = "회원가입 및 로그인을 위한 메소드") - @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))) - @PostMapping("/join") + @Operation(summary = "일반 로그인", description = "회원가입 및 로그인을 위한 메소드") + @ApiResponse(content = @Content(schema = @Schema(implementation = Token.class))) + @PostMapping("/login/general") @ResponseStatus(HttpStatus.OK ) - public Response joinAuth(@RequestBody @Valid LoginRequest request) { - log.info("[회원 가입 컨트롤러]: {}", request.email()); - Token token = authService.createLoginInfo(request); - return Response.createSuccess("회원가입 및 로그인 완료", token); + public Response joinAuth(@RequestBody @Valid LoginRequest request) { + log.info("[일반 로그인 컨트롤러]: {}", request.email()); + return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(request)); } @Operation(summary = "추가 정보 입력", description = "최초 로그인 (회원가입) 시 추가 정보를 입력하는 메소드") diff --git a/src/main/java/cotato/growingpain/auth/service/AuthService.java b/src/main/java/cotato/growingpain/auth/service/AuthService.java index b1b07fa..a661144 100644 --- a/src/main/java/cotato/growingpain/auth/service/AuthService.java +++ b/src/main/java/cotato/growingpain/auth/service/AuthService.java @@ -19,6 +19,7 @@ import cotato.growingpain.security.jwt.Token; import cotato.growingpain.security.jwt.dto.request.ReissueRequest; import cotato.growingpain.security.jwt.dto.response.ReissueResponse; +import cotato.growingpain.security.oauth.AuthProvider; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -75,6 +76,7 @@ public Token createLoginInfo(LoginRequest request) { .password(bCryptPasswordEncoder.encode(request.password())) .email(request.email()) .memberRole(MemberRole.PENDING) + .authProvider(AuthProvider.GENERAL) .build(); memberRepository.save(member); diff --git a/src/main/java/cotato/growingpain/member/domain/entity/Member.java b/src/main/java/cotato/growingpain/member/domain/entity/Member.java index 71b4b75..6645bca 100644 --- a/src/main/java/cotato/growingpain/member/domain/entity/Member.java +++ b/src/main/java/cotato/growingpain/member/domain/entity/Member.java @@ -14,6 +14,7 @@ import cotato.growingpain.post.domain.entity.PostSave; import cotato.growingpain.replycomment.domain.entity.ReplyComment; import cotato.growingpain.replycomment.domain.entity.ReplyCommentLike; +import cotato.growingpain.security.oauth.AuthProvider; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -74,8 +75,9 @@ public class Member extends BaseTimeEntity { @Column(name = "oauth_id") private String oauth2Id; -// @Column(name = "auth_provider") -// private AuthProvider authProvider; + @Column(name = "auth_provider") + @Enumerated(EnumType.STRING) + private AuthProvider authProvider; @Column(name = "education_background") private String educationBackground; @@ -139,14 +141,12 @@ public class Member extends BaseTimeEntity { private List jobPosts = new ArrayList<>(); @Builder - public Member(String email, String password, MemberRole memberRole, String name, String field, String belong, String profileImageUrl) { + public Member(String email, String password, String oauth2Id, AuthProvider authProvider, MemberRole memberRole) { this.email = email; this.password = password; + this.oauth2Id = oauth2Id; + this.authProvider = authProvider; this.memberRole = memberRole; - this.name = name; - this.field = field; - this.belong = belong; - this.profileImageUrl = profileImageUrl; } public void updatePassword(String newPassword) { diff --git a/src/main/java/cotato/growingpain/security/oauth/AuthProvider.java b/src/main/java/cotato/growingpain/security/oauth/AuthProvider.java new file mode 100644 index 0000000..ab376bd --- /dev/null +++ b/src/main/java/cotato/growingpain/security/oauth/AuthProvider.java @@ -0,0 +1,12 @@ +package cotato.growingpain.security.oauth; + +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public enum AuthProvider { + GENERAL("일반 로그인"), + KAKAO("카카오 소셜 로그인"), + GOOGLE("구글 소셜 로그인"); + + private final String 분description; +} \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index f38ae1d..2272a84 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -30,8 +30,7 @@ jwt: refresh: expiration: 86400000 #7일 -logging: - discord: - webhook-url: ${DISCORD_WEBHOOK_URL} - config: classpath:logback-test.xml - +#logging: +# discord: +# webhook-url: ${DISCORD_WEBHOOK_URL} +# config: classpath:logback-test.xml \ No newline at end of file From f796c5565b8d9db08488531d82f40c7e1fffccb8 Mon Sep 17 00:00:00 2001 From: yunhacandy Date: Tue, 13 Aug 2024 23:28:02 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=ED=99=95=EC=9E=A5=EC=84=B1?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AuthProvider 관련 정보를 AuthService와 AuthController에도 추가 - 공통 메서드 분리 --- .../auth/controller/AuthController.java | 3 ++- .../growingpain/auth/service/AuthService.java | 23 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/cotato/growingpain/auth/controller/AuthController.java b/src/main/java/cotato/growingpain/auth/controller/AuthController.java index 2254124..6796b7c 100644 --- a/src/main/java/cotato/growingpain/auth/controller/AuthController.java +++ b/src/main/java/cotato/growingpain/auth/controller/AuthController.java @@ -11,6 +11,7 @@ import cotato.growingpain.security.jwt.Token; import cotato.growingpain.security.jwt.dto.request.ReissueRequest; import cotato.growingpain.security.jwt.dto.response.ReissueResponse; +import cotato.growingpain.security.oauth.AuthProvider; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -44,7 +45,7 @@ public class AuthController { @ResponseStatus(HttpStatus.OK ) public Response joinAuth(@RequestBody @Valid LoginRequest request) { log.info("[일반 로그인 컨트롤러]: {}", request.email()); - return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(request)); + return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(AuthProvider.GENERAL, request)); } @Operation(summary = "추가 정보 입력", description = "최초 로그인 (회원가입) 시 추가 정보를 입력하는 메소드") diff --git a/src/main/java/cotato/growingpain/auth/service/AuthService.java b/src/main/java/cotato/growingpain/auth/service/AuthService.java index a661144..c7f8133 100644 --- a/src/main/java/cotato/growingpain/auth/service/AuthService.java +++ b/src/main/java/cotato/growingpain/auth/service/AuthService.java @@ -42,7 +42,7 @@ public class AuthService { private final BlackListRepository blackListRepository; @Transactional - public Token createLoginInfo(LoginRequest request) { + public Token createLoginInfo(AuthProvider authProvider, LoginRequest request) { Optional existingMember = memberRepository.findByEmail(request.email()); @@ -72,13 +72,7 @@ public Token createLoginInfo(LoginRequest request) { log.info("[회원 가입 서비스]: {}", request.email()); - Member member = Member.builder() - .password(bCryptPasswordEncoder.encode(request.password())) - .email(request.email()) - .memberRole(MemberRole.PENDING) - .authProvider(AuthProvider.GENERAL) - .build(); - memberRepository.save(member); + Member member = registerMember(authProvider, request.email(), request.password()); // 회원가입 성공 후 토큰 생성 및 반환 Token token = jwtTokenProvider.createToken(member.getId(), member.getEmail(), MemberRole.PENDING.getDescription()); @@ -89,6 +83,19 @@ public Token createLoginInfo(LoginRequest request) { } } + private Member registerMember(AuthProvider authProvider, String email, String password) { + Member.MemberBuilder memberBuilder = Member.builder() + .email(email) + .authProvider(authProvider) + .memberRole(MemberRole.PENDING); + + if (authProvider == AuthProvider.GENERAL) { + memberBuilder.password(bCryptPasswordEncoder.encode(password)); + } + + return memberRepository.save(memberBuilder.build()); + } + @Transactional public Token completeSignup(CompleteSignupRequest request, String accessToken) { From fd456f12157ea5b89b3caf128d66d6feb0bcbb6e Mon Sep 17 00:00:00 2001 From: yunhacandy Date: Wed, 14 Aug 2024 14:52:09 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=B2=B4=ED=81=AC=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=BD=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cotato/growingpain/auth/service/AuthService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/cotato/growingpain/auth/service/AuthService.java b/src/main/java/cotato/growingpain/auth/service/AuthService.java index c7f8133..f50a2db 100644 --- a/src/main/java/cotato/growingpain/auth/service/AuthService.java +++ b/src/main/java/cotato/growingpain/auth/service/AuthService.java @@ -110,6 +110,7 @@ public Token completeSignup(CompleteSignupRequest request, String accessToken) { if(member.getMemberRole() == MemberRole.PENDING){ // 필드를 개별적으로 업데이트 member.updateMemberInfo(request.name(), request.field(), request.belong(),request.job()); + validateService.checkDuplicateNickName(request.name()); //닉네임 중복 체크 member.updateRole(MemberRole.MEMBER); memberRepository.save(member); From a22148d0eb66a73107f13c6d5bf299a43eba8248 Mon Sep 17 00:00:00 2001 From: yunhacandy Date: Wed, 14 Aug 2024 15:18:21 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=A9=94=EC=9D=BC,=20?= =?UTF-8?q?=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=97=90=EB=9F=AC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cotato/growingpain/auth/service/AuthService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cotato/growingpain/auth/service/AuthService.java b/src/main/java/cotato/growingpain/auth/service/AuthService.java index f50a2db..1e09c29 100644 --- a/src/main/java/cotato/growingpain/auth/service/AuthService.java +++ b/src/main/java/cotato/growingpain/auth/service/AuthService.java @@ -68,7 +68,7 @@ public Token createLoginInfo(AuthProvider authProvider, LoginRequest request) { else { // 신규 회원일 경우 회원가입 처리 validateService.checkPasswordPattern(request.password()); - validateService.checkDuplicateEmail(request.email()); + //validateService.checkDuplicateEmail(request.email()); log.info("[회원 가입 서비스]: {}", request.email()); @@ -110,7 +110,7 @@ public Token completeSignup(CompleteSignupRequest request, String accessToken) { if(member.getMemberRole() == MemberRole.PENDING){ // 필드를 개별적으로 업데이트 member.updateMemberInfo(request.name(), request.field(), request.belong(),request.job()); - validateService.checkDuplicateNickName(request.name()); //닉네임 중복 체크 + //validateService.checkDuplicateNickName(request.name()); member.updateRole(MemberRole.MEMBER); memberRepository.save(member);