Files
ENI-enchere/src/main/java/fr/eni/enchere/controllers/LoginController.java
Parpaillax aa25617c81 patch
2024-04-23 16:36:35 +02:00

38 lines
1.1 KiB
Java

package fr.eni.enchere.controllers;
import fr.eni.enchere.bll.UserService;
import fr.eni.enchere.bo.UserProfil;
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) {
UserProfil user = userService.utilisateurByName(username);
if (user != null && user.getPassword().equals(password)) {
return "redirect:/accueil";
} else {
return "redirect:/security/login?error";
}
}
}