merge
This commit is contained in:
@@ -31,6 +31,7 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
|
||||
implementation 'org.mariadb.jdbc:mariadb-java-client:2.2.0'
|
||||
compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
|
||||
//Mail
|
||||
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
||||
implementation 'jakarta.mail:jakarta.mail-api'
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
public interface ArticleService {
|
||||
|
||||
List<Article> findAllArticle();
|
||||
List<Article> findByUser(int id);
|
||||
Article findArticleById(int id);
|
||||
int saveArticle(Article article);
|
||||
void deleteArticle(int id);
|
||||
|
||||
@@ -22,6 +22,11 @@ public class ArticleServiceImpl implements ArticleService{
|
||||
return articleRepository.findAllArticle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Article> findByUser(int id) {
|
||||
return articleRepository.findByUser(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Article findArticleById(int id) {
|
||||
return articleRepository.findArticleById(id);
|
||||
|
||||
@@ -5,6 +5,7 @@ import fr.eni.enchere.bo.Enchere;
|
||||
import java.util.List;
|
||||
|
||||
public interface EnchereService {
|
||||
Enchere enchereByUserAndArticle(int idUser, int idArticle);
|
||||
List<Enchere> enchereByUser(int idUser);
|
||||
List<Enchere> enchereByArticle(int idArticle);
|
||||
void setEnchere(Enchere enchere);
|
||||
|
||||
12
src/main/java/fr/eni/enchere/bll/FileService.java
Normal file
12
src/main/java/fr/eni/enchere/bll/FileService.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package fr.eni.enchere.bll;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileService {
|
||||
|
||||
public boolean fileExists(String filePath) {
|
||||
return Files.exists(Paths.get(filePath));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,16 +10,18 @@ public class Enchere {
|
||||
private int noArticle;
|
||||
private Date dateEnchere;
|
||||
private float montantEnchere;
|
||||
private boolean isDelete;
|
||||
|
||||
public Enchere(){}
|
||||
|
||||
public Enchere(int id, int noUtilisateur, int noArticle, String pseudoUtilisateur, Date dateEnchere, float montantEnchere ) {
|
||||
public Enchere(boolean isDelete, int id, int noUtilisateur, int noArticle, String pseudoUtilisateur, Date dateEnchere, float montantEnchere ) {
|
||||
setId(id);
|
||||
setNoUtilisateur(noUtilisateur);
|
||||
setPseudoUtilisateur(pseudoUtilisateur);
|
||||
setNoArticle(noArticle);
|
||||
setDateEnchere(dateEnchere);
|
||||
setMontantEnchere(montantEnchere);
|
||||
setDelete(isDelete);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -69,4 +71,12 @@ public class Enchere {
|
||||
public void setPseudoUtilisateur(String pseudoUtilisateur) {
|
||||
this.pseudoUtilisateur = pseudoUtilisateur;
|
||||
}
|
||||
|
||||
public boolean isDelete() {
|
||||
return isDelete;
|
||||
}
|
||||
|
||||
public void setDelete(boolean delete) {
|
||||
isDelete = delete;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bll.UserServiceImpl;
|
||||
import fr.eni.enchere.bll.*;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
@@ -30,17 +28,19 @@ import java.util.Locale;
|
||||
@SessionAttributes({"searchTitle", "searchCategory", "venteOptions", "achatOptions", "typeTransaction"})
|
||||
public class AccueilController {
|
||||
|
||||
@Autowired
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccueilController.class);
|
||||
private ArticleService articleService;
|
||||
private CategorieService categorieService;
|
||||
private UserService userService;
|
||||
private FileService fileService;
|
||||
|
||||
|
||||
public AccueilController(ArticleService articleService, CategorieService categorieService, UserService userService) {
|
||||
public AccueilController(ArticleService articleService, CategorieService categorieService, UserService userService, FileService fileService) {
|
||||
super();
|
||||
this.categorieService = categorieService;
|
||||
this.articleService = articleService;
|
||||
this.userService = userService;
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.EnchereService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
import fr.eni.enchere.dal.UserRepositoryImpl;
|
||||
import fr.eni.enchere.bo.Enchere;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
|
||||
private final UserRepositoryImpl userRepositoryImpl;
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
private EnchereService enchereService;
|
||||
private UserService userService;
|
||||
private CategorieService categorieService;
|
||||
|
||||
public AdminController(UserService userService, CategorieService categorieService, UserRepositoryImpl userRepositoryImpl) {
|
||||
public AdminController(UserService userService, CategorieService categorieService, ArticleService articleService, EnchereService enchereService) {
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
this.userRepositoryImpl = userRepositoryImpl;
|
||||
this.articleService = articleService;
|
||||
this.enchereService = enchereService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -60,6 +69,16 @@ public class AdminController {
|
||||
@PostMapping("/delete")
|
||||
public String deleteUser(@RequestParam("userDelete") int id) {
|
||||
userService.deleteUtilisateur(id);
|
||||
//Annuler les ventes en cours
|
||||
List<Article> userArticles = articleService.findByUser(id);
|
||||
for (Article article : userArticles) {
|
||||
articleService.deleteArticle(article.getId());
|
||||
}
|
||||
//Annuler les enchères en cours
|
||||
List<Enchere> userEnchere = enchereService.enchereByUser(id);
|
||||
for (Enchere enchere : userEnchere) {
|
||||
enchereService.delete(enchere.getId());
|
||||
}
|
||||
return "redirect:/admin";
|
||||
}
|
||||
|
||||
@@ -69,8 +88,16 @@ public class AdminController {
|
||||
userService.enableUtilisateur(id);
|
||||
}else {
|
||||
userService.disableUtilisateur(id);
|
||||
//Désactiver tout
|
||||
|
||||
//Annuler les ventes en cours
|
||||
List<Article> userArticles = articleService.findByUser(id);
|
||||
for (Article article : userArticles) {
|
||||
articleService.deleteArticle(article.getId());
|
||||
}
|
||||
//Annuler les enchères en cours
|
||||
List<Enchere> userEnchere = enchereService.enchereByUser(id);
|
||||
for (Enchere enchere : userEnchere) {
|
||||
enchereService.delete(enchere.getId());
|
||||
}
|
||||
}
|
||||
return "redirect:/admin";
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ public class ArticleController {
|
||||
private RetraitService retraitService;
|
||||
private EnchereService enchereService;
|
||||
|
||||
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService, RetraitService retraitService, EnchereService enchereService) {
|
||||
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService,
|
||||
RetraitService retraitService, EnchereService enchereService) {
|
||||
this.articleService = articleService;
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
|
||||
@@ -2,15 +2,15 @@ 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;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/login")
|
||||
@@ -19,17 +19,17 @@ public class LoginController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
public LoginController(UserService userService) {
|
||||
super();
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@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";
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class LoginController {
|
||||
if (user != null && user.getPassword().equals(password)) {
|
||||
return "redirect:/enchere";
|
||||
} else {
|
||||
return "redirect:/security/login?error";
|
||||
return "redirect:/login?error";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.List;
|
||||
|
||||
public interface ArticleRepository {
|
||||
List<Article> findAllArticle();
|
||||
List<Article> findByUser(int id);
|
||||
Page<Article> searchArticlePageable(SearchArticleCritere critere, Pageable pageable);
|
||||
Article findArticleById(int id);
|
||||
List<Article> findArticleByTitle(String title);
|
||||
|
||||
@@ -90,6 +90,13 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
return articles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Article> findByUser(int id) {
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS WHERE no_utilisateur = ? AND isDelete = 0";
|
||||
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper(), id);
|
||||
return articles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Article> searchArticlePageable(SearchArticleCritere critere, Pageable pageable) {
|
||||
StringBuilder sql = new StringBuilder("SELECT DISTINCT a.*, u.* FROM ARTICLES_VENDUS a ");
|
||||
|
||||
@@ -5,6 +5,7 @@ import fr.eni.enchere.bo.Enchere;
|
||||
import java.util.List;
|
||||
|
||||
public interface EnchereRepository {
|
||||
Enchere findByIdUserAndIdArticle(int idUser, int idArticle);
|
||||
List<Enchere> findByIdUser(int idUser);
|
||||
List<Enchere> findByIdArticle(int idArticle);
|
||||
void save(Enchere enchere);
|
||||
|
||||
@@ -56,28 +56,28 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
@Override
|
||||
public UserProfil findByUsername(String username) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = ? OR email = ? AND isDelete = 0 AND isDisabled = 0";
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE (pseudo = ? OR email = ?) AND isDelete = 0 AND isDisabled = 0";
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), username, username);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfil findUserByEmail(String email) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE email = ? AND isDelete = 0 AND isDisabled = 0";
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE email = ? AND isDelete = 0";
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), email);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findAllUsernames() {
|
||||
String sql = "SELECT pseudo FROM UTILISATEURS WHERE isDelete = 0 AND isDisabled = 0";
|
||||
String sql = "SELECT pseudo FROM UTILISATEURS WHERE isDelete = 0 ";
|
||||
List<String> usernames = jdbcTemplate.queryForList(sql, String.class);
|
||||
return usernames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findAllEmail() {
|
||||
String sql = "SELECT email FROM UTILISATEURS WHERE isDelete = 0 AND isDisabled = 0";
|
||||
String sql = "SELECT email FROM UTILISATEURS WHERE isDelete = 0";
|
||||
List<String> email = jdbcTemplate.queryForList(sql, String.class);
|
||||
return email;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
@Override
|
||||
public String findByEmail(String email) {
|
||||
//Vérifie si un email existe dans la base et est valide
|
||||
String sql = "SELECT email FROM UTILISATEURS WHERE isDisabled = 0 AND email = ? AND isDelete = 0";
|
||||
String sql = "SELECT email FROM UTILISATEURS WHERE email = ? AND isDelete = 0";
|
||||
try {
|
||||
return jdbcTemplate.queryForObject(sql, new Object[]{email}, String.class);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
@@ -96,14 +96,14 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
@Override
|
||||
public List<UserProfil> findAll() {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE isDelete = 0 AND isDisabled = 0";
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE isDelete = 0";
|
||||
List<UserProfil> users = jdbcTemplate.query(sql, new UserRowMapper());
|
||||
return users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfil findById(int id) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE no_utilisateur = ? AND isDelete = 0 AND isDisabled = 0";
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE no_utilisateur = ? AND isDelete = 0";
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), id);
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ public class LoginService implements UserDetailsService {
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// Charger l'utilisateur depuis la base de données
|
||||
UserProfil utilisateur = this.userRep.findByUsername(username);
|
||||
UserDetails userDetails = null;
|
||||
// Créer un nouvel objet UserBuilder
|
||||
if (utilisateur != null) {
|
||||
userDetails = User.builder()
|
||||
.username(utilisateur.getPseudo())
|
||||
@@ -30,9 +28,9 @@ public class LoginService implements UserDetailsService {
|
||||
.roles(utilisateur.isAdmin() ? "ADMIN" : "MEMBRE")
|
||||
.build();
|
||||
} else {
|
||||
throw new UsernameNotFoundException("Les identifiants sont incorrect !");
|
||||
throw new UsernameNotFoundException("Les identifiants sont incorrects !");
|
||||
}
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -121,7 +121,8 @@
|
||||
<div class="card shadow-sm h-100 card-article">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4 d-flex align-items-center justify-content-center p-3">
|
||||
<img th:src="${'images/articles/' + article.id + '.jpg'} ? ${'images/articles/' + article.id + '.jpg'} : ${'images/articles/no-data.jpg'}" alt="Image de l'article" class="img-fluid rounded">
|
||||
<img th:if="${fileService.fileExists('/images/articles/' + article.id + '.jpg')}" th:src="@{/images/articles/{id}(id=${article.id})}" alt="Image de l'article" class="img-fluid rounded">
|
||||
<img th:unless="${fileService.fileExists('/images/articles/' + article.id + '.jpg')}" th:src="@{/images/articles/no-data.jpg}" alt="Image de l'article" class="img-fluid rounded">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body d-flex flex-column ">
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
<form th:action="@{/login}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Identifiant:</label>
|
||||
<input type="text" class="form-control" name="username" id="username" placeholder="Entrez votre identifiant">
|
||||
<input type="text" class="form-control" name="username" id="username" placeholder="Entrez votre identifiant" th:value="${savedUsername}"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Mot de passe:</label>
|
||||
<input type="password" class="form-control" name="password" id="password" placeholder="Entrez votre mot de passe">
|
||||
<input type="password" class="form-control" name="password" id="password" placeholder="Entrez votre mot de passe" th:value="${savedPassword}"/>
|
||||
</div>
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="remember-me" name="remember-me">
|
||||
|
||||
Reference in New Issue
Block a user