Merge branch 'dev' into Romain

This commit is contained in:
Romain Verger 2022-03-09 14:12:28 +01:00
commit da37363a39
7 changed files with 61 additions and 21 deletions

View File

@ -27,7 +27,7 @@ import fr.cardon.simpleat.repository.RoleRepository;
import fr.cardon.simpleat.service.PersonneService;
@RestController
@CrossOrigin("*")
@CrossOrigin("http://localhost:4200")
public class PersonneController {
@ -125,7 +125,7 @@ public class PersonneController {
}
}
@PostMapping("/sign-up")
@PostMapping("/signup")
public ResponseEntity<JsonWebToken> signUp(@RequestBody Personne personne) {
try {
return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne)));

View File

@ -49,8 +49,17 @@ public class PreferenceController {
}
@PostMapping("/add-preference")
public ResponseEntity<?> ajoutPreference(@RequestBody Preference preference){
// @PostMapping("/add-preference")
// public ResponseEntity<?> ajoutPreference(@RequestBody Preference preference){
// System.out.println(preference);
// return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(preference));
// }
@PostMapping("/add-preference/{iduser}/{idrestau}")
public ResponseEntity<?> ajoutPreference(@PathVariable int iduser, @PathVariable int idrestau ){
System.out.println("hello");
Preference preference = new Preference(new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau)));
return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(preference));
}
@ -60,7 +69,7 @@ public class PreferenceController {
// return ResponseEntity.status(HttpStatus.OK).body(preferenceRepository.save(personne));
// }
//
@DeleteMapping("/delete-preference/{idrestau}/{iduser}")
@DeleteMapping("/delete-preference/{iduser}/{idrestau}")
public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){
PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau));
preferenceRepository.deleteById(id);

View File

@ -44,7 +44,7 @@ public class RestaurantController {
@PutMapping(value = "/update-restaurant/{id}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<?> modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){
return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne));
}

View File

