Skip to content

Commit

Permalink
[feat]: fcm 저장 및 조회 기능 추가 및 회원 아이디 중복 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Gseungmin committed Aug 12, 2023
1 parent 012e727 commit c8b440d
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/main/java/com/umc/refit/domain/dto/chat/FCM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.umc.refit.domain.dto.chat;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class FCM {
private String otherFcm;
}
10 changes: 10 additions & 0 deletions src/main/java/com/umc/refit/domain/dto/member/NameDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.umc.refit.domain.dto.member;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class NameDto {
private String name;
}
1 change: 1 addition & 0 deletions src/main/java/com/umc/refit/domain/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Member implements UserDetails {
private String socialType;
private Integer gender;
private String imageUrl;
private String fcm;
@ElementCollection(fetch = FetchType.EAGER)
private List<String> roles = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
, "/auth/reset/password" //패스워드 찾기
, "/static/**" //카카오 주소 api
, "/*.html" //카카오 주소 api
, "/oauth2/fcm"
, "/auth/join/name"
// , "/**" //임시로 모든 인증 처리 제외
).permitAll()
.anyRequest().authenticated())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public ResEmailDto email(@RequestBody EmailDto emailDto) throws MessagingExcepti
return new ResEmailDto(auth);
}

@PostMapping("/join/name")
public void checkName(@RequestBody NameDto nameDto) {
String name = nameDto.getName();
nameCheck(name);
}

/*회원 가입 API*/
@PostMapping("/join")
public void join(@RequestBody JoinDto joinDto) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/umc/refit/web/controller/OauthController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.refit.web.controller;

import com.umc.refit.domain.dto.chat.FCM;
import com.umc.refit.domain.dto.chat.OAuth2;
import com.umc.refit.domain.entity.Member;
import com.umc.refit.exception.ExceptionType;
Expand Down Expand Up @@ -33,4 +34,14 @@ public OAuth2 auth(Authentication authentication, HttpServletRequest request) {

return new OAuth2(member.getName());
}

@GetMapping("/oauth2/fcm")
public FCM getFcm(HttpServletRequest request) {

String otherId = request.getParameter("otherId");

Optional<Member> other = memberService.findMemberByName(otherId);

return new FCM(other.get().getFcm());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ

String loginId = request.getParameter("loginId");
String password = request.getParameter("password");
String fcm = request.getParameter("fcm");

Optional<Member> findMember = memberService.findMemberByLoginId(loginId);

Expand All @@ -54,6 +55,11 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
}
}

//fcm 토큰 저장
Member member = findMember.get();
member.setFcm(fcm);
memberService.updateFcm(member);

AuthenticationManager authenticationManager = httpSecurity.getSharedObject(AuthenticationManager.class);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginId, password);
Authentication authentication = authenticationManager.authenticate(authenticationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ protected boolean shouldNotFilter(HttpServletRequest request) {
|| pathMatcher.match("/auth/reset/password", path) //패스워드 찾기
|| pathMatcher.match("/auth/login", path) //일반 로그인
|| pathMatcher.match("/*.html", path)
|| pathMatcher.match("/oauth2/fcm", path)
|| pathMatcher.match("/auth/join/name", path)
// || pathMatcher.match("/**", path) //API 테스트를 위해 모든 로직에 대해 인가 제외
);
}
Expand Down
4 changes: 4 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 @@ -46,6 +46,10 @@ public void save(Member member) {
memberRepository.save(member);
}

public void updateFcm(Member member) {
memberRepository.save(member);
}

/* 회원 패스워드 수정 */
public void updateMemberPassword(Member member, String newPassword) {
member.updatePassword(passwordEncoder.encode(newPassword));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spring:

jpa:
hibernate:
ddl-auto: update
ddl-auto: create

properties:
hibernate:
Expand Down

0 comments on commit c8b440d

Please sign in to comment.