Skip to content
Merged
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 @@ -4,6 +4,8 @@
import com.example.booktree.category.entity.Category;
import com.example.booktree.category.repository.CategoryRepository;
import com.example.booktree.comment.repository.CommentRepository;
import com.example.booktree.email.entity.EmailMessage;
import com.example.booktree.email.service.EmailService;
import com.example.booktree.exception.BusinessLogicException;
import com.example.booktree.exception.ExceptionCode;
import com.example.booktree.follow.repository.FollowRepository;
Expand Down Expand Up @@ -60,6 +62,7 @@ public class UserService {


private final PasswordEncoder passwordEncoder;
private final EmailService emailService;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmailService 의존성 주입이 잘 되었는지 확인해야 합니다. @Autowired 어노테이션을 사용했는지, @Service 로 선언된 EmailService Bean이 제대로 등록되었는지 확인해주세요.

private final TokenService tokenService;
private final ImageService imageService;
private static final String USER_IMAGE= DEFAULT_USER_IMAGE;
Expand Down Expand Up @@ -139,16 +142,19 @@ public User findUserByEmail(String email){

}

//임시 비밀번호 발급 - 이메일로 비밀번호
public String findPasswordByEmail(String email){

public void findPasswordByEmail(String email){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

임시 비밀번호 생성 로직(randomPassword)이 어디에도 보이지 않습니다. 임시 비밀번호 생성 부분을 추가하고, 보안 강화를 위해 충분한 길이와 복잡성을 갖도록 해야 합니다. 또한, 생성된 임시 비밀번호를 데이터베이스에 저장하거나, 사용자에게 전달하는 추가적인 로직이 필요할 수 있습니다. 비밀번호 변경을 위한 링크를 이메일로 보내는 것을 고려하는 것이 더 안전할 수 있습니다.

EmailMessage emailMessage = EmailMessage.builder()
.to(email)
.subject("[BookTree] 임시 비밀번호 발급")
.build();
User user = findUserByEmail(email);
String randomPassword = CreateRandomNumber.randomNumber();
user.setPassword(passwordEncoder.encode(randomPassword));
userRepository.save(user);
return randomPassword;
}

emailService.sendMail(emailMessage, "password",randomPassword);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이메일 전송에 사용되는 password라는 템플릿 이름이 적절한지 확인해야 합니다. 템플릿 이름을 더 명확하게 변경하는 것이 좋습니다. 예를 들어, password_reset 과 같이 좀 더 구체적인 이름을 사용하는 것이 좋습니다. 또한, emailService.sendMail 메서드의 에러 핸들링이 필요합니다. 이메일 전송 실패 시 적절한 예외 처리를 추가해야 합니다.


}
//임시 비밀번호 발급 - 이메일, 핸드폰으로 비밀번호
public String findPasswordByEmailAndPhone(UserPasswordRequestDto.FindPwByEmailAndPhone findPwByEmailAndPhone){

Expand Down
31 changes: 28 additions & 3 deletions frontend/src/app/components/CommentsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,35 @@ export function CommentsSection({ postId }: { postId: number }) {
}, [activeCommentId, activeReplyPopoverId])

// ─── 프로필 이미지 불러오기 ────────────────────────────────────
// useEffect(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석 처리된 코드는 필요없는 코드인가요? 필요하다면 주석을 제거하고, 코드 스타일과 가독성을 개선하여 useEffect 훅 내부의 비동기 처리 부분을 더 명확하게 작성해야 합니다. fetch 호출의 에러 핸들링을 추가하고, 불필요한 try...catch 블록을 제거하여 코드를 간결하게 만들어야 합니다. userImages 상태 업데이트 로직을 더 효율적으로 작성할 수 있는 방법을 고려해야 합니다.

// if (!comments.length) return
// const ids = Array.from(
// new Set([...comments.map((c) => c.userId), ...comments.flatMap((c) => c.replies.map((r) => r.userId))]),
// )
// async function fetchUserImages() {
// const map: Record<number, string> = {}
// await Promise.all(
// ids.map(async (id) => {
// try {
// const res = await fetch(`${API}/api/v1/users/get/profile/${id}`)
// if (!res.ok) return
// const { imageUrl } = await res.json()
// map[id] = imageUrl
// } catch {}
// }),
// )
// setUserImages(map)
// }
// fetchUserImages()
// }, [comments])

useEffect(() => {
if (!comments.length) return
if (!rawComments.length) return
const ids = Array.from(
new Set([...comments.map((c) => c.userId), ...comments.flatMap((c) => c.replies.map((r) => r.userId))]),
new Set([
...rawComments.map((c) => c.userId),
...rawComments.flatMap((c) => c.replies.map((r) => r.userId)),
]),
)
async function fetchUserImages() {
const map: Record<number, string> = {}
Expand All @@ -354,7 +379,7 @@ export function CommentsSection({ postId }: { postId: number }) {
setUserImages(map)
}
fetchUserImages()
}, [comments])
}, [rawComments])

// ─── 렌더링 ────────────────────────────────────────────────────
return (
Expand Down
Loading