Update permission accès
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/inscription")
|
||||
public class InscriptionController {
|
||||
|
||||
@Autowired
|
||||
private final UserService userService;
|
||||
|
||||
public InscriptionController(UserService userService) {
|
||||
@@ -27,6 +27,7 @@ public class InscriptionController {
|
||||
|
||||
@PostMapping("/newUser")
|
||||
public String setUser(@ModelAttribute UserProfil user) {
|
||||
//Ajouter vérification du formulaire -> @RequestParam("confirmPassword") String confirmPassword
|
||||
userService.setUtilisateur(user);
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import fr.eni.enchere.dal.UserRepository;
|
||||
import org.springframework.ui.Model;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
@Controller()
|
||||
@RequestMapping("/profile")
|
||||
@@ -19,7 +24,34 @@ public class ProfileController {
|
||||
|
||||
@GetMapping
|
||||
public String viewProfile(Model model) {
|
||||
model.addAttribute("user", new UserProfil());
|
||||
return "profile";
|
||||
// Obtenez l'authentification actuelle
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
// Vérifiez si l'utilisateur est authentifié
|
||||
if (!authentication.getName().equals("anonymousUser") || true) { //Retirer le true pour le bon fonctionnement
|
||||
// Obtenez les détails de l'utilisateur authentifié
|
||||
String username = authentication.getName();
|
||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||
UserProfil userProfile = userService.utilisateurByName("Jojo");
|
||||
// Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML
|
||||
model.addAttribute("user", new UserProfil());
|
||||
model.addAttribute("userProfile", userProfile);
|
||||
return "profile";
|
||||
}else {
|
||||
return "accueil";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public String setUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
// Obtenez les détails de l'utilisateur authentifié
|
||||
String username = authentication.getName();
|
||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||
UserProfil userProfile = userService.utilisateurByName("Jojo");
|
||||
System.out.println(userProfile.getId());
|
||||
//Supprimer le compte
|
||||
userService.deleteUtilisateur(userProfile.getId());
|
||||
//ATTENTION AJOUTER LA DECONNEXION
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user