commit
						5ba2f1c9fd
					
				
					 4 changed files with 57 additions and 33 deletions
				
			
		| 
						 | 
				
			
			@ -159,15 +159,18 @@ public class MembreController {
 | 
			
		|||
     *
 | 
			
		||||
     * @return http://localhost:8088/membres/update/1
 | 
			
		||||
     */
 | 
			
		||||
    @PutMapping("/update/{id}")
 | 
			
		||||
    @PutMapping("/update/{team_id}/{id}")
 | 
			
		||||
    //@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;
 | 
			
		||||
        try {
 | 
			
		||||
            membreUpdate = membreRepository.findById(id);
 | 
			
		||||
            // membre trouvé
 | 
			
		||||
            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);
 | 
			
		||||
            }
 | 
			
		||||
            //membre inconnu
 | 
			
		||||
| 
						 | 
				
			
			@ -213,9 +216,7 @@ public class MembreController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /********************* Gestion Mot de Passe ************************************/
 | 
			
		||||
    //cette methode ne fonctionne pas parce que ça affiche "trouvé" dans tous les cas
 | 
			
		||||
    @PostMapping("/forgot-password")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) {
 | 
			
		||||
        Membre resultMembre = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -232,7 +233,6 @@ public class MembreController {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/reset-password/{uuid}")
 | 
			
		||||
    //@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
 | 
			
		||||
    public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception {
 | 
			
		||||
        Membre resultMembre = null;
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
package fr.organizee.model;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnore;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 | 
			
		||||
import com.sun.istack.NotNull;
 | 
			
		||||
import org.hibernate.annotations.SQLDelete;
 | 
			
		||||
import org.hibernate.annotations.Where;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.*;
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
| 
						 | 
				
			
			@ -10,6 +11,9 @@ import java.util.List;
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Table(name = "membre")
 | 
			
		||||
@SQLDelete(sql = "UPDATE membre SET deleted = true WHERE id=?")
 | 
			
		||||
@Where(clause = "deleted=false")
 | 
			
		||||
public class Membre {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.IDENTITY)
 | 
			
		||||
| 
						 | 
				
			
			@ -33,14 +37,14 @@ public class Membre {
 | 
			
		|||
    private String isAdmin;
 | 
			
		||||
    private String couleur;
 | 
			
		||||
    private String smiley;
 | 
			
		||||
    //    @ManyToOne
 | 
			
		||||
//    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
//    @JsonIgnore
 | 
			
		||||
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @JoinColumn(name="TEAM_ID")
 | 
			
		||||
    @JoinColumn(name = "TEAM_ID")
 | 
			
		||||
    @JsonIgnoreProperties("membre")
 | 
			
		||||
    private Team team;
 | 
			
		||||
 | 
			
		||||
    private boolean deleted = Boolean.FALSE;
 | 
			
		||||
 | 
			
		||||
    public Membre() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -52,56 +56,77 @@ public class Membre {
 | 
			
		|||
        this.email = email;
 | 
			
		||||
        this.password = password;
 | 
			
		||||
        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() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setId(int id) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getNom() {
 | 
			
		||||
        return nom;
 | 
			
		||||
    }
 | 
			
		||||
    public String getCouleur() {
 | 
			
		||||
        return couleur;
 | 
			
		||||
    }
 | 
			
		||||
    public void setCouleur(String couleur) {
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNom(String nom) {
 | 
			
		||||
        this.nom = nom;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getCouleur() {
 | 
			
		||||
        return couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCouleur(String couleur) {
 | 
			
		||||
        this.couleur = couleur;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getPrenom() {
 | 
			
		||||
        return prenom;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPrenom(String prenom) {
 | 
			
		||||
        this.prenom = prenom;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LocalDate getDateNaissance() {
 | 
			
		||||
        return dateNaissance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDateNaissance(LocalDate dateNaissance) {
 | 
			
		||||
        this.dateNaissance = dateNaissance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getEmail() {
 | 
			
		||||
        return email;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEmail(String email) {
 | 
			
		||||
        this.email = email;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getPassword() {
 | 
			
		||||
        return password;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPassword(String password) {
 | 
			
		||||
        this.password = password;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getIsAdmin() {
 | 
			
		||||
        return isAdmin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIsAdmin(String isAdmin) {
 | 
			
		||||
        this.isAdmin = isAdmin;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +134,7 @@ public class Membre {
 | 
			
		|||
    public Team getTeam() {
 | 
			
		||||
        return team;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTeam(Team team) {
 | 
			
		||||
        this.team = team;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -116,6 +142,7 @@ public class Membre {
 | 
			
		|||
    public List<Role> getRoleList() {
 | 
			
		||||
        return roleList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRoleList(List<Role> roleList) {
 | 
			
		||||
        this.roleList = roleList;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -136,4 +163,3 @@ public class Membre {
 | 
			
		|||
                '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,6 @@ public enum Role implements GrantedAuthority {
 | 
			
		|||
 | 
			
		||||
    ROLE_PARENT, ROLE_ENFANT;
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getAuthority() {
 | 
			
		||||
        return name();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,10 @@
 | 
			
		|||
package fr.organizee.service;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.security.authentication.AuthenticationManager;
 | 
			
		||||
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.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;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class
 | 
			
		||||
| 
						 | 
				
			
			@ -27,7 +26,7 @@ MembreServiceImpl implements MembreService {
 | 
			
		|||
    private BCryptPasswordEncoder passwordEncoder; // permet l'encodage du mot de passe
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private JwtTokenProvider jwtTokenProvider;	// permet la fourniture du Jeton (Token)
 | 
			
		||||
    private JwtTokenProvider jwtTokenProvider;    // permet la fourniture du Jeton (Token)
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AuthenticationManager authenticationManager; // gestionnaire d'authentification
 | 
			
		||||
| 
						 | 
				
			
			@ -59,6 +58,7 @@ MembreServiceImpl implements MembreService {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Membre> findAllUsers() {
 | 
			
		||||
        return membreRepository.findAll();
 | 
			
		||||
| 
						 | 
				
			
			@ -81,4 +81,3 @@ MembreServiceImpl implements MembreService {
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue