Merge branch 'main' of https://gitlab.com/marvin.epip/enchere
This commit is contained in:
@@ -48,9 +48,4 @@ public class AccueilController {
|
||||
return viewAccueil(searchTitle, searchCategory, model);
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
public String login(Model modele) {
|
||||
return "login";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import fr.eni.enchere.dal.UserRepository;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
public LoginController(UserService userService) {
|
||||
super();
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
public String login(Model modele) {
|
||||
return "security/login";
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public String login(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session) {
|
||||
UserProfil user = userService.utilisateurByName(username);
|
||||
System.out.println("test");
|
||||
if (user != null && user.getPassword().equals(password)) {
|
||||
return "redirect:/accueil";
|
||||
} else {
|
||||
return "redirect:/security/login?error";
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/main/java/fr/eni/enchere/controllers/MvcConfig.java
Normal file
12
src/main/java/fr/eni/enchere/controllers/MvcConfig.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/login").setViewName("security/login");
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,11 @@ public class ProfileController {
|
||||
// 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
|
||||
if (!authentication.getName().equals("anonymousUser")) { //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");
|
||||
UserProfil userProfile = userService.utilisateurByName(username);
|
||||
// Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML
|
||||
model.addAttribute("user", new UserProfil());
|
||||
model.addAttribute("userProfile", userProfile);
|
||||
@@ -47,7 +47,7 @@ public class ProfileController {
|
||||
// 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");
|
||||
UserProfil userProfile = userService.utilisateurByName(username);
|
||||
System.out.println(userProfile.getId());
|
||||
//Supprimer le compte
|
||||
userService.deleteUtilisateur(userProfile.getId());
|
||||
|
||||
Reference in New Issue
Block a user