diff --git a/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java b/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java index de1686a..4610e1d 100644 --- a/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java +++ b/backend/src/main/java/com/ssafy/home/domain/member/controller/MemberController.java @@ -50,6 +50,10 @@ public ResponseEntity login(@RequestBody LoginRequest loginRequest, Http TokenResponse tokenResponse = memberService.login(loginRequest.getEmail(), loginRequest.getPassword()); + if(tokenResponse == null){ + throw new AuthenticationException(ErrorCode.MEMBER_NOT_MATCH); + } + response.addHeader(JwtTokenProvider.AUTHORIZATION_HEADER, tokenResponse.getAccessToken()); Cookie cookie = new Cookie("refreshToken", tokenResponse.getRefreshToken()); diff --git a/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java b/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java index 680f619..2bb644a 100644 --- a/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java +++ b/backend/src/main/java/com/ssafy/home/domain/member/service/MemberService.java @@ -26,6 +26,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; +import java.util.List; + @Service @RequiredArgsConstructor @Slf4j @@ -103,7 +106,7 @@ public TokenResponse login(String email, String password) { } catch (AuthenticationException e){ member.getLoginAttempt().updateCount(); - throw new AuthenticationException(ErrorCode.MEMBER_NOT_MATCH); + e.printStackTrace(); } catch (Exception e) { member.getLoginAttempt().updateCount(); e.printStackTrace(); @@ -183,9 +186,13 @@ public void sendPassword(String email) { } @Transactional - public void initAttempt(){ - loginAttemptRepository.findAll().stream() + public void initAttempt() { + LocalDateTime thirtyMinutesAgo = LocalDateTime.now().minusMinutes(30); + List staleAttempts = loginAttemptRepository.findAll().stream() .filter(loginAttempt -> loginAttempt.getCount() >= 5) - .forEach(LoginAttempt::initCount); + .filter(loginAttempt -> loginAttempt.getLoginRecentAttemp().isBefore(thirtyMinutesAgo)) + .toList(); + + staleAttempts.forEach(LoginAttempt::initCount); } } diff --git a/backend/src/main/java/com/ssafy/home/entity/member/LoginAttempt.java b/backend/src/main/java/com/ssafy/home/entity/member/LoginAttempt.java index 25dd89f..10ccde1 100644 --- a/backend/src/main/java/com/ssafy/home/entity/member/LoginAttempt.java +++ b/backend/src/main/java/com/ssafy/home/entity/member/LoginAttempt.java @@ -8,7 +8,7 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import java.time.LocalDate; +import java.time.LocalDateTime; @Entity @NoArgsConstructor @@ -27,7 +27,7 @@ public class LoginAttempt { @LastModifiedDate @Column(name = "login_recent_attemp", columnDefinition = "datetime default CURRENT_TIMESTAMP") - private LocalDate loginRecentAttemp; + private LocalDateTime loginRecentAttemp; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") @@ -39,7 +39,7 @@ public LoginAttempt(Member member) { } public void updateCount(){ - this.count++; + this.count = this.count + 1; } public void initCount(){ diff --git a/backend/src/main/java/com/ssafy/home/entity/member/Member.java b/backend/src/main/java/com/ssafy/home/entity/member/Member.java index a6131e4..30f0889 100644 --- a/backend/src/main/java/com/ssafy/home/entity/member/Member.java +++ b/backend/src/main/java/com/ssafy/home/entity/member/Member.java @@ -10,6 +10,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; @NoArgsConstructor @@ -41,7 +42,7 @@ public class Member { @LastModifiedDate @Column(name = "modify_date", columnDefinition = "datetime default CURRENT_TIMESTAMP") - private LocalDate modifyDate; + private LocalDateTime modifyDate; @Column(name = "is_deleted") @ColumnDefault("false") diff --git a/backend/src/main/java/com/ssafy/home/global/config/batch/ScheduledJobConfiguration.java b/backend/src/main/java/com/ssafy/home/global/config/batch/ScheduledJobConfiguration.java index 5d4627e..4003747 100644 --- a/backend/src/main/java/com/ssafy/home/global/config/batch/ScheduledJobConfiguration.java +++ b/backend/src/main/java/com/ssafy/home/global/config/batch/ScheduledJobConfiguration.java @@ -12,7 +12,7 @@ public class ScheduledJobConfiguration { private final MemberService memberService; - @Scheduled(cron ="0 30 * * * *", zone = "Asia/Seoul") + @Scheduled(cron ="0 * * * * *", zone = "Asia/Seoul") public void scheduledEndForm() { memberService.initAttempt(); } diff --git a/backend/src/main/java/com/ssafy/home/global/entity/BaseTimeEntity.java b/backend/src/main/java/com/ssafy/home/global/entity/BaseTimeEntity.java index 37c7ac0..894a5a6 100644 --- a/backend/src/main/java/com/ssafy/home/global/entity/BaseTimeEntity.java +++ b/backend/src/main/java/com/ssafy/home/global/entity/BaseTimeEntity.java @@ -2,12 +2,13 @@ import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; -import java.time.LocalDateTime; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.time.LocalDateTime; + @Getter @EntityListeners(AuditingEntityListener.class) @MappedSuperclass diff --git a/backend/src/main/java/com/ssafy/home/global/error/ErrorCode.java b/backend/src/main/java/com/ssafy/home/global/error/ErrorCode.java index 940f442..8fcd18f 100644 --- a/backend/src/main/java/com/ssafy/home/global/error/ErrorCode.java +++ b/backend/src/main/java/com/ssafy/home/global/error/ErrorCode.java @@ -23,7 +23,7 @@ public enum ErrorCode { INVALID_MEMBER_TYPE(HttpStatus.BAD_REQUEST, "M-001", "잘못된 회원 타입 입니다.(memberType : KAKAO)"), ALREADY_REGISTERED_MEMBER(HttpStatus.BAD_REQUEST, "M-002", "이미 가입된 회원 입니다."), MEMBER_NOT_EXISTS(HttpStatus.BAD_REQUEST, "M-003", "해당 회원은 존재하지 않습니다."), - MEMBER_COUNT_OUT(HttpStatus.BAD_REQUEST, "M-004", "해당 회원 로그인 시도 횟수가 초과되었습니다. (비밀번호 변경이 필요합니다.)"), + MEMBER_COUNT_OUT(HttpStatus.BAD_REQUEST, "M-004", "해당 회원 로그인 시도 횟수가 초과되었습니다. 30분 후 다시 시도하세요!"), MEMBER_NOT_MATCH(HttpStatus.BAD_REQUEST, "M-005", " 아이디(로그인 전용 아이디) 또는 비밀번호를 잘못 입력했습니다.\n" + "입력하신 내용을 다시 확인해주세요."),