Merge branch 'main' of https://github.com/Parpaillax/Ludotheque
# Conflicts: # src/main/java/fr/eni/demo/controller/ClientController.java
This commit is contained in:
@@ -11,4 +11,5 @@ public interface ClientService {
|
||||
List<Client> findByName(String name);
|
||||
void fullUpdate(Long id, Client client, Adresse adresseDetails);
|
||||
void updateLocation(Long idClient, Adresse adresseDetails);
|
||||
void delete(Long idClient);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class ClientServiceImpl implements ClientService {
|
||||
return clients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fullUpdate(Long id, Client clientDetails, Adresse adresseDetails) {
|
||||
Client client = clientRepository.findById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Client non trouvé avec l'id " + id));
|
||||
@@ -82,6 +83,7 @@ public class ClientServiceImpl implements ClientService {
|
||||
clientRepository.save(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Long idClient, Adresse adresseDetails) {
|
||||
Client client = clientRepository.findById(idClient)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Client non trouvé avec l'id " + idClient));
|
||||
@@ -89,4 +91,12 @@ public class ClientServiceImpl implements ClientService {
|
||||
client.setAdresse(adresseDetails);
|
||||
clientRepository.save(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long idClient) {
|
||||
Client client = clientRepository.findById(idClient)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Client non trouvé avec l'id " + idClient));
|
||||
|
||||
clientRepository.delete(client);
|
||||
}
|
||||
}
|
||||
|
||||
40
src/main/java/fr/eni/demo/bll/JwtService.java
Normal file
40
src/main/java/fr/eni/demo/bll/JwtService.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package fr.eni.demo.bll;
|
||||
|
||||
import io.jsonwebtoken.JwtException;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.Key;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class JwtService {
|
||||
|
||||
private static final long EXPIRATION_TIME = 86400000; // 1j
|
||||
private final Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
|
||||
|
||||
public String generateToken(String username) {
|
||||
return Jwts.builder()
|
||||
.setSubject(username)
|
||||
.setIssuedAt(new Date())
|
||||
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
|
||||
.signWith(key)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public String extractUsername(String token) {
|
||||
return Jwts.parserBuilder().setSigningKey(key).build()
|
||||
.parseClaimsJws(token).getBody().getSubject();
|
||||
}
|
||||
|
||||
public boolean isTokenValid(String token) {
|
||||
try {
|
||||
Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token);
|
||||
return true;
|
||||
} catch (JwtException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user