Skip to content
Open
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
5 changes: 4 additions & 1 deletion BE/src/main/java/com/wepat/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wepat.config;


import com.wepat.aop.interceptor.JwtIntercepptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
Expand All @@ -21,7 +22,9 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/finance/**")
.excludePathPatterns("/member/signup")
.excludePathPatterns("/member/logout")
.excludePathPatterns("/member/signin");
.excludePathPatterns("/member/signin")
.excludePathPatterns("/member/socialsignin")
.excludePathPatterns("/member/socialsignup");

}
}
3 changes: 2 additions & 1 deletion BE/src/main/java/com/wepat/member/MemberEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public MemberEntity(MemberDto member) {
this.email = member.getEmail();
this.calendarId = member.getCalendarId();
this.reportList = new ArrayList<>();
this.block = new Boolean(false);
this.block = false;
this.social=member.getSocial();
}
@ApiParam(value = "사용자 비밀번호", required = true)
private String pwd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,38 @@ public ResponseEntity<?> signIn(String memberId, String pwd) {
throw new RuntimeException();
}
}
@PostMapping("/socialsignin")
@ApiOperation(value = "로그인 시도", notes = "로그인 요청을 한다.",response = MemberDto.class)
public ResponseEntity<?> socialsignin(String memberId, int social) {
try {
Map<String, String> resultMap = new HashMap<>();
MemberDto memberResult = memberService.socialSignIn(memberId,social);//유저가 로그인 가능한 유저인지 확인
String accessToken = null;
String refreshToken = null;//유저가 로그인 되면 토큰을 생성하여 저장할 String
if(memberResult != null){//로그인에서 객체를 받아왔다.
accessToken = jwtUtil.createAccessToken("memberId", memberId);
refreshToken = jwtUtil.createRefreshToken("memberId", memberId);
memberService.saveRefreshToken(memberId, refreshToken);

resultMap.put("access-token", accessToken);
resultMap.put("refresh-token", refreshToken);
return new ResponseEntity<>(resultMap, HttpStatus.ACCEPTED);
} else {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
} catch (IdWriteException e) {
throw new IdWriteException(e.getMessage());
} catch (BlockMember e) {
throw new BlockMember(e.getMessage());
} catch (PwdWriteException e) {
throw new PwdWriteException(e.getMessage());
} catch (Exception e) {
throw new RuntimeException();
}
}
@PostMapping("/signup")
@ApiOperation(value = "회원가입", notes = "정보를 받아 회원가입 시도한다.", response = MemberDto.class)
public ResponseEntity<?> signUp(MemberDto member) {
public ResponseEntity<?> signUp(@RequestBody MemberDto member) {
try {
memberService.signUp(member);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
Expand All @@ -73,6 +101,22 @@ public ResponseEntity<?> signUp(MemberDto member) {
throw new RuntimeException(e.getMessage());
}
}
@PostMapping("/socialsignup")
@ApiOperation(value = "SNS회원가입", notes = "SNS에서 정보를 받아 회원가입 시도한다.", response = MemberDto.class)
public ResponseEntity<?> socialsignup(MemberDto member) {
try {
memberService.socialsignup(member);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} catch (ExistEmailException e) {
throw new ExistEmailException(e.getMessage());
} catch (ExistIdException e) {
throw new ExistIdException(e.getMessage());
} catch (NotExistCalendarException e) {
throw new NotExistCalendarException(e.getMessage());
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
@PostMapping("/findid")
@ApiOperation(value = "아이디 찾기", notes = "이메일을 확인하여 해당 아이디 제공", response = String.class)
public ResponseEntity<?> findId(String email) {
Expand All @@ -84,6 +128,7 @@ public ResponseEntity<?> findId(String email) {
throw new RuntimeException();
}
}

@PostMapping("/findpwd")
@ApiOperation(value = "비밀번호 찾기", notes = "아이디, 이메일 인증 성공 시," +
"해당 이메일로 임시 비밀번호 제공 및 임시 비밀번호로 정보 변경", response = HttpResponse.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
public interface MemberRepository {
void signUpWithCalendar(MemberDto member) throws ExecutionException, InterruptedException;
void signUp(MemberDto member) throws ExecutionException, InterruptedException;
void socialsignup(MemberDto member)throws ExecutionException, InterruptedException;

MemberDto signIn(String memberId, String pwd) throws ExecutionException, InterruptedException;
MemberDto socialsignin( String id, int sns)throws ExecutionException, InterruptedException;

String findId(String email) throws ExecutionException, InterruptedException;
void changePwdToRandom(String randomPassword, String memberId) throws ExecutionException, InterruptedException;
void modifyPwd(String memberId, String pwd) throws ExecutionException, InterruptedException ;
Expand All @@ -23,5 +27,8 @@ public interface MemberRepository {
void deleteRefreshToken(String memberId) throws Exception;

void modifyCalendarIdAlone(String memberId) throws ExecutionException, InterruptedException;



}

Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,98 @@ public void signUp(MemberDto member) throws ExecutionException, InterruptedExcep
}
}

@Override
public void socialsignup(MemberDto member) throws ExecutionException, InterruptedException {

// memberId인 document 를 가져옴(없으면 생성)
final DocumentReference memDocRef = memCollection.document(member.getMemberId());
// calendar document 를 생성 (docId 는 랜덤값)
final DocumentReference calDocRef = calCollection.document();

// run an asynchronous transaction
ApiFuture<ReturnType> returnTypeApiFuture = db.runTransaction(transaction -> {

// memberId 인 document 를 가져옴
DocumentSnapshot memSnapshot = transaction.get(memDocRef).get();
// memberEntity 를 db 에 추가 함
member.setCalendarId(calDocRef.getId());
transaction.create(memDocRef, new MemberEntity(member));
// calendarEntity(memberId 를 갖는)를 db에 추가 함
transaction.create(calDocRef, new CalendarEntity(member.getMemberId()));

return ReturnType.SUCCESS;

});
// 트랜잭션 실행 결과를 반환
returnTypeApiFuture.get();
}



@Override
public MemberDto signIn(String memberId, String pwd) throws ExecutionException, InterruptedException {

final DocumentReference memDocRef = memCollection.document(memberId);

ApiFuture<ReturnType> returnTypeApiFuture = db.runTransaction(transaction -> {
ApiFuture<?> future = db.runTransaction(transaction -> {

DocumentSnapshot memSnapshot = transaction.get(memDocRef).get();
MemberEntity memberEntity = transaction.get(memDocRef).get().toObject(MemberEntity.class);
MemberDto memberDto = transaction.get(memDocRef).get().toObject(MemberDto.class);

if (!memSnapshot.exists()) { // 멤버ID가 없을 경우
return ReturnType.IdWriteException;

} else if (memSnapshot.toObject(MemberEntity.class).getSocial() != 0) { //SNS로 가입된 계정
return ReturnType.NotExistMember;
} else if (memSnapshot.toObject(MemberEntity.class).isBlock()) { //차단된 계정
return ReturnType.BlockMember;

} else if (memSnapshot.exists() && memberEntity.getPwd().equals(pwd)) { //해당 멤버ID가 있고, pwd가 같다면 로그인 성공
return ReturnType.SUCCESS;

} else if (memSnapshot.exists() && memberDto.getPwd().equals(pwd)) { //해당 멤버ID가 있고, pwd가 같다면 로그인 성공
return memberDto;
} else { //비밀번호가 다르다면
return ReturnType.PwdWriteException;

}
});
// 트랜잭션 실행 결과를 반환
if (future.get() == ReturnType.IdWriteException) {
throw new IdWriteException();
} else if (future.get() == ReturnType.BlockMember) {
throw new BlockMember();
} else if (future.get() == ReturnType.PwdWriteException) {
throw new PwdWriteException();
}
else if (future.get() == ReturnType.NotExistMember) {
throw new NotExistMember();
}
else {
return (MemberDto) future.get();
}
}

@Override
public MemberDto socialsignin(String memberId, int social) throws ExecutionException, InterruptedException {
final DocumentReference memDocRef = memCollection.document(memberId);

ApiFuture<ReturnType> returnTypeApiFuture = db.runTransaction(transaction -> {

DocumentSnapshot memSnapshot = transaction.get(memDocRef).get();
MemberEntity memberEntity = transaction.get(memDocRef).get().toObject(MemberEntity.class);

if (!memSnapshot.exists()) { // 멤버ID가 없을 경우
return ReturnType.IdWriteException;

} else if (memSnapshot.toObject(MemberEntity.class).isBlock()) { //차단된 계정
return ReturnType.BlockMember;
}
else if ( !(memberEntity.getSocial()==(social))) { //해당 SNS로 가입된 아이디아니면
return ReturnType.NotExistMember;//존재안하는 아이디로 판단
}
else { //다 통과
return ReturnType.SUCCESS;

}
});
// 트랜잭션 실행 결과를 반환ㅐ
if (returnTypeApiFuture.get() == ReturnType.IdWriteException) {
throw new IdWriteException();
} else if (returnTypeApiFuture.get() == ReturnType.BlockMember) {
Expand Down
5 changes: 5 additions & 0 deletions BE/src/main/java/com/wepat/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

public interface MemberService {
void signUp(MemberDto member) throws ExecutionException, InterruptedException;
void socialsignup(MemberDto member)throws ExecutionException, InterruptedException;
MemberDto signIn(String memberId, String pwd) throws ExecutionException, InterruptedException;
MemberDto socialSignIn(String memberId, int social)throws ExecutionException, InterruptedException;
String findId(String email) throws ExecutionException, InterruptedException;
void findPwd(String memberId, String email) throws ExecutionException, InterruptedException, MessagingException;
void modifyPwd(String memberId, String pwd) throws ExecutionException, InterruptedException;
Expand All @@ -24,4 +26,7 @@ public interface MemberService {
void saveRefreshToken(String memberId, String refreshToken) throws Exception;

void modifyCalendarIdAlone(String memberId) throws ExecutionException, InterruptedException;



}
10 changes: 10 additions & 0 deletions BE/src/main/java/com/wepat/member/service/MemberServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ public void signUp(MemberDto member) throws ExecutionException, InterruptedExcep
memberRepository.signUpWithCalendar(member);
}
}
@Override
public void socialsignup(MemberDto member) throws ExecutionException, InterruptedException {
memberRepository.socialsignup(member);//무조건 아이디생성

}
@Override
public MemberDto signIn(String memberId, String pwd) throws ExecutionException, InterruptedException {
return memberRepository.signIn(memberId, pwd);
}

@Override
public MemberDto socialSignIn(String memberId, int social) throws ExecutionException, InterruptedException {
return memberRepository.socialsignin(memberId, social);
}

@Override
public String findId(String email) throws ExecutionException, InterruptedException {
return memberRepository.findId(email);
Expand Down Expand Up @@ -120,4 +129,5 @@ public void modifyCalendarIdAlone(String memberId) throws ExecutionException, In
memberRepository.modifyCalendarIdAlone(memberId);
}


}
2 changes: 1 addition & 1 deletion BE/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

server.port= 8081
# spring boot tomcat multipart size limit
spring.servlet.multipart.max-file-size=128MB
spring.servlet.multipart.max-request-size=128MB
Expand Down