Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: 카카오 로그인시 필요한 로직 추가 구현 #115

Merged
merged 2 commits into from
Aug 18, 2023
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
9 changes: 7 additions & 2 deletions src/main/java/com/umc/refit/domain/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 {

/*카카오 로그인 시 유일한 멤버 닉네임 생성*/
Expand All @@ -79,9 +85,8 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
}
}

Member member = new Member(EMAIL, DEFAULT_PASSWORD, name);
member.getRoles().add("USER");
memberService.save(member);
Member member = new Member(EMAIL, DEFAULT_PASSWORD, name, fcm);
memberService.kakaoSave(member);
}

AuthenticationManager authenticationManager = httpSecurity.getSharedObject(AuthenticationManager.class);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/umc/refit/web/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,6 +16,9 @@ public class MemberService {
private final MemberRepository memberRepository;
private final PasswordEncoder passwordEncoder;

@Value("${member.image}")
private String imageUrl;

public Optional<Member> findMemberByEmail(String email) {
return memberRepository.findByEmail(email);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Loading