Merge branch 'dev' of https://github.com/HediMjid/Organizee into Blandine

This commit is contained in:
Blandine Bajard 2022-03-01 17:45:58 +01:00
commit 057530cb29
6 changed files with 43 additions and 26 deletions

View file

@ -4,14 +4,12 @@ import fr.organizee.model.Mail;
import fr.organizee.service.SendMailService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.mail.MessagingException;
@RestController
@CrossOrigin("*")
@RequestMapping("/sendmail")
public class MailController {
SendMailService service;

View file

@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@ -219,14 +220,16 @@ public class MembreController {
/********************* Gestion Mot de Passe ************************************/
//cette methode ne fonctionne pas parce que ça affiche "trouvé" dans tous les cas
@GetMapping("/forgot-password")
@PostMapping("/forgot-password")
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> findUserByEmail(@RequestBody Membre findUserByEmail) {
public ResponseEntity<?> findUserByEmail(@RequestBody Membre membre) {
Membre resultMembre = null;
try {
this.membreService.findUserByEmail(findUserByEmail);
return ResponseEntity.status(HttpStatus.OK).body("Email trouvé !");
resultMembre = membreRepo.chercheEmail(membre.getEmail());
String uuid = UUID.randomUUID().toString();
resultMembre.setPassword(uuid);
membreRepo.saveAndFlush(resultMembre);
return ResponseEntity.status(HttpStatus.OK).body(uuid);
} catch (EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.OK).body("Email introuvable !");
@ -234,22 +237,14 @@ public class MembreController {
}
@PutMapping("/reset-password/{email}")
@PutMapping("/reset-password/{uuid}")
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> updatePassword(@RequestBody String password, @PathVariable String email) throws Exception {
Membre resultMembre;
public ResponseEntity<?> updatePassword(@RequestBody Membre membre, @PathVariable String uuid) throws Exception {
Membre resultMembre = null;
try {
resultMembre = this.membreService.chercheEmail(email);
System.out.println(resultMembre);
resultMembre.setPassword(passwordEncoder.encode(password));
System.out.println(password);
this.membreRepo.save(resultMembre);
System.out.println(resultMembre.getPassword());
resultMembre = membreRepo.findByUUID(uuid);
resultMembre.setPassword(passwordEncoder.encode(membre.getPassword()));
membreRepo.saveAndFlush(resultMembre);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}

View file

@ -1,6 +1,7 @@
package fr.organizee.controller;
import fr.organizee.model.TodoList;
import fr.organizee.model.Team;
import fr.organizee.repository.TodoListRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -19,6 +20,7 @@ public class TodoListController {
@Autowired
private TodoListRepository todolistRepo;
@GetMapping(value = "/all")
public ResponseEntity<?> getAll(){
List<TodoList> liste = null;
@ -32,6 +34,23 @@ public class TodoListController {
return ResponseEntity.status(HttpStatus.OK).body(liste);
}
//Ajoute une nouvelle ToDoList
@PostMapping(value="/add/{team_id}", produces="application/json", consumes= "application/json")
//@PreAuthorize("hasRole('ROLE_PARENT') or hasRole('ROLE_ENFANT')")
public ResponseEntity<?> addTodolist(@RequestBody TodoList todolist, @PathVariable Integer team_id) {
TodoList resultTodolist = null;
try {
Team team = new Team();
team.setId(team_id);
todolist.setTeam(team);
resultTodolist = todolistRepo.saveAndFlush(todolist);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultTodolist);
}
@DeleteMapping(value = "/delete/{id}")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteTodolist(@PathVariable int id){

View file

@ -21,6 +21,9 @@ public interface MembreRepository extends JpaRepository<Membre, Integer> {
Optional<Membre> findByEmail(String email);
@Query(value = "select * from membre where password = :uuid", nativeQuery = true)
Membre findByUUID(@Param("uuid") String uuid);
@Query(value = "select * from membre where email = :email", nativeQuery = true)
Membre chercheEmail(@Param("email") String email);

View file

@ -9,7 +9,8 @@ import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface TacheRepository extends JpaRepository<Tache, Integer> {
public interface
TacheRepository extends JpaRepository<Tache, Integer> {
// N'est plus utilisé normalement
@Query(value = "select * from todo_list, tache where todo_list.team_id = :team_id and todo_list.id = tache.todolist_id", nativeQuery = true)

View file

@ -17,7 +17,8 @@ import fr.organizee.repository.MembreRepository;
import fr.organizee.security.JwtTokenProvider;
@Service
public class MembreServiceImpl implements MembreService {
public class
MembreServiceImpl implements MembreService {
@Autowired
private MembreRepository membreRepository; // permet communication avec la BD