This commit is contained in:
AlineRinquin 2022-01-20 09:37:47 +01:00
commit 796070b73c
25 changed files with 1006 additions and 168 deletions

View File

@ -26,6 +26,15 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId> <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

View File

@ -1,13 +1,47 @@
package fr.organizee; package fr.organizee;
import fr.organizee.model.Membre;
import fr.organizee.model.Role;
import fr.organizee.service.MembreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.util.ArrayList;
import java.util.Arrays;
@SpringBootApplication @SpringBootApplication
public class OrganizeeApplication { public class OrganizeeApplication implements CommandLineRunner {
@Autowired
private MembreService membreService;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(OrganizeeApplication.class, args); SpringApplication.run(OrganizeeApplication.class, args);
} }
/**
* Ceci est un Bean, un composant
* Méthode de Hachage
* Bcrypt est un algorithme de hachage considé comme le plus sûr.
* bcrypt est un algorithme de hashage unidirectionnel,
* vous ne pourrez jamais retrouver le mot de passe sans connaitre à la fois le grain de sel,
* la clé et les différentes passes que l'algorithme à utiliser.
* Voir le <a href="https://bcrypt-generator.com/"> site pour effectuer un test</a>
*
* @return
*/
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
public void run(String... args) throws Exception {
}
} }

View File

