merge
This commit is contained in:
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.Phonenumber;
|
||||
import fr.eni.enchere.security.LoginService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.commons.validator.routines.EmailValidator;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -37,17 +36,15 @@ public class InscriptionController {
|
||||
|
||||
@Autowired
|
||||
private final UserService userService;
|
||||
private LoginService loginService;
|
||||
private PasswordEncoder passwordEncoder;
|
||||
private EmailValidator emailValidator;
|
||||
private PhoneNumberUtil phoneValidator;
|
||||
|
||||
public InscriptionController(UserService userService, PasswordEncoder passwordEncoder, EmailValidator emailValidator, PhoneNumberUtil phoneValidator, LoginService loginService) {
|
||||
public InscriptionController(UserService userService, PasswordEncoder passwordEncoder, EmailValidator emailValidator, PhoneNumberUtil phoneValidator) {
|
||||
this.userService = userService;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.emailValidator = emailValidator;
|
||||
this.phoneValidator = phoneValidator;
|
||||
this.loginService = loginService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -22,25 +18,11 @@ public class LoginController {
|
||||
@GetMapping
|
||||
public String login(Model modele) {
|
||||
//Début cookie
|
||||
String savedUsername = "";
|
||||
String savedPassword = "";
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (!authentication.getName().equals("anonymousUser")){
|
||||
return "redirect:/enchere";
|
||||
}
|
||||
modele.addAttribute("savedUsername", savedUsername);
|
||||
modele.addAttribute("savedPassword", savedPassword);
|
||||
return "security/login";
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
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:/enchere";
|
||||
} else {
|
||||
return "redirect:/login?error";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@ import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Component
|
||||
|
||||
@Service
|
||||
public class LoginService implements UserDetailsService {
|
||||
|
||||
private UserRepository userRep;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package fr.eni.enchere.security;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
// @Bean
|
||||
// public PasswordEncoder passwordEncoder() {
|
||||
// return new BCryptPasswordEncoder();
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -4,12 +4,12 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig {
|
||||
@@ -25,6 +25,11 @@ public class WebSecurityConfig {
|
||||
.formLogin((form) -> form
|
||||
.loginPage("/login")
|
||||
.defaultSuccessUrl("/enchere", true))
|
||||
.rememberMe(rememberMe -> rememberMe
|
||||
.key("secretKey")
|
||||
.rememberMeParameter("remember-me")
|
||||
.tokenValiditySeconds(604800)
|
||||
.rememberMeCookieName("remember-me"))
|
||||
.logout((logout) -> logout
|
||||
.clearAuthentication(true).invalidateHttpSession(true)
|
||||
.deleteCookies("JSESSIONID").logoutSuccessUrl("/enchere")
|
||||
|
||||
Reference in New Issue
Block a user