From 7385dd6795429959bc74a90bde5d1fe1312d77f7 Mon Sep 17 00:00:00 2001 From: Ji Seungmin Date: Fri, 18 Aug 2023 22:12:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/umc/refit/domain/entity/Member.java | 9 +++++++-- .../authentication/JwtKakaoAuthenticationFilter.java | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/umc/refit/domain/entity/Member.java b/src/main/java/com/umc/refit/domain/entity/Member.java index a8c7cb4..71621c0 100644 --- a/src/main/java/com/umc/refit/domain/entity/Member.java +++ b/src/main/java/com/umc/refit/domain/entity/Member.java @@ -42,11 +42,16 @@ public Member(String name) { this.name = name; } - public Member(String email, String password, String name) { - this.password = password; + public Member(String email, String password, String name, String fcm) { this.email = email; this.loginId = email; + this.password = password; this.name = name; + this.birth = LocalDate.now().toString().replace('-', '/'); + this.gender = 0; + this.getRoles().add("USER"); + this.joinDate = LocalDate.now(); + this.fcm = fcm; this.socialType = "KAKAO"; } diff --git a/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java b/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java index 9538ca0..de312d9 100644 --- a/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java +++ b/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java @@ -56,6 +56,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ String KAKAO_API_URL = "https://kapi.kakao.com/v2/user/me"; String DEFAULT_PASSWORD = "KAKAO_LOGIN"; String accessToken = request.getHeader("Authorization"); + String fcm = request.getParameter("fcm"); String EMAIL = getEmailFromKakao(accessToken, KAKAO_API_URL); @@ -65,6 +66,11 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ throw new LoginException(BASIC_MEMBER_EXIST, BASIC_MEMBER_EXIST.getCode(), BASIC_MEMBER_EXIST.getErrorMessage()); } + + //fcm 토큰 저장 + Member member = findMember.get(); + member.setFcm(fcm); + memberService.updateFcm(member); } else { /*카카오 로그인 시 유일한 멤버 닉네임 생성*/ @@ -79,8 +85,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ } } - Member member = new Member(EMAIL, DEFAULT_PASSWORD, name); - member.getRoles().add("USER"); + Member member = new Member(EMAIL, DEFAULT_PASSWORD, name, fcm); memberService.save(member); } From 4c57db9238765056ec597de353c70d3127c5be5f Mon Sep 17 00:00:00 2001 From: Ji Seungmin Date: Fri, 18 Aug 2023 22:37:24 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=8B=9C=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authentication/JwtKakaoAuthenticationFilter.java | 2 +- .../java/com/umc/refit/web/service/MemberService.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java b/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java index de312d9..0b70e16 100644 --- a/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java +++ b/src/main/java/com/umc/refit/web/filter/authentication/JwtKakaoAuthenticationFilter.java @@ -86,7 +86,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ } Member member = new Member(EMAIL, DEFAULT_PASSWORD, name, fcm); - memberService.save(member); + memberService.kakaoSave(member); } AuthenticationManager authenticationManager = httpSecurity.getSharedObject(AuthenticationManager.class); diff --git a/src/main/java/com/umc/refit/web/service/MemberService.java b/src/main/java/com/umc/refit/web/service/MemberService.java index 4241544..e8982a3 100644 --- a/src/main/java/com/umc/refit/web/service/MemberService.java +++ b/src/main/java/com/umc/refit/web/service/MemberService.java @@ -3,6 +3,7 @@ import com.umc.refit.domain.entity.Member; import com.umc.refit.web.repository.MemberRepository; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -15,6 +16,9 @@ public class MemberService { private final MemberRepository memberRepository; private final PasswordEncoder passwordEncoder; + @Value("${member.image}") + private String imageUrl; + public Optional findMemberByEmail(String email) { return memberRepository.findByEmail(email); } @@ -46,6 +50,13 @@ public void save(Member member) { memberRepository.save(member); } + /*패스워드 인코딩 후 저장*/ + public void kakaoSave(Member member) { + member.setPassword(passwordEncoder.encode(member.getPassword())); + member.setImageUrl(imageUrl); + memberRepository.save(member); + } + public void updateFcm(Member member) { memberRepository.save(member); }