diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 9f9dcc0..89e9ada 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -53,31 +53,14 @@ public class MockController { userRepo.saveAll(mockUsers); - for (User user: mockUsers){ - //Petit test pour ĂȘtre sur de delete les bons tokens - if (user.getLastName().equals("brine")){ - Calendar c = Calendar.getInstance(); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_WEEK, 1); - tokenService.saveToken(new Token(user,user.getPassword(), c.getTime())); - }else{ - tokenService.saveToken(new Token(user,user.getPassword(), new Date())); - } - - } - } - - //Nous allons donner des tokens a herobrine pour tester la limite de token - @PostMapping("/herobrine") - public void giveHerobrineTokens(){ - User herobrine = userRepo.findById(1); Calendar c = Calendar.getInstance(); - for (int i = 1; i <= 7; i++){ - Token t = new Token(herobrine, herobrine.getPassword(), c.getTime()); - c.add(Calendar.DAY_OF_YEAR, 1); - tokenService.saveToken(t); + c.setTime(new Date()); + + for (User user: mockUsers){ + tokenService.saveToken(new Token(user,user.getPassword(), new Date())); } } + @DeleteMapping("/mock") public void deleteMock(){ for (User user:mockUsers){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java index 7134508..029661d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/TokenService.java @@ -14,7 +14,6 @@ import java.util.Date; @Service public class TokenService { - TokenRepository tokenRepo; public TokenService(TokenRepository tokenRepo){ @@ -52,13 +51,14 @@ public class TokenService { //Tous les jours a minuit @Scheduled(cron = "0 0 0 * * ?") public void autoDeleteToken() { + System.out.println("triggered"); for (Token t: tokenRepo.findAll()){ Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); Calendar cal2 = Calendar.getInstance(); cal2.setTime(t.getExpirationDate()); - if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)){ + + if (cal.compareTo(cal2) >= 0){ tokenRepo.delete(t); } }