Début de la page admin
This commit is contained in:
@@ -12,4 +12,5 @@ public interface UserService {
|
||||
List<String> listEmail();
|
||||
void setUtilisateur(UserProfil utilisateur);
|
||||
void deleteUtilisateur(int id);
|
||||
void disableUtilisateur(int id);
|
||||
}
|
||||
|
||||
@@ -49,4 +49,9 @@ public class UserServiceImpl implements UserService {
|
||||
public void deleteUtilisateur(int id) {
|
||||
userRepository.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableUtilisateur(int id) {
|
||||
userRepository.disable(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@ public class UserProfil {
|
||||
private String currentPassword;
|
||||
private String newPassword;
|
||||
private float credit;
|
||||
private boolean isDisabled;
|
||||
private boolean isAdmin;
|
||||
|
||||
//Constructeur
|
||||
public UserProfil(){}
|
||||
|
||||
public UserProfil(int id, String pseudo, String nom, String prenom, String email, String telephone, String rue, String code_postal, String ville, String password, String confirmPassword, String newPassword, String currentPassword, int credit, boolean isAdmin) {
|
||||
public UserProfil(int id, String pseudo, String nom, String prenom, String email, String telephone, String rue, String code_postal, String ville, String password, String confirmPassword, String newPassword, String currentPassword, int credit, boolean isDisabled, boolean isAdmin) {
|
||||
setId(id);
|
||||
setPrenom(prenom);
|
||||
setNom(nom);
|
||||
@@ -35,6 +36,7 @@ public class UserProfil {
|
||||
setPassword(password);
|
||||
setConfirmPassword(confirmPassword);
|
||||
setCredit(credit);
|
||||
setDisabled(isDisabled);
|
||||
setAdmin(isAdmin);
|
||||
setCurrentPassword(currentPassword);
|
||||
setNewPassword(newPassword);
|
||||
@@ -137,6 +139,14 @@ public class UserProfil {
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return isDisabled;
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
isDisabled = disabled;
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -7,11 +9,18 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
@Controller
|
||||
public class AdminController {
|
||||
|
||||
public AdminController() {
|
||||
private UserService userService;
|
||||
private CategorieService categorieService;
|
||||
|
||||
public AdminController(UserService userService, CategorieService categorieService) {
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
}
|
||||
|
||||
@GetMapping( "/admin")
|
||||
public String viewAdminPanel(Model model) {
|
||||
model.addAttribute("categories", categorieService.findAllCategories());
|
||||
//model.addAttribute("userProfil", userService.f);
|
||||
return "admin";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ public interface UserRepository {
|
||||
List<String> findAllEmail();
|
||||
void save(UserProfil utilisateur);
|
||||
void delete(int id);
|
||||
void disable(int id);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,8 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
public void save(UserProfil utilisateur) {
|
||||
if (utilisateur.getId() == 0) {
|
||||
//Création utilisateur
|
||||
String sql = "INSERT INTO UTILISATEURS (pseudo, nom, prenom, email, telephone, rue, code_postal, ville, mot_de_passe, credit, administrateur, isDelete) VALUES (:pseudo, :nom, :prenom, :email, :telephone, :rue, :code_postal, :ville, :mot_de_passe, 0, false, false)";
|
||||
String sql = "INSERT INTO UTILISATEURS (pseudo, nom, prenom, email, telephone, rue, code_postal, ville, mot_de_passe, credit, administrateur, isDisabled, isDelete) " +
|
||||
"VALUES (:pseudo, :nom, :prenom, :email, :telephone, :rue, :code_postal, :ville, :mot_de_passe, 0, false, false, false)";
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("pseudo", utilisateur.getPseudo());
|
||||
parameters.addValue("nom", utilisateur.getNom());
|
||||
@@ -107,12 +108,14 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
}
|
||||
}else {
|
||||
//Mettre à jour
|
||||
String sql = "UPDATE UTILISATEURS SET pseudo = :pseudo, nom = :nom, prenom = :prenom, email = :email, telephone = :telephone, rue = :rue, code_postal = :code_postal, ville = :ville, mot_de_passe = :mot_de_passe WHERE no_utilisateur = :id";
|
||||
String sql;
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
if(utilisateur.getNewPassword().isEmpty()){
|
||||
sql = "UPDATE UTILISATEURS SET pseudo = :pseudo, nom = :nom, prenom = :prenom, email = :email, telephone = :telephone, rue = :rue, code_postal = :code_postal, ville = :ville WHERE no_utilisateur = :id";
|
||||
sql = "UPDATE UTILISATEURS SET pseudo = :pseudo, nom = :nom, prenom = :prenom, email = :email, telephone = :telephone, rue = :rue, code_postal = :code_postal, ville = :ville " +
|
||||
"WHERE no_utilisateur = :id";
|
||||
}else{
|
||||
sql = "UPDATE UTILISATEURS SET pseudo = :pseudo, nom = :nom, prenom = :prenom, email = :email, telephone = :telephone, rue = :rue, code_postal = :code_postal, ville = :ville, mot_de_passe = :mot_de_passe WHERE no_utilisateur = :id";
|
||||
sql = "UPDATE UTILISATEURS SET pseudo = :pseudo, nom = :nom, prenom = :prenom, email = :email, telephone = :telephone, rue = :rue, code_postal = :code_postal," +
|
||||
" ville = :ville, mot_de_passe = :mot_de_passe WHERE no_utilisateur = :id";
|
||||
parameters.addValue("mot_de_passe", passwordEncoder.encode(utilisateur.getNewPassword()));
|
||||
}
|
||||
parameters.addValue("pseudo", utilisateur.getPseudo());
|
||||
@@ -134,4 +137,11 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
String sql = "UPDATE UTILISATEURS SET isDelete = 1 WHERE no_utilisateur = ?";
|
||||
jdbcTemplate.update(sql, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable(int id) {
|
||||
String sql = "UPDATE UTILISATEURS SET isDisabled = 1 WHERE no_utilisateur = ?";
|
||||
jdbcTemplate.update(sql, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public class WebSecurityConfig{
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user