@ -19,6 +19,13 @@ public class Preference {
}
public Preference(PreferencePK preferencePK) {
super();
this.preferencePK = preferencePK;
}
public Preference(PreferencePK preferencePK, int note, boolean favoris) {
super();
this.preferencePK = preferencePK;

View File

@ -10,6 +10,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -40,7 +41,7 @@ public class PreferencePK implements Serializable {
@ManyToOne
@PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" )
@JsonIgnore
@JsonBackReference("personne")
public Personne getPersonne() {
return personne;
}

View File

@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import fr.cardon.simpleat.exception.InvalidJWTException;
import fr.cardon.simpleat.model.EnumRole;
import fr.cardon.simpleat.repository.PersonneRepository;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
@ -43,6 +44,9 @@ public class JwtTokenProvider {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private PersonneRepository personneRepository;
/**
* Cette méthode d'initialisation s'exécute avant le constructeur
@ -104,6 +108,7 @@ public class JwtTokenProvider {
public String createToken(String email, List<EnumRole> roleList){
Claims claims = Jwts.claims().setSubject(email);
claims.put("userId", personneRepository.findByEmail(email).get().getId());
claims.put("auth", roleList.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
System.out.println("claims = "+claims);

View File

@ -1,19 +1,37 @@
insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', 'pjKxIN');
insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', 'YY0TuY6JH0di');
insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', 'C4sfAW4');
insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', 'ACdXxMr');
insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', 'pjKxIN');
insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', 'YY0TuY6JH0di');
insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', 'C4sfAW4');
insert into personne (nom, prenom, email, password) values ('El hiri', 'Sana', 'sana.el-hiri@gmail.com', 'ACdXxMr');
insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', 'pjKxIN');
insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', 'YY0TuY6JH0di');
insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', 'C4sfAW4');
insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', 'ACdXxMr');
insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', 'pjKxIN');
insert into personne (nom, prenom, email, password) values ('MJID', 'Hedi', 'hedi.mjid@gmail.com', 'YY0TuY6JH0di');
insert into personne (nom, prenom, email, password) values ('Cardon', 'Thomas', 'thomas.cardon@gmail.com', '$2a$10$724bLjLyGOEKTBbHy.s3C.ETc.HuBnhEoCOuoO7.Ts7kyPbz6hkme');
insert into personne (nom, prenom, email, password) values ('Ramiere', 'Vincent', 'vincent.ramiere@gmail.com', '$2a$10$x6.VyO9PCMXSPsi5/m/Hze9xOP.IUdYbaye7cNFc.PfyuRuVLbG7e');
insert into personne (nom, prenom, email, password) values ('Verger', 'Romain', 'romain.verger@gmail.com', '$2a$10$oe/h0ZDpi6xFmTj8CvDMDe13hoEGv0DhHziY7GUatbb9ETcRw/8RG');
insert into personne (nom, prenom, email, password) values ('Ribardiere', 'Paul-Emmanuel', 'paul.ribardiere@gmail.com', '$2a$10$ArSe7TSUapTs9oGE8824fOv4PM6NJwu7mzcg72cSmHy0.ds585Oke');
insert into personne (nom, prenom, email, password) values ('Noris', 'William', 'william.noris@gmail.com', '$2a$10$6UbvPYBR2Ql09M1kgK0.HuoX3X1gxScmaOxI242EB2U7cXiylX3z.');
insert into personne (nom, prenom, email, password) values ('Harmand', 'Isabelle', 'isabelle.harmand@gmail.com', '$2a$10$at1EZABxNN32M5pCttV36OvzbUWx1myGisa36i3..vveO6j0Lk2Da');
insert into personne (nom, prenom, email, password) values ('Bajard', 'Blandine', 'blandine.bajard@gmail.com', '$2a$10$koeHn0Wg54MTc7iDb9hbsujy/Opfrhhu0uuhhBNA00rMXLeMpSl.m');
insert into personne (nom, prenom, email, password) values ('El Hiri', 'Sana', 'sana.el-hiri@gmail.com', '$2a$10$jBBk1RQrl5XOeSQYz3xdJ.Xl8hBIu/x3mqHpYyL10m6KjwfDsWGEW');
insert into personne (nom, prenom, email, password) values ('Lucas', 'Cecile', 'cecile.lucas@gmail.com', '$2a$10$HAUg8vlmtvS/YphJzWAPfuGJdLd/3SeSZ48JVvybK6Wh/AY3QirGG');
insert into personne (nom, prenom, email, password) values ('Kerkeb', 'Mohamed', 'mohamed.kerkeb@gmail.com', '$2a$10$BpWZMlDLKXA2qGMo9t6cxeS6G/6mvjdsdN4nIUOAjE2sr/0sJNiCW');
insert into personne (nom, prenom, email, password) values ('Rinquin', 'Aline', 'aline.rinquin@gmail.com', '$2a$10$FJKDTcipj/8PKos7AcCnZ.HHAmdDh6EjknpUWPLDcVfSXWPcHZI5O');
insert into personne (nom, prenom, email, password) values ('Keddar', 'Noreddine', 'noredinne.keddar@gmail.com', '$2a$10$5iowOIUv72hFVsT9B8K.nerA3YTPAyyUiqOAwKR55ZZcpiHT96LhG');
insert into personne (nom, prenom, email, password) values ('Tomczyk', 'Julian', 'julian.tomczyk@gmail.com', '$2a$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.');
insert into personne (nom, prenom, email, password) values ('Mjid', 'Hedi', 'hedi.mjid@gmail.com', '$10$vJ89S5CXjtO01NsYrwfLyudU/p2Cz1QNDm1dGUkfKD60Z23HLZM2.');
insert into personne (nom, prenom, email, password) values ('BIDEN', 'Joe', 'joe@biden.fr', '$2a$10$NNfAnATNZf/MzIjrUFi5K.xqWizxv1Hil4/PyRAabKWK5DxsLPE6.');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (1,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (2,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (3,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (4,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (5,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (6,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (7,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (8,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (9,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (10,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (11,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (12,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (13,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (14,'ROLE_READER');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_ADMIN');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_CREATOR');
INSERT INTO `personne_role_list` (`personne_id_personne`,`role_list`) VALUES (15,'ROLE_READER');
insert into role (id_role, intitule) values (1, 'Admin');
insert into role (id_role, intitule) values (2, 'User');