Merge branch 'dev' into Romain
This commit is contained in:
commit
da37363a39
|
@ -27,7 +27,7 @@ import fr.cardon.simpleat.repository.RoleRepository;
|
||||||
import fr.cardon.simpleat.service.PersonneService;
|
import fr.cardon.simpleat.service.PersonneService;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin("*")
|
@CrossOrigin("http://localhost:4200")
|
||||||
public class PersonneController {
|
public class PersonneController {
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class PersonneController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/sign-up")
|
@PostMapping("/signup")
|
||||||
public ResponseEntity<JsonWebToken> signUp(@RequestBody Personne personne) {
|
public ResponseEntity<JsonWebToken> signUp(@RequestBody Personne personne) {
|
||||||
try {
|
try {
|
||||||
return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne)));
|
return ResponseEntity.ok(new JsonWebToken(personneService.signup(personne)));
|
||||||
|
|
|
@ -49,8 +49,17 @@ public class PreferenceController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/add-preference")
|
// @PostMapping("/add-preference")
|
||||||
public ResponseEntity<?> ajoutPreference(@RequestBody Preference 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));
|
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));
|
// 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 ){
|
public void deletePreferenceById(@PathVariable int iduser, @PathVariable int idrestau ){
|
||||||
PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau));
|
PreferencePK id = new PreferencePK(personneRepository.getById(iduser) ,restaurantRepository.getById(idrestau));
|
||||||
preferenceRepository.deleteById(id);
|
preferenceRepository.deleteById(id);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class RestaurantController {
|
||||||
|
|
||||||
|
|
||||||
@PutMapping(value = "/update-restaurant/{id}")
|
@PutMapping(value = "/update-restaurant/{id}")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
public ResponseEntity<?> modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){
|
public ResponseEntity<?> modifRestaurant(@PathVariable int id, @RequestBody Restaurant personne){
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne));
|
return ResponseEntity.status(HttpStatus.OK).body(restaurantRepository.save(personne));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,13 @@ public class Preference {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Preference(PreferencePK preferencePK) {
|
||||||
|
super();
|
||||||
|
this.preferencePK = preferencePK;
|
||||||
|
}
|
||||||
|
|
||||||
public Preference(PreferencePK preferencePK, int note, boolean favoris) {
|
public Preference(PreferencePK preferencePK, int note, boolean favoris) {
|
||||||
super();
|
super();
|
||||||
this.preferencePK = preferencePK;
|
this.preferencePK = preferencePK;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.PrimaryKeyJoinColumn;
|
import javax.persistence.PrimaryKeyJoinColumn;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ public class PreferencePK implements Serializable {
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" )
|
@PrimaryKeyJoinColumn(name="id_personne", referencedColumnName ="id_personne" )
|
||||||
@JsonIgnore
|
@JsonBackReference("personne")
|
||||||
public Personne getPersonne() {
|
public Personne getPersonne() {
|
||||||
return personne;
|
return personne;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
|
||||||
import fr.cardon.simpleat.exception.InvalidJWTException;
|
import fr.cardon.simpleat.exception.InvalidJWTException;
|
||||||
import fr.cardon.simpleat.model.EnumRole;
|
import fr.cardon.simpleat.model.EnumRole;
|
||||||
|
import fr.cardon.simpleat.repository.PersonneRepository;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import io.jsonwebtoken.JwtException;
|
import io.jsonwebtoken.JwtException;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
|
@ -44,6 +45,9 @@ public class JwtTokenProvider {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserDetailsService userDetailsService;
|
private UserDetailsService userDetailsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PersonneRepository personneRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cette méthode d'initialisation s'exécute avant le constructeur
|
* Cette méthode d'initialisation s'exécute avant le constructeur
|
||||||
* Elle encode notre code secret en base64 pour la transmission dans le header
|
* Elle encode notre code secret en base64 pour la transmission dans le header
|
||||||
|
@ -104,6 +108,7 @@ public class JwtTokenProvider {
|
||||||
public String createToken(String email, List<EnumRole> roleList){
|
public String createToken(String email, List<EnumRole> roleList){
|
||||||
|
|
||||||
Claims claims = Jwts.claims().setSubject(email);
|
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()));
|
claims.put("auth", roleList.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||||
|
|
||||||
System.out.println("claims = "+claims);
|
System.out.println("claims = "+claims);
|
||||||
|
|
|
@ -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 ('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', 'YY0TuY6JH0di');
|
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', 'C4sfAW4');
|
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', 'ACdXxMr');
|
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', 'pjKxIN');
|
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', 'YY0TuY6JH0di');
|
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', 'C4sfAW4');
|
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', 'ACdXxMr');
|
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', 'pjKxIN');
|
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', 'YY0TuY6JH0di');
|
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', 'C4sfAW4');
|
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', 'ACdXxMr');
|
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', 'pjKxIN');
|
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', 'YY0TuY6JH0di');
|
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 (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 (1, 'Admin');
|
||||||
insert into role (id_role, intitule) values (2, 'User');
|
insert into role (id_role, intitule) values (2, 'User');
|
||||||
|
|
Loading…
Reference in New Issue