@ -0,0 +1,93 @@
package fr.organizee.controller;
import fr.organizee.model.Contact;
import fr.organizee.model.Membre;
import fr.organizee.model.Team;
import fr.organizee.repository.ContactRepository;
import fr.organizee.repository.TeamRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException;
import java.util.List;
import java.util.Optional;
@RestController
@CrossOrigin("*")
@RequestMapping("/contacts")
public class ContactController {
@Autowired
private ContactRepository contactRepo;
@GetMapping(value = "/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findById(@PathVariable int id){
Optional<Contact> contact = null;
try
{
contact = contactRepo.findById(id);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(contact);
}
@GetMapping(value = "team/{team_id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
List<Contact> contacts = null;
try
{
contacts = contactRepo.FindContactsByTeam(team_id);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(contacts);
}
@PostMapping(value="/add")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> addContact(@RequestBody Contact contact){
Contact resultContact = null;
try {
resultContact = contactRepo.saveAndFlush(contact);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultContact);
}
@PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> updateContact(@RequestBody Contact contact, @PathVariable Integer id) throws Exception {
Contact resultContact = null;
try {
resultContact = contactRepo.save(contact);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.OK).body(resultContact);
}
@DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteContact(@PathVariable int id){
try {
contactRepo.delete(contactRepo.getById(id));
return ResponseEntity.status(HttpStatus.OK).body("Contact effacé !");
} catch (EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.OK).body("Contact introuvable !");
}
}
}

View File

@ -1,17 +1,24 @@
package fr.organizee.controller; package fr.organizee.controller;
import fr.organizee.dto.JsonWebToken;
import fr.organizee.dto.MembreDto;
import fr.organizee.exception.ExistingUsernameException;
import fr.organizee.exception.InvalidCredentialsException;
import fr.organizee.model.Membre; import fr.organizee.model.Membre;
//import fr.organizee.model.Team; //import fr.organizee.model.Team;
import fr.organizee.repository.MembreRepository; import fr.organizee.repository.MembreRepository;
//import fr.organizee.repository.TeamRepository; //import fr.organizee.repository.TeamRepository;
import fr.organizee.service.MembreService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException; import javax.persistence.EntityNotFoundException;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/* toto */ /* toto */
@RestController @RestController
@ -22,6 +29,9 @@ public class MembreController {
@Autowired @Autowired
private MembreRepository membreRepo; private MembreRepository membreRepo;
@Autowired
private MembreService membreService;
// @Autowired // @Autowired
// private TeamRepository teamRepo; // private TeamRepository teamRepo;
@ -36,6 +46,7 @@ public class MembreController {
} }
@GetMapping(value = "/all") @GetMapping(value = "/all")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> getAll(){ public ResponseEntity<?> getAll(){
List<Membre> liste = null; List<Membre> liste = null;
try try
@ -48,6 +59,13 @@ public class MembreController {
return ResponseEntity.status(HttpStatus.OK).body(liste); return ResponseEntity.status(HttpStatus.OK).body(liste);
} }
@GetMapping("/admin/all")
@PreAuthorize("hasRole('ROLE_PARENT')")
public List<MembreDto> getAllAdminUsers() {
return membreService.findAllUsers().stream().map(appUser -> new MembreDto(appUser.getEmail(), appUser.getRoleList())).collect(Collectors.toList());
}
// @GetMapping(value = "/team/all") // @GetMapping(value = "/team/all")
// public ResponseEntity<?> getAllTeam(){ // public ResponseEntity<?> getAllTeam(){
// List<Team> liste = null; // List<Team> liste = null;
@ -62,6 +80,7 @@ public class MembreController {
// } // }
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findById(@PathVariable int id){ public ResponseEntity<?> findById(@PathVariable int id){
Optional<Membre> membre = null; Optional<Membre> membre = null;
try try
@ -82,11 +101,12 @@ public class MembreController {
// } // }
@DeleteMapping(value = "/delete/{id}") @DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteMembre(@PathVariable int id){ public ResponseEntity<?> deleteMembre(@PathVariable int id){
try { try {
membreRepo.delete(membreRepo.getById(id)); membreRepo.delete(membreRepo.getById(id));
//membreRepo.deleteById(id); //membreRepo.deleteById(id);
return ResponseEntity.status(HttpStatus.OK).body("Membre effacée !"); return ResponseEntity.status(HttpStatus.OK).body("Membre effacé !");
} catch (EntityNotFoundException e) { } catch (EntityNotFoundException e) {
@ -94,19 +114,26 @@ public class MembreController {
} }
} }
@PostMapping(value="/add", produces="application/json", consumes="application/json") @PostMapping("/sign-up")
public ResponseEntity<?> addMembre(@RequestBody Membre membre){ public ResponseEntity<JsonWebToken> signUp(@RequestBody Membre membre) {
Membre resultMembre = null;
try { try {
resultMembre = membreRepo.saveAndFlush(membre); return ResponseEntity.ok(new JsonWebToken(membreService.signup(membre)));
} catch (Exception e) { } catch (ExistingUsernameException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); return ResponseEntity.badRequest().build();
} }
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultMembre); @PostMapping("/sign-in")
public ResponseEntity<JsonWebToken> signIn(@RequestBody Membre membre) {
try {
return ResponseEntity.ok(new JsonWebToken(membreService.signin(membre.getEmail(), membre.getPassword())));
} catch (InvalidCredentialsException ex) {
return ResponseEntity.badRequest().build();
}
} }
@PutMapping("/update/{id}") @PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception { public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception {
Membre resultMembre = null; Membre resultMembre = null;
try { try {
@ -148,22 +175,4 @@ public class MembreController {
// //
// return ResponseEntity.status(HttpStatus.OK).body(liste); // return ResponseEntity.status(HttpStatus.OK).body(liste);
// } // }
@PostMapping(value="/login", produces="application/json", consumes="application/json")
public ResponseEntity<?> login(@RequestBody Membre membre){
Membre resultMembre = null;
try {
resultMembre = membreRepo.findByNom(membre.getNom());
if(resultMembre == null){
throw new RuntimeException("User inexistant.");
}
if(!resultMembre.getPassword().equals(membre.getPassword())){
throw new RuntimeException("mauvais password.");
}
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultMembre);
}
} }

View File

@ -0,0 +1,90 @@
package fr.organizee.controller;
import fr.organizee.model.Contact;
import fr.organizee.model.Menu;
import fr.organizee.repository.MenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException;
import java.util.List;
import java.util.Optional;
@RestController
@CrossOrigin("*")
@RequestMapping("/menus")
public class MenuController {
@Autowired
private MenuRepository menuRepository;
@GetMapping(value = "/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findById(@PathVariable int id){
Optional<Menu> menu = null;
try
{
menu = menuRepository.findById(id);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(menu);
}
@GetMapping(value = "team/{team_id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findByTeamId(@PathVariable int team_id) {
List<Menu> menus = null;
try {
menus = menuRepository.FindMenusByTeam(team_id);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(menus);
}
@PostMapping(value="/add")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> addMenu(@RequestBody Menu menu){
Menu resultMenu = null;
try {
resultMenu = menuRepository.saveAndFlush(menu);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultMenu);
}
@PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateMenu(@RequestBody Menu menu, @PathVariable Integer id) throws Exception {
Menu resultMenu = null;
try {
resultMenu = menuRepository.save(menu);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.OK).body(menuRepository);
}
@DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteMenu(@PathVariable int id){
try {
menuRepository.delete(menuRepository.getById(id));
return ResponseEntity.status(HttpStatus.OK).body("Menu effacé !");
} catch (EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.OK).body("Menu introuvable !");
}
}
}

View File

@ -1,10 +1,12 @@
package fr.organizee.controller; package fr.organizee.controller;
import fr.organizee.model.Membre;
import fr.organizee.model.Team; import fr.organizee.model.Team;
import fr.organizee.repository.TeamRepository; import fr.organizee.repository.TeamRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException; import javax.persistence.EntityNotFoundException;
@ -32,6 +34,7 @@ public class TeamController {
// Récupération de toutes les teams // Récupération de toutes les teams
@GetMapping(value = "/all") @GetMapping(value = "/all")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> getAllTeam(){ public ResponseEntity<?> getAllTeam(){
List<Team> liste = null; List<Team> liste = null;
try try
@ -45,6 +48,7 @@ public class TeamController {
} }
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findTeamById(@PathVariable int id){ public ResponseEntity<?> findTeamById(@PathVariable int id){
Optional<Team> liste = null; Optional<Team> liste = null;
try try
@ -57,4 +61,44 @@ public class TeamController {
return ResponseEntity.status(HttpStatus.OK).body(liste); return ResponseEntity.status(HttpStatus.OK).body(liste);
} }
@PostMapping(value="/add", produces="application/json", consumes="application/json")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> addTeam(@RequestBody Team team){
Team resultTeam = null;
try {
resultTeam = teamRepo.saveAndFlush(team);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultTeam);
}
@PutMapping("/update/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateTeam(@RequestBody Team team, @PathVariable Integer id) throws Exception {
Team resultTeam = null;
try {
resultTeam = teamRepo.save(team);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.OK).body(resultTeam);
}
@DeleteMapping(value = "/delete/{id}")
@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteTeam(@PathVariable int id){
try {
teamRepo.delete(teamRepo.getById(id));
//membreRepo.deleteById(id);
return ResponseEntity.status(HttpStatus.OK).body("Team effacée !");
} catch (EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.OK).body("Team introuvable !");
}
}
} }

View File

@ -0,0 +1,18 @@
package fr.organizee.dto;
/**
* Classe spécifique DTO (Data Transfer Object) qui retourne un Jeton au format JSON (REST response)
*
*/
public class JsonWebToken {
private final String token;
public JsonWebToken(String token) {
this.token = token;
}
public String getToken() {
return token;
}
}

View File

@ -0,0 +1,53 @@
package fr.organizee.dto;
import java.util.List;
import com.sun.istack.NotNull;
import fr.organizee.model.Role;
/**
* Specifique : AppUser DTO permet de renvoyer un User sans le mot de passe (REST response).
*/
public class MembreDto {
private Long id;
private String email;
private List<Role> roleList;
public MembreDto() {
}
public MembreDto(@NotNull String email) {
this(email, null);
}
public MembreDto(@NotNull String email, List<Role> roleList) {
this.email = email;
this.roleList = roleList;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Role> getRoleList() {
return roleList;
}
public void setRoleList(List<Role> roleList) {
this.roleList = roleList;
}
}

View File

@ -0,0 +1,15 @@
package fr.organizee.exception;
/**
* Classe personnalisée pour ©rer un message si l'utilisateur (User) existe en Base de données
*/
public class ExistingUsernameException extends Exception {
private static final long serialVersionUID = 1L;
@Override
public String getMessage()
{
return "Désolé, l'utilisateur existe déjà en base de données !";
}
}

View File

@ -0,0 +1,15 @@
package fr.organizee.exception;
/**
* Specific exception that should be thrown when user credentials are not valid.
*/
public class InvalidCredentialsException extends Exception {
private static final long serialVersionUID = -6483691380297851921L;
@Override
public String getMessage()
{
return "L'accréditation est invalide !";
}
}

View File

@ -0,0 +1,17 @@
package fr.organizee.exception;
/**
* Specific exception that should be thrown when a JWT has an invalid format.
*/
public class InvalidJWTException extends Exception {
private static final long serialVersionUID = -6546999838071338632L;
@Override
public String getMessage()
{
return "Le format JWT est invalide !";
}
}

View File

@ -2,9 +2,11 @@ package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sun.istack.NotNull;
import javax.persistence.*; import javax.persistence.*;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
@Entity @Entity
@ -15,8 +17,19 @@ public class Membre {
private String nom; private String nom;
private String prenom; private String prenom;
private LocalDate dateNaissance; private LocalDate dateNaissance;
@NotNull
@Column(nullable = false)
private String email; private String email;
@NotNull
@Column(nullable = false)
private String password; private String password;
@ElementCollection(fetch = FetchType.EAGER)
@Enumerated(EnumType.STRING)
private List<Role> roleList;
private String isAdmin; private String isAdmin;
private String couleur; private String couleur;
private String smiley; private String smiley;
@ -31,7 +44,7 @@ public class Membre {
public Membre() { public Membre() {
} }
public Membre(String nom, String prenom, LocalDate dateNaissance, String email, String password, String isAdmin, String couleur, String smiley, Team team) { public Membre(String nom, String prenom, LocalDate dateNaissance, @NotNull String email, @NotNull String password, String isAdmin, String couleur, String smiley, Team team, List<Role> roleList) {
this.nom = nom; this.nom = nom;
this.prenom = prenom; this.prenom = prenom;
this.dateNaissance = dateNaissance; this.dateNaissance = dateNaissance;
@ -41,8 +54,16 @@ public class Membre {
this.couleur = couleur; this.couleur = couleur;
this.smiley = smiley; this.smiley = smiley;
this.team = team; this.team = team;
this.roleList=roleList;
} }
public Membre(@NotNull String email, @NotNull String password, List<Role> roleList) {
this.email = email;
this.password = password;
this.roleList=roleList;
}
public int getId() { public int getId() {
return id; return id;
} }
@ -109,6 +130,13 @@ public class Membre {
this.smiley = smiley; this.smiley = smiley;
} }
public List<Role> getRoleList() {
return roleList;
}
public void setRoleList(List<Role> roleList) {
this.roleList = roleList;
}
@Override @Override
public String toString() { public String toString() {
return "Membre{" + return "Membre{" +

View File

@ -12,6 +12,7 @@ public class Menu {
private int id; private int id;
private String libelle; private String libelle;
private LocalDate dateMenu; private LocalDate dateMenu;
private int validationProposition;
@ManyToOne(cascade = CascadeType.MERGE) @ManyToOne(cascade = CascadeType.MERGE)
@JoinColumn(name="TEAM_ID") @JoinColumn(name="TEAM_ID")
@JsonIgnoreProperties("menu") @JsonIgnoreProperties("menu")
@ -22,9 +23,10 @@ public class Menu {
public Menu() { public Menu() {
} }
public Menu(String libelle, LocalDate dateMenu) { public Menu(String libelle, LocalDate dateMenu, int validationProposition) {
this.libelle = libelle; this.libelle = libelle;
this.dateMenu = dateMenu; this.dateMenu = dateMenu;
this.validationProposition=validationProposition;
} }
public int getId() { public int getId() {

View File

@ -0,0 +1,16 @@
package fr.organizee.model;
import org.springframework.security.core.GrantedAuthority;
/**
* User possible roles.
*/
public enum Role implements GrantedAuthority {
ROLE_PARENT, ROLE_ENFANT;
@Override
public String getAuthority() {
return name();
}
}

View File

@ -55,8 +55,16 @@ public class Team {
this.membres = membre; this.membres = membre;
} }
public List<Contact> getContacts() {
return contacts;
}
public void setContacts(List<Contact> contacts) {
this.contacts = contacts;
}
@Override @Override
public String toString() { public String toString() {
return "Team [id=" + id + ", nom=" + nom + ", membre=" + membres + "]"; return "Team [id=" + id + ", nom=" + nom + ", membre=" + membres + ", contact=" + contacts + "]";
} }
} }

View File

@ -1,4 +1,19 @@
package fr.organizee.repository; package fr.organizee.repository;
public interface ContactRepository { import fr.organizee.model.Contact;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface ContactRepository extends JpaRepository<Contact, Integer> {
@Query(value = "select * from contact where team_id = :team_id", nativeQuery = true)
List<Contact> FindContactsByTeam(@Param("team_id") int team_id);
} }

View File

@ -4,7 +4,15 @@ import fr.organizee.model.Membre;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository @Repository
public interface MembreRepository extends JpaRepository<Membre, Integer> { public interface MembreRepository extends JpaRepository<Membre, Integer> {
Membre findByNom(String nom); Membre findByNom(String nom);
Optional<Membre> findByEmail(String email);
boolean existsByEmail(String email);
void deleteByEmail(String email);
} }

View File

@ -1,4 +1,17 @@
package fr.organizee.repository; package fr.organizee.repository;
public interface MenuRepository { import fr.organizee.model.Contact;
import fr.organizee.model.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface MenuRepository extends JpaRepository <Menu, Integer> {
@Query(value = "select * from menu where team_id = :team_id", nativeQuery = true)
List<Menu> FindMenusByTeam(@Param("team_id") int team_id);
} }

View File

@ -0,0 +1,46 @@
package fr.organizee.security;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;
import fr.organizee.exception.InvalidJWTException;
/**
* Filtre specifique en charge d'analyser la requête HTTP qui arrive vers notre Serveur et qui doit
* contenir un JWT valide.
*/
public class JwtTokenFilter extends OncePerRequestFilter {
private JwtTokenProvider jwtTokenProvider;
public JwtTokenFilter(JwtTokenProvider jwtTokenProvider) {
this.jwtTokenProvider = jwtTokenProvider;
}
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
String token = jwtTokenProvider.resolveToken(httpServletRequest);
try {
if (token != null && jwtTokenProvider.validateToken(token)) {
Authentication auth = jwtTokenProvider.getAuthentication(token);
SecurityContextHolder.getContext().setAuthentication(auth);
}
} catch (InvalidJWTException ex) {
// permet de garantir que le AppClient n'est pas authentifié
SecurityContextHolder.clearContext();
httpServletResponse.sendError(HttpStatus.BAD_REQUEST.value(), "JWT invalide !");
return;
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}

View File

@ -0,0 +1,185 @@
package fr.organizee.security;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import fr.organizee.exception.InvalidJWTException;
import fr.organizee.model.Role;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
/**
* JWT : classe utilitaire chargée de fournir le Jeton (Token) et les ©rifications
*/
@Component
public class JwtTokenProvider {
// on ©cupère le secret dans notre fichier application.properties
@Value("${security.jwt.token.secret-key:secret-key}")
private String secretKey;
// ici on met la valeur par ©faut
@Value("${security.jwt.token.expire-length:3600000}")
private long validityInMilliseconds = 3600000; // 1h pour être pénard
@Autowired
private UserDetailsService userDetailsService;
/**
* Cette ©thode d'initialisation s'exécute avant le constructeur
* Elle encode notre code secret en base64 pour la transmission dans le header
*/
@PostConstruct
protected void init() {
secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes());
}
/**
* Methode qui crée le Token avec :
* username comme un champ "sub",
* User Role comme champ "auth"
* "iat" comme date du jour ,
* "exp" as now date + validity time.
* claims = les droits
struture :
HEADER : Algo + Type de Token
{
"alg": "HS256",
"typ": "JWT"
}
PAYLOAD : data
{
"sub": "pbouget",
"auth": [
"ROLE_ADMIN",
"ROLE_CREATOR",
"ROLE_READER"
],
"iat": 1589817421,
"exp": 1589821021
}
Signature :
Signature avec code secret :
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
03888dd6ceb88c3fee410a70802fb93d483fd52d70349d8f7e7581ae346cf658
)
JWT ©¨rer avec cette info :
header = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
payload = eyJzdWIiOiJwYm91Z2V0IiwiYXV0aCI6WyJST0xFX0FETUlOIiwiUk9MRV9DUkVBVE9SIiwiUk9MRV9SRUFERVIiXSwiaWF0IjoxNTg5ODE3NDIxLCJleHAiOjE1ODk4MjEwMjF9.
signature = lrKQIkrCzNMwzTN-hs_EdoYYxrb59sAlku7nmaml0vk
©rifier sur https://jwt.io
* @param email the user email.
* @param roles the user roles.
* @return the created JWT as String.
* @throws JsonProcessingException
*/
public String createToken(String email, List<Role> roles){
Claims claims = Jwts.claims().setSubject(email);
claims.put("auth", roles.stream().map(s -> new SimpleGrantedAuthority(s.getAuthority())).filter(Objects::nonNull).collect(Collectors.toList()));
System.out.println("claims = "+claims);
// claims = {sub=pbouget, auth=[ROLE_ADMIN, ROLE_CREATOR, ROLE_READER]}
Date now = new Date();
Date validity = new Date(now.getTime() + validityInMilliseconds);
String leToken = Jwts.builder()//
.setClaims(claims)// le username avec les roles ou setPayload()
.setIssuedAt(now)// 1589817421 pour le 18 mai 2020 à 17 heure 57
.setExpiration(validity)// 1589821021 même date avec 1 heure de plus
.signWith(SignatureAlgorithm.HS256, secretKey) // la signature avec la clef secrête.
.compact(); // concatène l'ensemble pour construire une chaîne
System.out.println(leToken); // pour test cela donne ceci
/*
site pour convertir une date en millisecondes : http://timestamp.fr/?
site structure du jeton : https://www.vaadata.com/blog/fr/jetons-jwt-et-securite-principes-et-cas-dutilisation/
site jwt encoder / ©coder : https://jwt.io/
eyJhbGciOiJIUzI1NiJ9.
eyJzdWIiOiJwYm91Z2V0IiwiYXV0aCI6W3siYXV0aG9yaXR5IjoiUk9MRV9BRE1JTiJ9LHsiYXV0aG9yaXR5IjoiUk9MRV9DUkVBVE9SIn0seyJhdXRob3JpdHkiOiJST0xFX1JFQURFUiJ9XSwiaWF0IjoxNTg5ODE2OTIyLCJleHAiOjE1ODk4MjA1MjJ9.
Cn4_UTjZ2UpJ32FVT3Bd1-VN8K62DVBHQbWiK6MNZ04
*/
// https://www.codeflow.site/fr/article/java__how-to-convert-java-object-to-from-json-jackson
return leToken;
}
/**
* Methode qui retourne un objet Authentication basé sur JWT.
* @param token : le token pour l'authentification.
* @return the authentication si Username est trouvé.
*/
public Authentication getAuthentication(String token) {
UserDetails userDetails = userDetailsService.loadUserByUsername(getEmail(token));
return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities());
}
/**
* Methode qui extrait le userName du JWT.
* @param token : Token a analyser.
* @return le UserName comme chaîne de caractères.
*/
public String getEmail(String token) {
return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().getSubject();
}
/**
* ©thode qui ©cupère la requete HTTP.
* L'entête doit contenir un champ d'autorisation ou JWT ajoute le token après le mot clef Bearer.
* @param requete : la requête à tester.
* @return le JWT depuis l'entête HTTP.
*/
public String resolveToken(HttpServletRequest requeteHttp) {
String bearerToken = requeteHttp.getHeader("Authorization");
if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
}
return null;
}
/**
* Methode qui ¿½rifie que JWT est valide.
* La signature doit �tre correcte et la dur�e de validit� du Token doit �tre apr�s "now" (maintenant)
* @param token : Token � valider
* @return True si le Token est valide sinon on lance l'exception InvalidJWTException.
* @throws InvalidJWTException
*/
public boolean validateToken(String token) throws InvalidJWTException {
try {
Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token);
return true;
} catch (JwtException | IllegalArgumentException e) {
throw new InvalidJWTException();
}
}
}

View File

@ -0,0 +1,72 @@
package fr.organizee.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
/**
* Configuration de S<EFBFBD>curit<EFBFBD> globale pour notre REST API.
*/
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private JwtTokenProvider jwtTokenProvider;
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
/**
* Methode qui configure la s<EFBFBD>curit<EFBFBD> HTTP.
* @param http the HttpSecurity object to configure.
* @throws Exception
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// Disable CSRF (Cross Site Request Forgery comme votre Token sera stock<EFBFBD> dans le session storage)
http.cors();
http.csrf().disable()
.authorizeRequests()
.antMatchers("/**").permitAll() // accessible sans besoin de s'authentifier
.and()
.authorizeRequests()
.antMatchers("/membres/sign-in").permitAll() // se connecter
.antMatchers("/membres/sign-up").permitAll() // s'inscrire
.antMatchers("membres/all").hasAuthority("ROLE_PARENT") // uniquement pour le r<EFBFBD>le admin
.anyRequest().authenticated(); // tout le reste est autoris<EFBFBD> par un utilisateur authentifi<EFBFBD>
// Appliquer un filtre avec le token pour toutes requ<EFBFBD>tes HTTP
http.addFilterBefore(new JwtTokenFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class);
}
/**
* Methode qui configure la s<EFBFBD>curit<EFBFBD> web.
* Utilis<EFBFBD> pour interdire l'acc<EFBFBD>s à certains r<EFBFBD>pertoires.
* @param web : WebSecurity
* @throws Exception
*/
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
}

View File

@ -0,0 +1,45 @@
package fr.organizee.service;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
import fr.organizee.exception.ExistingUsernameException;
import fr.organizee.exception.InvalidCredentialsException;
import fr.organizee.model.Membre;
@Service
public interface MembreService {
/**
* Methode qui permet à un utilisateur de se connecter.
* @param email : nom de l'utilisateur.
* @param password : mot de passe de l'utilisateur.
* @returnun JWT si credentials est valide, throws InvalidCredentialsException otherwise.
* @throws InvalidCredentialsException
*/
String signin(String email, String password) throws InvalidCredentialsException;
/**
* Methode qui permet de s'inscrire.
* @param membre nouvel utilisateur.
* @return un JWT si user n'existe pas ©  !
* @throws ExistingUsernameException
*/
String signup(Membre membre) throws ExistingUsernameException;
/**
* Methode qui retourne tous les utilisateurs de la bd
* @return the list of all application users.
*/
List<Membre> findAllUsers();
/**
* Methode qui retourne un utilisateur à partir de son username
* @param email the username to look for.
* @return an Optional object containing user if found, empty otherwise.
*/
Optional<Membre> findUserByEmail(String email);
}

View File

@ -0,0 +1,69 @@
package fr.organizee.service;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import fr.organizee.exception.ExistingUsernameException;
import fr.organizee.exception.InvalidCredentialsException;
import fr.organizee.model.Membre;
import fr.organizee.repository.MembreRepository;
import fr.organizee.security.JwtTokenProvider;
@Service
public class MembreServiceImpl implements MembreService {
@Autowired
private MembreRepository membreRepository; // permet communication avec la BD
@Autowired
private BCryptPasswordEncoder passwordEncoder; // permet l'encodage du mot de passe
@Autowired
private JwtTokenProvider jwtTokenProvider; // permet la fourniture du Jeton (Token)
@Autowired
private AuthenticationManager authenticationManager; // gestionnaire d'authentification
/**
* Permet de se connecter en encodant le mot de passe avec ©©ration du token.
*/
@Override
public String signin(String email, String password) throws InvalidCredentialsException {
try {
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(email, password));
return jwtTokenProvider.createToken(email, membreRepository.findByEmail(email).get().getRoleList());
} catch (AuthenticationException e) {
throw new InvalidCredentialsException();
}
}
@Override
public String signup(Membre membre) throws ExistingUsernameException {
if (!membreRepository.existsByEmail(membre.getEmail())) {
Membre membreToSave = new Membre(membre.getEmail(), passwordEncoder.encode(membre.getPassword()), membre.getRoleList());
membreRepository.save(membreToSave);
return jwtTokenProvider.createToken(membre.getEmail(), membre.getRoleList());
} else {
throw new ExistingUsernameException();
}
}
@Override
public List<Membre> findAllUsers() {
return membreRepository.findAll();
}
@Override
public Optional<Membre> findUserByEmail(String email) {
return membreRepository.findByEmail(email);
}
}

View File

@ -0,0 +1,40 @@
package fr.organizee.service;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import fr.organizee.model.Membre;
import fr.organizee.repository.MembreRepository;
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
@Autowired
private MembreRepository userRepository;
@Override
public UserDetails loadUserByUsername(String email) {
final Optional<Membre> user = userRepository.findByEmail(email);
if (!user.isPresent()) {
throw new UsernameNotFoundException("utilisateur '" + email + "' introuvable");
}
return User
.withUsername(email)
.password(user.get().getPassword())
.authorities(user.get().getRoleList())
.accountExpired(false)
.accountLocked(false)
.credentialsExpired(false)
.disabled(false)
.build();
}
}

View File

@ -1,65 +1,21 @@
-- -------------------------------------------------------- INSERT INTO `team` (`id`, `nom`) VALUES
-- Hôte : 192.168.1.16 (1, 'Team JAVA'),
-- Version du serveur: 10.3.32-MariaDB-0ubuntu0.20.04.1 - Ubuntu 20.04 (2, 'Team Angular'),
-- SE du serveur: debian-linux-gnu (3, 'Team PHP'),
-- HeidiSQL Version: 9.5.0.5196 (4, 'Team Bancal');
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
-- Export de la structure de la table jpa. contact
CREATE TABLE IF NOT EXISTS `contact` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`adresse` varchar(255) DEFAULT NULL,
`date_naissance` date DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`nom` varchar(255) DEFAULT NULL,
`prenom` varchar(255) DEFAULT NULL,
`telephone` varchar(255) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK7gyd9s84tx9eeuigeu3uv984x` (`team_id`),
CONSTRAINT `FK7gyd9s84tx9eeuigeu3uv984x` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table jpa.contact : ~0 rows (environ)
/*!40000 ALTER TABLE `contact` DISABLE KEYS */;
INSERT INTO `contact` (`id`, `adresse`, `date_naissance`, `email`, `nom`, `prenom`, `telephone`, `team_id`) VALUES INSERT INTO `contact` (`id`, `adresse`, `date_naissance`, `email`, `nom`, `prenom`, `telephone`, `team_id`) VALUES
(1, '7554 Messerschmidt Center', '2021-01-24', 'oogleasane0@cargocollective.com', 'Ophelia', 'O\'Gleasane', '913-198-6499', 1), (1, '7554 Messerschmidt Center', '2021-01-24', 'oogleasane0@cargocollective.com', 'Ophelia', 'O\'Gleasane', '913-198-6499','1'),
(2, '534 Jay Way', '2021-03-26', 'fmowett1@ocn.ne.jp', 'Fiann', 'Mowett', '248-224-7233', 1), (2, '534 Jay Way', '2021-03-26', 'fmowett1@ocn.ne.jp', 'Fiann', 'Mowett', '248-224-7233','1'),
(3, '077 Buell Place', '2021-06-24', 'vlewknor2@spotify.com', 'Vladamir', 'Lewknor', '922-822-3626', 1), (3, '077 Buell Place', '2021-06-24', 'vlewknor2@spotify.com', 'Vladamir', 'Lewknor', '922-822-3626','1'),
(4, '6226 Esker Street', '2021-04-13', 'jbarmadier3@opensource.org', 'Jervis', 'Barmadier', '838-581-8112', 2), (4, '6226 Esker Street', '2021-04-13', 'jbarmadier3@opensource.org', 'Jervis', 'Barmadier', '838-581-8112','2'),
(5, '28531 Luster Circle', '2021-06-15', 'tmee4@ameblo.jp', 'Tuesday', 'Mee', '761-975-7324', 2), (5, '28531 Luster Circle', '2021-06-15', 'tmee4@ameblo.jp', 'Tuesday', 'Mee', '761-975-7324','2'),
(6, '96 Hallows Avenue', '2021-08-13', 'tcolvine5@elegantthemes.com', 'Toni', 'Colvine', '348-778-7679', 2), (6, '96 Hallows Avenue', '2021-08-13', 'tcolvine5@elegantthemes.com', 'Toni', 'Colvine', '348-778-7679','2'),
(7, '6401 Jay Crossing', '2021-01-14', 'rrielly6@netlog.com', 'Riane', 'Rielly', '740-571-0835', 3), (7, '6401 Jay Crossing', '2021-01-14', 'rrielly6@netlog.com', 'Riane', 'Rielly', '740-571-0835','3'),
(8, '3273 Cascade Pass', '2021-03-22', 'jlauder7@rambler.ru', 'Juieta', 'Lauder', '928-408-6855', 3), (8, '3273 Cascade Pass', '2021-03-22', 'jlauder7@rambler.ru', 'Juieta', 'Lauder', '928-408-6855','3'),
(9, '1170 Burning Wood Road', '2021-05-31', 'tbolver8@google.ca', 'Thibaut', 'Bolver', '681-860-8291', 4), (9, '1170 Burning Wood Road', '2021-05-31', 'tbolver8@google.ca', 'Thibaut', 'Bolver', '681-860-8291','4'),
(10, '1 Westridge Road', '2021-03-11', 'emebs9@uol.com.br', 'Evered', 'Mebs', '898-483-6075', 4); (10, '1 Westridge Road', '2021-03-11', 'emebs9@uol.com.br', 'Evered', 'Mebs', '898-483-6075','4');
/*!40000 ALTER TABLE `contact` ENABLE KEYS */;
-- Export de la structure de la table jpa. membre
CREATE TABLE IF NOT EXISTS `membre` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`couleur` varchar(255) DEFAULT NULL,
`date_naissance` date DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`is_admin` varchar(255) DEFAULT NULL,
`nom` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`prenom` varchar(255) DEFAULT NULL,
`smiley` varchar(255) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FKll5mmgkw1h2kmxnuo4885x2fn` (`team_id`),
CONSTRAINT `FKll5mmgkw1h2kmxnuo4885x2fn` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table jpa.membre : ~0 rows (environ)
/*!40000 ALTER TABLE `membre` DISABLE KEYS */;
INSERT INTO `membre` (`id`, `couleur`, `date_naissance`, `email`, `is_admin`, `nom`, `password`, `prenom`, `smiley`, `team_id`) VALUES INSERT INTO `membre` (`id`, `couleur`, `date_naissance`, `email`, `is_admin`, `nom`, `password`, `prenom`, `smiley`, `team_id`) VALUES
(1, '#fcba03', '2021-12-13', 'hedi@simplon.com', '0', 'SKYWALKER', 'toto', 'Hédi', NULL, 1), (1, '#fcba03', '2021-12-13', 'hedi@simplon.com', '0', 'SKYWALKER', 'toto', 'Hédi', NULL, 1),
(2, '#8df505', '2021-07-03', 'aline@simplon.com', '0', 'FETT', 'tata', 'Aline', NULL, 1), (2, '#8df505', '2021-07-03', 'aline@simplon.com', '0', 'FETT', 'tata', 'Aline', NULL, 1),
@ -67,81 +23,19 @@ INSERT INTO `membre` (`id`, `couleur`, `date_naissance`, `email`, `is_admin`, `n
(4, '#ed09de', '2021-06-29', 'blandine@simplon.com', '0', 'VADER', 'tutu', 'Blandine', NULL, 3), (4, '#ed09de', '2021-06-29', 'blandine@simplon.com', '0', 'VADER', 'tutu', 'Blandine', NULL, 3),
(5, '#ed09de', '2021-08-29', 'sana@simplon.com', '0', 'C3PO', 'riri', 'Sana', NULL, 4), (5, '#ed09de', '2021-08-29', 'sana@simplon.com', '0', 'C3PO', 'riri', 'Sana', NULL, 4),
(6, '#ed09de', '2021-10-29', 'cecile@simplon.com', '0', 'R2D2', 'loulou', 'Cecile', NULL, 4); (6, '#ed09de', '2021-10-29', 'cecile@simplon.com', '0', 'R2D2', 'loulou', 'Cecile', NULL, 4);
/*!40000 ALTER TABLE `membre` ENABLE KEYS */;
-- Export de la structure de la table jpa. menu
CREATE TABLE IF NOT EXISTS `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date_menu` date DEFAULT NULL,
`libelle` varchar(255) DEFAULT NULL,
`membre_id` int(11) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK9k2sad7pn2qsivwavhptvm3u6` (`membre_id`),
KEY `FKky2j5l3syborv9dtqtprgpr28` (`team_id`),
CONSTRAINT `FK9k2sad7pn2qsivwavhptvm3u6` FOREIGN KEY (`membre_id`) REFERENCES `membre` (`id`),
CONSTRAINT `FKky2j5l3syborv9dtqtprgpr28` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Export de données de la table jpa.menu : ~0 rows (environ)
/*!40000 ALTER TABLE `menu` DISABLE KEYS */;
/*!40000 ALTER TABLE `menu` ENABLE KEYS */;
-- Export de la structure de la table jpa. tache
CREATE TABLE IF NOT EXISTS `tache` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`etat` bit(1) DEFAULT NULL,
`texte` varchar(255) DEFAULT NULL,
`todolist_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK50q0ja9qvoud7ujsudc9jj9yk` (`todolist_id`),
CONSTRAINT `FK50q0ja9qvoud7ujsudc9jj9yk` FOREIGN KEY (`todolist_id`) REFERENCES `todo_list` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table jpa.tache : ~0 rows (environ)
/*!40000 ALTER TABLE `tache` DISABLE KEYS */;
INSERT INTO `tache` (`id`, `etat`, `texte`, `todolist_id`) VALUES
(1, b'0', 'Apprendre le PHP', 1),
(2, b'0', 'Revoir CRUD', 1),
(3, b'0', 'Acheter des guirlandes', 3),
(4, b'0', 'Acheter un sapin', 3),
(5, b'0', 'Trouver un repas', 3);
/*!40000 ALTER TABLE `tache` ENABLE KEYS */;
-- Export de la structure de la table jpa. team
CREATE TABLE IF NOT EXISTS `team` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table jpa.team : ~0 rows (environ)
/*!40000 ALTER TABLE `team` DISABLE KEYS */;
INSERT INTO `team` (`id`, `nom`) VALUES
(1, 'Team JAVA'),
(2, 'Team Angular'),
(3, 'Team PHP'),
(4, 'Team Bancal');
/*!40000 ALTER TABLE `team` ENABLE KEYS */;
-- Export de la structure de la table jpa. todo_list
CREATE TABLE IF NOT EXISTS `todo_list` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` varchar(255) DEFAULT NULL,
`team_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK6ty40hkdysbql7xaewhujsjg` (`team_id`),
CONSTRAINT `FK6ty40hkdysbql7xaewhujsjg` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
-- Export de données de la table jpa.todo_list : ~0 rows (environ)
/*!40000 ALTER TABLE `todo_list` DISABLE KEYS */;
INSERT INTO `todo_list` (`id`, `nom`, `team_id`) VALUES INSERT INTO `todo_list` (`id`, `nom`, `team_id`) VALUES
(1, 'Pour Blandine', 1), (1, 'Pour Blandine',1),
(2, 'Corvées', 1), (2, 'Corvées',1),
(3, 'Noel', 1); (3, 'Noel',1);
/*!40000 ALTER TABLE `todo_list` ENABLE KEYS */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; INSERT INTO `tache` (`id`, `etat`, `texte`, `todolist_id`) VALUES
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; (1, 0, 'Apprendre le PHP', 1),
(2, 0, 'Revoir CRUD', 1),
(3, 0, 'Acheter des guirlandes', 3),
(4, 0, 'Acheter un sapin', 3),
(5, 0, 'Trouver un repas', 3);
INSERT INTO `evenement` (`id`, `all_day`, `event_debut`, `event_fin`, `libelle`, `membre_id`, `team_id`) VALUES
(1, 0, '2022-01-13 09:00:33', '2022-01-13 13:04:38', 'Simplon', 1, 1);