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/회원가입 거절사유 메모 유저아이디 암호화 #162 #163

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Getter
public class MemoRequestDto {
@NotNull(message = "사용자 id가 없습니다.")
private Long userId;
private String userId;
@NotNull(message = "메모가 없습니다.")
private String memo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RejectionRequestDto {
@NotNull(message = "사용자 id가 없습니다.")
private Long userId;
private String userId;
@NotNull(message = "거절 사유가 없습니다.")
private String reason;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SignupResponseDto {
private Long id;
private String id;
private String name;
private String nickname;

public static SignupResponseDto of(Long id, String name, String nickname) {
public static SignupResponseDto of(String id, String name, String nickname) {
SignupResponseDto responseDto = new SignupResponseDto();
responseDto.id = id;
responseDto.name = name;
Expand Down
16 changes: 13 additions & 3 deletions wingle/src/main/java/kr/co/wingle/member/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import kr.co.wingle.common.exception.NotFoundException;
import kr.co.wingle.common.jwt.TokenInfo;
import kr.co.wingle.common.jwt.TokenProvider;
import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.common.util.RedisUtil;
import kr.co.wingle.common.util.S3Util;
import kr.co.wingle.common.util.SecurityUtil;
Expand Down Expand Up @@ -50,6 +51,7 @@
import kr.co.wingle.member.mailVo.CodeMail;
import kr.co.wingle.member.mailVo.RejectionMail;
import kr.co.wingle.profile.ProfileRepository;
import kr.co.wingle.profile.ProfileUtil;
import kr.co.wingle.profile.entity.Profile;
import lombok.RequiredArgsConstructor;

Expand All @@ -67,6 +69,8 @@ public class AuthService {
private final RedisUtil redisUtil;
private final MailService mailService;
private final MemberService memberService;
private final ProfileUtil profileUtil;
private final AES256Util aes;

@Transactional
public SignupResponseDto signup(SignupRequestDto request) {
Expand All @@ -87,10 +91,16 @@ public SignupResponseDto signup(SignupRequestDto request) {
getTermAndSaveTermMember(member, TermCode.TERMS_OF_PROMOTION, request.isTermsOfPromotion());

// save profile
Profile profile = Profile.createProfile(member, request.getNickname(), request.isGender(), request.getNation());
if (profileUtil.isDuplicatedNickname(request.getNickname())) {
throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME);
}

Profile profile = Profile.createProfile(member, request.getNickname(), request.isGender(),
request.getNation());
profileRepository.save(profile);

return SignupResponseDto.of(member.getId(), member.getName(), profile.getNickname());
// encrypt and return
return SignupResponseDto.of(aes.encrypt(member.getId().toString()), member.getName(), profile.getNickname());
}

@Transactional
Expand Down Expand Up @@ -182,7 +192,7 @@ public PermissionResponseDto sendAcceptanceMail(AcceptanceRequestDto acceptanceR

@Transactional
public PermissionResponseDto sendRejectionMail(RejectionRequestDto rejectionRequestDto) {
Long userId = rejectionRequestDto.getUserId();
Long userId = Long.parseLong(aes.decrypt(rejectionRequestDto.getUserId()));
Member member = memberService.findMemberByMemberId(userId);
if (member.getPermission() == Permission.DENY.getStatus())
throw new CustomException(ErrorCode.ALREADY_DENY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import kr.co.wingle.common.constants.ErrorCode;
import kr.co.wingle.common.exception.ForbiddenException;
import kr.co.wingle.common.exception.NotFoundException;
import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.member.MemberRepository;
import kr.co.wingle.member.dto.MemoRequestDto;
import kr.co.wingle.member.dto.MemoResponseDto;
Expand All @@ -27,6 +28,7 @@
public class MemberService {
private final MemberRepository memberRepository;
private final ProfileRepository profileRepository;
private final AES256Util aes;
private final int pageSize = 10;

@Transactional(readOnly = true)
Expand Down Expand Up @@ -71,14 +73,15 @@ public WaitingUserResponseDto getWaitingUserInfo(Long userId) {

@Transactional
public MemoResponseDto saveMemo(MemoRequestDto memoRequestDto) {
Member member = findMemberByMemberId(memoRequestDto.getUserId());

Member member = findMemberByMemberId(Long.parseLong(aes.decrypt(memoRequestDto.getUserId())));
member.setMemo(memoRequestDto.getMemo());
return MemoResponseDto.from(memoRequestDto.getMemo());
}

@Transactional
public RejectionResponseDto saveRejectionReason(RejectionRequestDto request) {
Member member = findMemberByMemberId(request.getUserId());
Member member = findMemberByMemberId(Long.parseLong(aes.decrypt(request.getUserId())));
member.setRejectionReason(request.getReason());
return RejectionResponseDto.from(request.getReason());
}
Expand Down
5 changes: 2 additions & 3 deletions wingle/src/main/java/kr/co/wingle/profile/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import kr.co.wingle.common.constants.ErrorCode;
import kr.co.wingle.common.exception.DuplicateException;
import kr.co.wingle.common.exception.NotFoundException;
import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.common.util.S3Util;
import kr.co.wingle.member.entity.Member;
import kr.co.wingle.member.service.AuthService;
Expand Down Expand Up @@ -46,7 +45,7 @@ public class ProfileService {
private final InterestRepository interestRepository;
private final SnsRepository snsRepository;
private final S3Util s3Util;
private final AES256Util aes;
private final ProfileUtil profileUtil;

@Transactional
public ProfileResponseDto saveProfile(ProfileRequestDto request) {
Expand All @@ -57,7 +56,7 @@ public ProfileResponseDto saveProfile(ProfileRequestDto request) {
Profile profile = getProfile(member);

if (!profile.getNickname().equals(request.getNickname()) &&
profileRepository.existsByNickname(request.getNickname())) {
profileUtil.isDuplicatedNickname(request.getNickname())) {
throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME);
}

Expand Down
23 changes: 23 additions & 0 deletions wingle/src/main/java/kr/co/wingle/profile/ProfileUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kr.co.wingle.profile;

import org.springframework.stereotype.Component;

import kr.co.wingle.common.constants.ErrorCode;
import kr.co.wingle.common.exception.DuplicateException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@Component
public class ProfileUtil {
private final ProfileRepository profileRepository;

public boolean isDuplicatedNickname(String newNickname) {
if (profileRepository.existsByNickname(newNickname)) {
throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME);
}

return false;
}
}