Merge pull request #18 from HediMjid/Blandine
sign-up + forgot-password + rester-pwd non complet
This commit is contained in:
commit
b6c5adb262
|
@ -13,6 +13,7 @@ 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.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
|
@ -32,6 +33,9 @@ public class MembreController {
|
|||
@Autowired
|
||||
private MembreService membreService;
|
||||
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder passwordEncoder;
|
||||
|
||||
// @Autowired
|
||||
// private TeamRepository teamRepo;
|
||||
|
||||
|
@ -66,6 +70,41 @@ public class MembreController {
|
|||
|
||||
}
|
||||
|
||||
@GetMapping("/forgot-password")
|
||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
||||
public ResponseEntity<?> findUserByEmail(@RequestBody Membre findUserByEmail)
|
||||
{
|
||||
try {
|
||||
|
||||
this.membreService.findUserByEmail(findUserByEmail);
|
||||
return ResponseEntity.ok("ok");
|
||||
} catch(Exception e)
|
||||
{
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/reset-password/{email}")
|
||||
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
|
||||
public ResponseEntity<?> updatePassword(@RequestBody String password, @PathVariable String email) throws Exception {
|
||||
Membre resultMembre;
|
||||
try {
|
||||
resultMembre = this.membreService.chercheEmail(email);
|
||||
|
||||
System.out.println(resultMembre);
|
||||
|
||||
resultMembre.setPassword(passwordEncoder.encode(password));
|
||||
|
||||
this.membreRepo.save(resultMembre);
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(resultMembre);
|
||||
}
|
||||
|
||||
|
||||
// @GetMapping(value = "/team/all")
|
||||
// public ResponseEntity<?> getAllTeam(){
|
||||
// List<Team> liste = null;
|
||||
|
|
|
@ -44,24 +44,16 @@ public class Membre {
|
|||
public Membre() {
|
||||
}
|
||||
|
||||
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) {
|
||||
public Membre(String nom, String prenom, LocalDate dateNaissance, Team team, @NotNull String email, @NotNull String password, List<Role> roleList) {
|
||||
this.nom = nom;
|
||||
this.prenom = prenom;
|
||||
this.dateNaissance = dateNaissance;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.isAdmin = isAdmin;
|
||||
this.couleur = couleur;
|
||||
this.smiley = smiley;
|
||||
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() {
|
||||
|
@ -114,22 +106,6 @@ public class Membre {
|
|||
this.team = team;
|
||||
}
|
||||
|
||||
public String getCouleur() {
|
||||
return couleur;
|
||||
}
|
||||
|
||||
public void setCouleur(String couleur) {
|
||||
this.couleur = couleur;
|
||||
}
|
||||
|
||||
public String getSmiley() {
|
||||
return smiley;
|
||||
}
|
||||
|
||||
public void setSmiley(String smiley) {
|
||||
this.smiley = smiley;
|
||||
}
|
||||
|
||||
public List<Role> getRoleList() {
|
||||
return roleList;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package fr.organizee.repository;
|
||||
|
||||
import fr.organizee.model.Contact;
|
||||
import fr.organizee.model.Membre;
|
||||
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
|
||||
|
@ -12,7 +16,12 @@ public interface MembreRepository extends JpaRepository<Membre, Integer> {
|
|||
|
||||
Optional<Membre> findByEmail(String email);
|
||||
|
||||
@Query(value = "select * from membre where email = :email", nativeQuery = true)
|
||||
Membre chercheEmail(@Param("email") String email);
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
void deleteByEmail(String email);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public interface MembreService {
|
|||
*/
|
||||
String signup(Membre membre) throws ExistingUsernameException;
|
||||
|
||||
|
||||
/**
|
||||
* Methode qui retourne tous les utilisateurs de la bd
|
||||
* @return the list of all application users.
|
||||
|
@ -40,6 +41,10 @@ public interface MembreService {
|
|||
* @param email the username to look for.
|
||||
* @return an Optional object containing user if found, empty otherwise.
|
||||
*/
|
||||
Optional<Membre> findUserByEmail(String email);
|
||||
Optional<Membre> findUserByEmail(Membre membre);
|
||||
Optional<Membre> findByEmail(String email);
|
||||
|
||||
Membre chercheEmail(String email);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class MembreServiceImpl implements MembreService {
|
|||
@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());
|
||||
Membre membreToSave = new Membre(membre.getNom(), membre.getPrenom(), membre.getDateNaissance(), membre.getTeam(), membre.getEmail(), passwordEncoder.encode(membre.getPassword()), membre.getRoleList());
|
||||
membreRepository.save(membreToSave);
|
||||
return jwtTokenProvider.createToken(membre.getEmail(), membre.getRoleList());
|
||||
} else {
|
||||
|
@ -62,8 +62,20 @@ public class MembreServiceImpl implements MembreService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Membre> findUserByEmail(String email) {
|
||||
return membreRepository.findByEmail(email);
|
||||
public Optional<Membre> findUserByEmail(Membre membre) {
|
||||
return this.membreRepository.findByEmail(membre.getEmail());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Membre> findByEmail(String email) {
|
||||
return this.membreRepository.findByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Membre chercheEmail(String email) {
|
||||
return this.membreRepository.chercheEmail(email);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue