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