Merge pull request #51 from HediMjid/sana

avancées
This commit is contained in:
Blandine Bajard 2022-03-04 16:15:41 +01:00 committed by GitHub
commit 5ba2f1c9fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 33 deletions

View File

@ -159,15 +159,18 @@ public class MembreController {
* *
* @return http://localhost:8088/membres/update/1 * @return http://localhost:8088/membres/update/1
*/ */
@PutMapping("/update/{id}") @PutMapping("/update/{team_id}/{id}")
//@PreAuthorize("hasRole('ROLE_PARENT')") //@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable int id) { public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable int id, @PathVariable int team_id) {
Optional<Membre> membreUpdate; Optional<Membre> membreUpdate;
try { try {
membreUpdate = membreRepository.findById(id); membreUpdate = membreRepository.findById(id);
// membre trouvé // membre trouvé
if (membreUpdate.isPresent()) { if (membreUpdate.isPresent()) {
membre.setId(membreUpdate.get().getId()); membre.setId(membreRepository.findById(id).get().getId());
Team team = new Team();
team.setId(team_id);
membre.setTeam(team);
membreRepository.save(membre); membreRepository.save(membre);
} }
//membre inconnu //membre inconnu
@ -213,9 +216,7 @@ public class MembreController {
} }
/********************* Gestion Mot de Passe ************************************/ /********************* Gestion Mot de Passe ************************************/
//cette methode ne fonctionne pas parce que ça affiche "trouvé" dans tous les cas
@PostMapping("/forgot-password") @PostMapping("/forgot-password")
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) { public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) {
Membre resultMembre = null; Membre resultMembre = null;
try { try {
@ -232,7 +233,6 @@ public class MembreController {
} }
@PutMapping("/reset-password/{uuid}") @PutMapping("/reset-password/{uuid}")
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception { public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception {
Membre resultMembre = null; Membre resultMembre = null;
try { try {

View File

@ -1,8 +1,9 @@
package fr.organizee.model; package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sun.istack.NotNull; import com.sun.istack.NotNull;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.*; import javax.persistence.*;
import java.time.LocalDate; import java.time.LocalDate;
@ -10,6 +11,9 @@ import java.util.List;
@Entity @Entity
@Table(name = "membre")
@SQLDelete(sql = "UPDATE membre SET deleted = true WHERE id=?")
@Where(clause = "deleted=false")
public class Membre { public class Membre {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -33,14 +37,14 @@ public class Membre {
private String isAdmin; private String isAdmin;
private String couleur; private String couleur;
private String smiley; private String smiley;
// @ManyToOne
// @JoinColumn(name="TEAM_ID")
// @JsonIgnore
@ManyToOne @ManyToOne
@JoinColumn(name="TEAM_ID") @JoinColumn(name = "TEAM_ID")
@JsonIgnoreProperties("membre") @JsonIgnoreProperties("membre")
private Team team; private Team team;
private boolean deleted = Boolean.FALSE;
public Membre() { public Membre() {
} }
@ -52,56 +56,77 @@ public class Membre {
this.email = email; this.email = email;
this.password = password; this.password = password;
this.team = team; this.team = team;
this.roleList=roleList; this.roleList = roleList;
} }
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
public int getId() { public int getId() {
return id; return id;
} }
public void setId(int id) { public void setId(int id) {
this.id = id; this.id = id;
} }
public String getNom() { public String getNom() {
return nom; return nom;
} }
public String getCouleur() {
return couleur;
}
public void setCouleur(String couleur) {
this.couleur = couleur;
}
public void setNom(String nom) { public void setNom(String nom) {
this.nom = nom; this.nom = nom;
} }
public String getCouleur() {
return couleur;
}
public void setCouleur(String couleur) {
this.couleur = couleur;
}
public String getPrenom() { public String getPrenom() {
return prenom; return prenom;
} }
public void setPrenom(String prenom) { public void setPrenom(String prenom) {
this.prenom = prenom; this.prenom = prenom;
} }
public LocalDate getDateNaissance() { public LocalDate getDateNaissance() {
return dateNaissance; return dateNaissance;
} }
public void setDateNaissance(LocalDate dateNaissance) { public void setDateNaissance(LocalDate dateNaissance) {
this.dateNaissance = dateNaissance; this.dateNaissance = dateNaissance;
} }
public String getEmail() { public String getEmail() {
return email; return email;
} }
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
public String getPassword() { public String getPassword() {
return password; return password;
} }
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
public String getIsAdmin() { public String getIsAdmin() {
return isAdmin; return isAdmin;
} }
public void setIsAdmin(String isAdmin) { public void setIsAdmin(String isAdmin) {
this.isAdmin = isAdmin; this.isAdmin = isAdmin;
} }
@ -109,6 +134,7 @@ public class Membre {
public Team getTeam() { public Team getTeam() {
return team; return team;
} }
public void setTeam(Team team) { public void setTeam(Team team) {
this.team = team; this.team = team;
} }
@ -116,6 +142,7 @@ public class Membre {
public List<Role> getRoleList() { public List<Role> getRoleList() {
return roleList; return roleList;
} }
public void setRoleList(List<Role> roleList) { public void setRoleList(List<Role> roleList) {
this.roleList = roleList; this.roleList = roleList;
} }
@ -135,5 +162,4 @@ public class Membre {
/*", team=" + team +*/ /*", team=" + team +*/
'}'; '}';
} }
} }

View File

@ -8,8 +8,7 @@ import org.springframework.security.core.GrantedAuthority;
public enum Role implements GrantedAuthority { public enum Role implements GrantedAuthority {
ROLE_PARENT, ROLE_ENFANT; ROLE_PARENT, ROLE_ENFANT;
@Override
public String getAuthority() { public String getAuthority() {
return name(); return name();
} }

View File

@ -1,8 +1,10 @@
package fr.organizee.service; package fr.organizee.service;
import java.util.List; import fr.organizee.exception.ExistingUsernameException;
import java.util.Optional; import fr.organizee.exception.InvalidCredentialsException;
import fr.organizee.model.Membre;
import fr.organizee.repository.MembreRepository;
import fr.organizee.security.JwtTokenProvider;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -10,11 +12,8 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import fr.organizee.exception.ExistingUsernameException; import java.util.List;
import fr.organizee.exception.InvalidCredentialsException; import java.util.Optional;
import fr.organizee.model.Membre;
import fr.organizee.repository.MembreRepository;
import fr.organizee.security.JwtTokenProvider;
@Service @Service
public class public class
@ -27,7 +26,7 @@ MembreServiceImpl implements MembreService {
private BCryptPasswordEncoder passwordEncoder; // permet l'encodage du mot de passe private BCryptPasswordEncoder passwordEncoder; // permet l'encodage du mot de passe
@Autowired @Autowired
private JwtTokenProvider jwtTokenProvider; // permet la fourniture du Jeton (Token) private JwtTokenProvider jwtTokenProvider; // permet la fourniture du Jeton (Token)
@Autowired @Autowired
private AuthenticationManager authenticationManager; // gestionnaire d'authentification private AuthenticationManager authenticationManager; // gestionnaire d'authentification
@ -59,6 +58,7 @@ MembreServiceImpl implements MembreService {
} }
} }
@Override @Override
public List<Membre> findAllUsers() { public List<Membre> findAllUsers() {
return membreRepository.findAll(); return membreRepository.findAll();
@ -80,5 +80,4 @@ MembreServiceImpl implements MembreService {
} }
} }