- Implémentation de la limite de 5 tokens par utilisateurs
This commit is contained in:
parent
a297641fa9
commit
54c0f9069e
@ -67,6 +67,17 @@ public class MockController {
|
||||
}
|
||||
}
|
||||
|
||||
//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")
|
||||
public void deleteMock(){
|
||||
for (User user:mockUsers){
|
||||
|
@ -4,9 +4,13 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Token;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface TokenRepository extends CrudRepository<Token,Long> {
|
||||
|
||||
Token getByToken(String token);
|
||||
|
||||
Iterable<Token> getByUser(User user);
|
||||
|
||||
ArrayList <Token> getByUserOrderByExpirationDate(User user);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@ -34,6 +35,11 @@ public class TokenService {
|
||||
}
|
||||
|
||||
public void saveToken(Token token){
|
||||
//Si l'utilisateur a déja 5 token delete celui qui devait expirer le plus vite
|
||||
ArrayList<Token> tokenList = tokenRepo.getByUserOrderByExpirationDate(token.getUser());
|
||||
if (tokenList.size() == 5){
|
||||
tokenRepo.delete(tokenList.get(0));
|
||||
}
|
||||
tokenRepo.save(token);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user