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

비밀글 기능 구현 #37

Closed
eheh12321 opened this issue Oct 28, 2022 · 2 comments · Fixed by #38
Closed

비밀글 기능 구현 #37

eheh12321 opened this issue Oct 28, 2022 · 2 comments · Fixed by #38
Assignees
Labels
enhancement New feature or request

Comments

@eheh12321
Copy link
Owner

eheh12321 commented Oct 28, 2022

게시글에 비밀번호를 걸어 비밀글을 설정할 수 있는 기능을 만들어본다

@eheh12321 eheh12321 self-assigned this Oct 28, 2022
@eheh12321 eheh12321 changed the title 비밀글 / 게시글 삭제 비밀번호 기능 구현 비밀글 기능 구현 Oct 28, 2022
@eheh12321
Copy link
Owner Author

Board 엔티티에 비밀번호 넣고 대충 비교하면 되겠지 싶었는데 생각보다 아주 큰 작업이 되고있다..

  • 일단 게시글 조회 시 비밀번호를 입력받기 위해 비밀번호 입력 페이지로 포워드 시키는 작업
  • 비밀번호가 맞으면 세션에다가 해당 게시글의 비밀번호를 담아놓는다 (??)
    (맨 처음에 flashmap 써서 일회성으로만 넘기게 하려 했는데 그렇게 하니까 댓글만 달면 다시 비밀번호를 입력해야해서 세션에다가 저장해놓는게 맞는 것 같음)
  • 이 세션을 받아서 서비스 계층에서 비밀번호 재확인 이후 게시글 정보 반환
  • 브라우저가 종료되면 세션 정보도 다 같이 날리고 싶은데 가능한지 모르겠음

eheh12321 added a commit that referenced this issue Oct 29, 2022
- password 컬럼의 null 유무로 비밀글 유무 확인하게끔 만들 예정
- 비밀글 유무 체크박스를 체크한 경우에만 비밀번호를 저장하도록 함
- getSecret 메서드를 따로 만든 이유는 html form에서 체크박스 체크를 하지 않았다면 null, 값을 아예 보내지 않기 때문에 기본값으로 false를 설정하기 위함.
eheh12321 added a commit that referenced this issue Oct 29, 2022
- 스프링 시큐리티가 지원하는 BCryptEncoder를 그대로 가져와서 사용!
- 비즈니스 로직이 Mapper 안으로 들어가는 것 같은데 괜찮은 방법인건지 모르겠다.
eheh12321 added a commit that referenced this issue Oct 29, 2022
- ResponseDTO 였던 것을 뒤에 이름 깔끔하게 뗌
- Board 엔티티에 password 컬럼이 null 아니면 비밀글으로 간주함
- 부트스트랩 아이콘 추가해서 비밀글의 경우 자물쇠 아이콘이 옆에 붙도록 개선

* https://icons.getbootstrap.com/
eheh12321 added a commit that referenced this issue Oct 29, 2022
- 필드 에러(BindException)를 만들기 위해 Validator 이용
- 검증에 통과한 경우 세션에 "secret_board_[게시글ID]" 이름으로 게시글 비밀번호를 담는다.
- Validator를 @InitBinder를 통해 등록해두면 모든 DTO 변환 시에 validator의 supports() 메서드를 통해 검증 시 사용할 수 있는지를 확인하는 절차를 거치게 된다
-> supports()가 false이면 그냥 검증기 사용을 안하는 줄 알았는데 의외로 "Invalid target for Validator" 에러가 발생한다
--> 해당 검증기는 boardPasswordDto 매핑에 대해서만 사용하도록 @InitBinder에 설정을 추가하면 된다!!

* https://www.inflearn.com/questions/280541
eheh12321 added a commit that referenced this issue Oct 29, 2022
- 해당 게시글이 비밀글인 경우 비밀번호 입력 페이지로 포워드
- 세션에 저장해뒀기 때문에 세선이 사라지기 전 까지 한번 비밀글을 열면 나중에 다시 비밀번호 입력하지 않아도 조회 가능
- 세션에 대한 활용을 이렇게 해도 되는지 사실 좀 더 찾아봐야 할 것 같음

(사실 세션에 대해 잘 모르고 썼는데 세션의 삭제 시점이라던가 조금 더 공부해보기)
eheh12321 added a commit that referenced this issue Oct 29, 2022
1. 해당 게시글이 비밀글인지를 확인하는 메서드
2. 입력한 비밀번호가 해당 게시글의 비밀번호와 일치하는지를 확인하는 메서드
3. 게시글 조회 시 비밀글인 경우 비밀번호 일치하지 않을 경우 예외 터트림

비밀번호 검증을 중복해서 하는 부분이 없지않아 있긴 한 것 같다.
eheh12321 added a commit that referenced this issue Oct 29, 2022
- 비밀번호 암호화가 잘 되는지는 테스트 하지 않음.
- DTO 변경내용 적용
- 테스트 실패한 채로 브랜치 머지 하니까 빌드 실패가 떠서.. 클라우드에 반영이 안됨. 이런 경우에는 어떻게 할지??
@eheh12321
Copy link
Owner Author

지금 가만보니까 게시글 작성자는 비밀번호 없이 비밀글 바로 볼 수 있도록 하는 기능이 더 있었으면 좋겠다!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant