Search

feat: [안성희] 수정된 비밀번호로 저장 [BYL-BACK-PROCESS-37]

작성날짜
2024/06/10 01:45
작업타입
Task 🔨
작업상태
Complete 🙌
우선순위
P1 🔥
Issue
마지막 백로그 넘버
37
작성자

Success criteria

1.

To-do

Review

Issue

@Override @Transactional public Boolean registerModifiedPassword(ModifiedPassword modifiedPassword) { Long memberId = modifiedPassword.getId(); Optional<Member> maybeMember = memberRepository.findById(memberId); Optional<Authentication> maybeauthentication = authenticationRepository.findById(memberId); if(maybeMember.isEmpty() && maybeauthentication.isEmpty()) { return false; } else { final Member member = maybeMember.get(); memberRepository.save(member); final BasicAuthentication authentication = new BasicAuthentication( member, Authentication.BASIC_AUTH, modifiedPassword.getPassword() ); authenticationRepository.save(authentication); } return true; }
Java
복사
이딴식으로 쓰면 Authentication이 Member와 OneToMany 관계라서 비밀번호가 두개 생기고 두 비밀번호 모두 가입이 가능한 상태가 됩니다. 왜 OneToMany인지 예전에 찾아봤던 기억이 있는데 회원가입을 저희가 만든 코드로 하면 Basic으로 들어가고 특정 사이트 (구글, 카카오)로 가입을 하면 Google, KaKao로 등록할 예정이여서 이렇게 하셨다고 합니다.
@Override @Transactional public Boolean registerModifiedPassword(ModifiedPassword modifiedPassword) { Long memberId = modifiedPassword.getId(); // Optional<Member> maybeMember = memberRepository.findById(memberId); Optional<Authentication> maybeauthentication = authenticationRepository.findById(memberId); // if(maybeMember.isEmpty() || maybeauthentication.isEmpty()) { if(maybeauthentication.isEmpty()) { return false; } else { // final Member member = maybeMember.get(); final BasicAuthentication authentication = (BasicAuthentication) maybeauthentication.get(); String encryptedPassword = new PasswordHashConverter().convertToDatabaseColumn(modifiedPassword.getPassword()); authentication.setPassword(encryptedPassword); authenticationRepository.save(authentication); } return true; }
Java
복사
그래서 생성자를 만들지 않고 (BasicAuthentication) maybeauthentication.get();