Merge branch 'Olivier'
This commit is contained in:
@@ -2,8 +2,6 @@ package fr.eni.enchere.controllers;
|
|||||||
|
|
||||||
import fr.eni.enchere.bll.UserService;
|
import fr.eni.enchere.bll.UserService;
|
||||||
import fr.eni.enchere.bo.UserProfil;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
@@ -28,9 +26,8 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public String login(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session) {
|
public String login(@RequestParam("username") String username, @RequestParam("password") String password) {
|
||||||
UserProfil user = userService.utilisateurByName(username);
|
UserProfil user = userService.utilisateurByName(username);
|
||||||
System.out.println("test");
|
|
||||||
if (user != null && user.getPassword().equals(password)) {
|
if (user != null && user.getPassword().equals(password)) {
|
||||||
return "redirect:/accueil";
|
return "redirect:/accueil";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class ProfileController {
|
|||||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||||
UserProfil userProfile = userService.utilisateurByName(username);
|
UserProfil userProfile = userService.utilisateurByName(username);
|
||||||
// Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML
|
// Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML
|
||||||
model.addAttribute("user", new UserProfil());
|
// model.addAttribute("user", new UserProfil());
|
||||||
model.addAttribute("userProfile", userProfile);
|
model.addAttribute("userProfile", userProfile);
|
||||||
return "profile";
|
return "profile";
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.List;
|
|||||||
public interface UserRepository {
|
public interface UserRepository {
|
||||||
List<UserProfil> findAll();
|
List<UserProfil> findAll();
|
||||||
UserProfil findById(int id);
|
UserProfil findById(int id);
|
||||||
UserProfil findByUsername(String username);
|
UserProfil findByUsername(String username, String email);
|
||||||
void save(UserProfil utilisateur);
|
void save(UserProfil utilisateur);
|
||||||
void delete(int id);
|
void delete(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||||
import org.springframework.jdbc.support.KeyHolder;
|
import org.springframework.jdbc.support.KeyHolder;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@@ -58,11 +57,16 @@ public class UserRepositoryImpl implements UserRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfil findByUsername(String username) {
|
public UserProfil findByUsername(String username, String email) {
|
||||||
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username AND isDelete = 0";
|
UserProfil user = null;
|
||||||
Map<String, Object> params = new HashMap<>();
|
if (username != null) {
|
||||||
params.put("username", username);
|
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = ? AND isDelete = 0";
|
||||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), params);
|
user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), username);
|
||||||
|
} else if (email != null) {
|
||||||
|
String sql = "SELECT * FROM UTILISATEURS WHERE email = ? AND isDelete = 0";
|
||||||
|
user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), email);
|
||||||
|
}
|
||||||
|
System.out.println(user.getPassword());
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
@@ -16,14 +15,16 @@ public class WebSecurityConfig{
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http.authorizeHttpRequests((requests) -> requests.requestMatchers("/", "/accueil").permitAll()
|
http.authorizeHttpRequests((requests) -> requests
|
||||||
.requestMatchers("/login").permitAll()
|
.requestMatchers("/", "/accueil").permitAll()
|
||||||
|
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/profile/**").permitAll()
|
||||||
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
||||||
.requestMatchers("/article/**").authenticated()
|
.requestMatchers("/article/**").authenticated()
|
||||||
.requestMatchers("/admin").hasRole("ADMIN")
|
.requestMatchers("/admin").hasRole("ADMIN")
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
||||||
.logout((logout) -> logout.clearAuthentication(true).invalidateHttpSession(true).deleteCookies("JSESSIONID").logoutSuccessUrl("/filmLogout")
|
.logout((logout) -> logout.clearAuthentication(true).invalidateHttpSession(true)
|
||||||
|
.deleteCookies("JSESSIONID").logoutSuccessUrl("/logout")
|
||||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll());
|
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll());
|
||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
|
|||||||
Reference in New Issue
Block a user