patch fin projet v1
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,6 +32,7 @@ out/
|
|||||||
/dist/
|
/dist/
|
||||||
/nbdist/
|
/nbdist/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
|
/src/main/resources/logs/eni.log
|
||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ dependencies {
|
|||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
|
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
|
||||||
implementation 'org.mariadb.jdbc:mariadb-java-client:2.2.0'
|
implementation 'org.mariadb.jdbc:mariadb-java-client:2.2.0'
|
||||||
|
compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
|
||||||
//Mail
|
//Mail
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
||||||
implementation 'jakarta.mail:jakarta.mail-api'
|
implementation 'jakarta.mail:jakarta.mail-api'
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
public interface ArticleService {
|
public interface ArticleService {
|
||||||
|
|
||||||
List<Article> findAllArticle();
|
List<Article> findAllArticle();
|
||||||
|
List<Article> findByUser(int id);
|
||||||
Article findArticleById(int id);
|
Article findArticleById(int id);
|
||||||
int saveArticle(Article article);
|
int saveArticle(Article article);
|
||||||
void deleteArticle(int id);
|
void deleteArticle(int id);
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ public class ArticleServiceImpl implements ArticleService{
|
|||||||
return articleRepository.findAllArticle();
|
return articleRepository.findAllArticle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Article> findByUser(int id) {
|
||||||
|
return articleRepository.findByUser(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Article findArticleById(int id) {
|
public Article findArticleById(int id) {
|
||||||
return articleRepository.findArticleById(id);
|
return articleRepository.findArticleById(id);
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ public interface EnchereService {
|
|||||||
List<Enchere> enchereByUser(int idUser);
|
List<Enchere> enchereByUser(int idUser);
|
||||||
List<Enchere> enchereByArticle(int idArticle);
|
List<Enchere> enchereByArticle(int idArticle);
|
||||||
void setEnchere(Enchere enchere);
|
void setEnchere(Enchere enchere);
|
||||||
|
void delete(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,9 @@ public class EnchereServiceImpl implements EnchereService{
|
|||||||
public void setEnchere(Enchere enchere) {
|
public void setEnchere(Enchere enchere) {
|
||||||
enchereRepository.save(enchere);
|
enchereRepository.save(enchere);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(int id) {
|
||||||
|
enchereRepository.deleteArticle(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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,15 +10,17 @@ public class Enchere {
|
|||||||
private int noArticle;
|
private int noArticle;
|
||||||
private Date dateEnchere;
|
private Date dateEnchere;
|
||||||
private float montantEnchere;
|
private float montantEnchere;
|
||||||
|
private boolean isDelete;
|
||||||
|
|
||||||
public Enchere(){}
|
public Enchere(){}
|
||||||
|
|
||||||
public Enchere(int noUtilisateur, int noArticle, String pseudoUtilisateur, Date dateEnchere, float montantEnchere ) {
|
public Enchere(int noUtilisateur, int noArticle, String pseudoUtilisateur, Date dateEnchere, float montantEnchere, boolean isDelete) {
|
||||||
setNoUtilisateur(noUtilisateur);
|
setNoUtilisateur(noUtilisateur);
|
||||||
setPseudoUtilisateur(pseudoUtilisateur);
|
setPseudoUtilisateur(pseudoUtilisateur);
|
||||||
setNoArticle(noArticle);
|
setNoArticle(noArticle);
|
||||||
setDateEnchere(dateEnchere);
|
setDateEnchere(dateEnchere);
|
||||||
setMontantEnchere(montantEnchere);
|
setMontantEnchere(montantEnchere);
|
||||||
|
setDelete(isDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@@ -68,4 +70,12 @@ public class Enchere {
|
|||||||
public void setPseudoUtilisateur(String pseudoUtilisateur) {
|
public void setPseudoUtilisateur(String pseudoUtilisateur) {
|
||||||
this.pseudoUtilisateur = 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;
|
package fr.eni.enchere.controllers;
|
||||||
|
|
||||||
import fr.eni.enchere.bll.ArticleService;
|
import fr.eni.enchere.bll.*;
|
||||||
import fr.eni.enchere.bll.CategorieService;
|
|
||||||
import fr.eni.enchere.bll.UserService;
|
|
||||||
import fr.eni.enchere.bll.UserServiceImpl;
|
|
||||||
import fr.eni.enchere.bo.Article;
|
import fr.eni.enchere.bo.Article;
|
||||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
@@ -30,17 +28,19 @@ import java.util.Locale;
|
|||||||
@SessionAttributes({"searchTitle", "searchCategory", "venteOptions", "achatOptions", "typeTransaction"})
|
@SessionAttributes({"searchTitle", "searchCategory", "venteOptions", "achatOptions", "typeTransaction"})
|
||||||
public class AccueilController {
|
public class AccueilController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AccueilController.class);
|
private static final Logger logger = LoggerFactory.getLogger(AccueilController.class);
|
||||||
private ArticleService articleService;
|
private ArticleService articleService;
|
||||||
private CategorieService categorieService;
|
private CategorieService categorieService;
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
|
public AccueilController(ArticleService articleService, CategorieService categorieService, UserService userService, FileService fileService) {
|
||||||
public AccueilController(ArticleService articleService, CategorieService categorieService, UserService userService) {
|
|
||||||
super();
|
super();
|
||||||
this.categorieService = categorieService;
|
this.categorieService = categorieService;
|
||||||
this.articleService = articleService;
|
this.articleService = articleService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.fileService = fileService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,34 @@
|
|||||||
package fr.eni.enchere.controllers;
|
package fr.eni.enchere.controllers;
|
||||||
|
|
||||||
|
import fr.eni.enchere.bll.ArticleService;
|
||||||
import fr.eni.enchere.bll.CategorieService;
|
import fr.eni.enchere.bll.CategorieService;
|
||||||
|
import fr.eni.enchere.bll.EnchereService;
|
||||||
import fr.eni.enchere.bll.UserService;
|
import fr.eni.enchere.bll.UserService;
|
||||||
|
import fr.eni.enchere.bo.Article;
|
||||||
import fr.eni.enchere.bo.Categorie;
|
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.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/admin")
|
@RequestMapping("/admin")
|
||||||
public class AdminController {
|
public class AdminController {
|
||||||
|
|
||||||
private final UserRepositoryImpl userRepositoryImpl;
|
@Autowired
|
||||||
|
private ArticleService articleService;
|
||||||
|
private EnchereService enchereService;
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
private CategorieService categorieService;
|
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.userService = userService;
|
||||||
this.categorieService = categorieService;
|
this.categorieService = categorieService;
|
||||||
this.userRepositoryImpl = userRepositoryImpl;
|
this.articleService = articleService;
|
||||||
|
this.enchereService = enchereService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@@ -60,6 +69,16 @@ public class AdminController {
|
|||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public String deleteUser(@RequestParam("userDelete") int id) {
|
public String deleteUser(@RequestParam("userDelete") int id) {
|
||||||
userService.deleteUtilisateur(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";
|
return "redirect:/admin";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +88,16 @@ public class AdminController {
|
|||||||
userService.enableUtilisateur(id);
|
userService.enableUtilisateur(id);
|
||||||
}else {
|
}else {
|
||||||
userService.disableUtilisateur(id);
|
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";
|
return "redirect:/admin";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ public class ArticleController {
|
|||||||
private RetraitService retraitService;
|
private RetraitService retraitService;
|
||||||
private EnchereService enchereService;
|
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.articleService = articleService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.categorieService = categorieService;
|
this.categorieService = categorieService;
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ 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 jakarta.servlet.http.Cookie;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/login")
|
@RequestMapping("/login")
|
||||||
@@ -19,17 +19,17 @@ public class LoginController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
public LoginController(UserService userService) {
|
|
||||||
super();
|
|
||||||
this.userService = userService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String login(Model modele) {
|
public String login(Model modele) {
|
||||||
|
//Début cookie
|
||||||
|
String savedUsername = "";
|
||||||
|
String savedPassword = "";
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
if (!authentication.getName().equals("anonymousUser")){
|
if (!authentication.getName().equals("anonymousUser")){
|
||||||
return "redirect:/enchere";
|
return "redirect:/enchere";
|
||||||
}
|
}
|
||||||
|
modele.addAttribute("savedUsername", savedUsername);
|
||||||
|
modele.addAttribute("savedPassword", savedPassword);
|
||||||
return "security/login";
|
return "security/login";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +39,8 @@ public class LoginController {
|
|||||||
if (user != null && user.getPassword().equals(password)) {
|
if (user != null && user.getPassword().equals(password)) {
|
||||||
return "redirect:/enchere";
|
return "redirect:/enchere";
|
||||||
} else {
|
} else {
|
||||||
return "redirect:/security/login?error";
|
return "redirect:/login?error";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ArticleRepository {
|
public interface ArticleRepository {
|
||||||
List<Article> findAllArticle();
|
List<Article> findAllArticle();
|
||||||
|
List<Article> findByUser(int id);
|
||||||
Page<Article> searchArticlePageable(SearchArticleCritere critere, Pageable pageable);
|
Page<Article> searchArticlePageable(SearchArticleCritere critere, Pageable pageable);
|
||||||
Article findArticleById(int id);
|
Article findArticleById(int id);
|
||||||
List<Article> findArticleByTitle(String title);
|
List<Article> findArticleByTitle(String title);
|
||||||
|
|||||||
@@ -90,6 +90,13 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
|||||||
return articles;
|
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
|
@Override
|
||||||
public Page<Article> searchArticlePageable(SearchArticleCritere critere, Pageable pageable) {
|
public Page<Article> searchArticlePageable(SearchArticleCritere critere, Pageable pageable) {
|
||||||
StringBuilder sql = new StringBuilder("SELECT DISTINCT a.*, u.* FROM ARTICLES_VENDUS a ");
|
StringBuilder sql = new StringBuilder("SELECT DISTINCT a.*, u.* FROM ARTICLES_VENDUS a ");
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ public interface EnchereRepository {
|
|||||||
List<Enchere> findByIdUser(int idUser);
|
List<Enchere> findByIdUser(int idUser);
|
||||||
List<Enchere> findByIdArticle(int idArticle);
|
List<Enchere> findByIdArticle(int idArticle);
|
||||||
void save(Enchere enchere);
|
void save(Enchere enchere);
|
||||||
|
void deleteArticle(int idArticle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ public class EnchereRepositoryImpl implements EnchereRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Enchere> findByIdUser(int idUser) {
|
public List<Enchere> findByIdUser(int idUser) {
|
||||||
return List.of();
|
String sql = "SELECT * FROM ENCHERES WHERE no_utilisateur = ? AND isDelete = 0";
|
||||||
|
List<Enchere> encheres = jdbcTemplate.query(sql, new EnchereRowMapper(), idUser);
|
||||||
|
return encheres;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,4 +67,10 @@ public class EnchereRepositoryImpl implements EnchereRepository {
|
|||||||
enchere.setId(keyHolder.getKey().intValue());
|
enchere.setId(keyHolder.getKey().intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteArticle(int idArticle) {
|
||||||
|
String sql = "UPDATE ENCHERES SET isDelete = 1 WHERE id = ?";
|
||||||
|
jdbcTemplate.update(sql, idArticle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,28 +56,28 @@ public class UserRepositoryImpl implements UserRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfil findByUsername(String username) {
|
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);
|
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), username, username);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfil findUserByEmail(String email) {
|
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);
|
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), email);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> findAllUsernames() {
|
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);
|
List<String> usernames = jdbcTemplate.queryForList(sql, String.class);
|
||||||
return usernames;
|
return usernames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> findAllEmail() {
|
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);
|
List<String> email = jdbcTemplate.queryForList(sql, String.class);
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ public class UserRepositoryImpl implements UserRepository {
|
|||||||
@Override
|
@Override
|
||||||
public String findByEmail(String email) {
|
public String findByEmail(String email) {
|
||||||
//Vérifie si un email existe dans la base et est valide
|
//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 {
|
try {
|
||||||
return jdbcTemplate.queryForObject(sql, new Object[]{email}, String.class);
|
return jdbcTemplate.queryForObject(sql, new Object[]{email}, String.class);
|
||||||
} catch (EmptyResultDataAccessException e) {
|
} catch (EmptyResultDataAccessException e) {
|
||||||
@@ -96,14 +96,14 @@ public class UserRepositoryImpl implements UserRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserProfil> findAll() {
|
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());
|
List<UserProfil> users = jdbcTemplate.query(sql, new UserRowMapper());
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfil findById(int id) {
|
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);
|
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), id);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ public class LoginService implements UserDetailsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
// Charger l'utilisateur depuis la base de données
|
|
||||||
UserProfil utilisateur = this.userRep.findByUsername(username);
|
UserProfil utilisateur = this.userRep.findByUsername(username);
|
||||||
UserDetails userDetails = null;
|
UserDetails userDetails = null;
|
||||||
// Créer un nouvel objet UserBuilder
|
|
||||||
if (utilisateur != null) {
|
if (utilisateur != null) {
|
||||||
userDetails = User.builder()
|
userDetails = User.builder()
|
||||||
.username(utilisateur.getPseudo())
|
.username(utilisateur.getPseudo())
|
||||||
@@ -30,9 +28,9 @@ public class LoginService implements UserDetailsService {
|
|||||||
.roles(utilisateur.isAdmin() ? "ADMIN" : "MEMBRE")
|
.roles(utilisateur.isAdmin() ? "ADMIN" : "MEMBRE")
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
throw new UsernameNotFoundException("Les identifiants sont incorrect !");
|
throw new UsernameNotFoundException("Les identifiants sont incorrects !");
|
||||||
}
|
}
|
||||||
return userDetails;
|
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="card shadow-sm h-100 card-article">
|
||||||
<div class="row g-0">
|
<div class="row g-0">
|
||||||
<div class="col-md-4 d-flex align-items-center justify-content-center p-3">
|
<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>
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div class="card-body d-flex flex-column ">
|
<div class="card-body d-flex flex-column ">
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
<form th:action="@{/login}" method="post">
|
<form th:action="@{/login}" method="post">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="username" class="form-label">Identifiant:</label>
|
<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>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="password" class="form-label">Mot de passe:</label>
|
<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>
|
||||||
<div class="mb-3 form-check">
|
<div class="mb-3 form-check">
|
||||||
<input type="checkbox" class="form-check-input" id="remember-me" name="remember-me">
|
<input type="checkbox" class="form-check-input" id="remember-me" name="remember-me">
|
||||||
|
|||||||
Reference in New Issue
Block a user