Compare commits
2 Commits
d8a6d06b7a
...
dcf5b26b05
Author | SHA1 | Date | |
---|---|---|---|
dcf5b26b05 | |||
94d86ef252 |
@ -54,30 +54,10 @@ public class MockController {
|
|||||||
userRepo.saveAll(mockUsers);
|
userRepo.saveAll(mockUsers);
|
||||||
|
|
||||||
for (User user: 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()));
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@DeleteMapping("/mock")
|
@DeleteMapping("/mock")
|
||||||
public void deleteMock(){
|
public void deleteMock(){
|
||||||
for (User user:mockUsers){
|
for (User user:mockUsers){
|
||||||
|
@ -14,7 +14,6 @@ import java.util.Date;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TokenService {
|
public class TokenService {
|
||||||
|
|
||||||
TokenRepository tokenRepo;
|
TokenRepository tokenRepo;
|
||||||
|
|
||||||
public TokenService(TokenRepository tokenRepo){
|
public TokenService(TokenRepository tokenRepo){
|
||||||
@ -54,11 +53,11 @@ public class TokenService {
|
|||||||
public void autoDeleteToken() {
|
public void autoDeleteToken() {
|
||||||
for (Token t: tokenRepo.findAll()){
|
for (Token t: tokenRepo.findAll()){
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(new Date());
|
|
||||||
|
|
||||||
Calendar cal2 = Calendar.getInstance();
|
Calendar cal2 = Calendar.getInstance();
|
||||||
cal2.setTime(t.getExpirationDate());
|
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);
|
tokenRepo.delete(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user