merge conflict
This commit is contained in:
@@ -14,4 +14,7 @@ public interface UserService {
|
||||
void setCredit(float credit, int id);
|
||||
void deleteUtilisateur(int id);
|
||||
void disableUtilisateur(int id);
|
||||
void enableUtilisateur(int id);
|
||||
void onAdminUtilisateur(int id);
|
||||
void offAdminUtilisateur(int id);
|
||||
}
|
||||
|
||||
@@ -59,4 +59,19 @@ public class UserServiceImpl implements UserService {
|
||||
public void disableUtilisateur(int id) {
|
||||
userRepository.disable(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableUtilisateur(int id) {
|
||||
userRepository.enable(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdminUtilisateur(int id) {
|
||||
userRepository.onAdmin(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offAdminUtilisateur(int id) {
|
||||
userRepository.offAdmin(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import org.apache.commons.validator.routines.EmailValidator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.web.context.request.RequestContextListener;
|
||||
import org.springframework.web.filter.RequestContextFilter;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
@@ -53,4 +56,5 @@ public class WebConfig {
|
||||
public RequestContextFilter requestContextFilter() {
|
||||
return new RequestContextFilter();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
import fr.eni.enchere.bo.Retrait;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import fr.eni.enchere.dal.UserRepositoryImpl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -17,12 +18,14 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
|
||||
private final UserRepositoryImpl userRepositoryImpl;
|
||||
private UserService userService;
|
||||
private CategorieService categorieService;
|
||||
|
||||
public AdminController(UserService userService, CategorieService categorieService) {
|
||||
public AdminController(UserService userService, CategorieService categorieService, UserRepositoryImpl userRepositoryImpl) {
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
this.userRepositoryImpl = userRepositoryImpl;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -67,8 +70,22 @@ public class AdminController {
|
||||
}
|
||||
|
||||
@PostMapping("/disabled")
|
||||
public String disabledUser(@RequestParam("userDisabled") int id) {
|
||||
userService.disableUtilisateur(id);
|
||||
public String disabledUser(@RequestParam("userDisabled") int id, @RequestParam("isDis") boolean isDis) {
|
||||
if (isDis){
|
||||
userService.enableUtilisateur(id);
|
||||
}else {
|
||||
userService.disableUtilisateur(id);
|
||||
}
|
||||
return "redirect:/admin";
|
||||
}
|
||||
|
||||
@PostMapping("/administrateur")
|
||||
public String administrateurUser(@RequestParam("userAdmin") int id, @RequestParam("isAdmin") boolean isAdmin) {
|
||||
if (isAdmin){
|
||||
userService.offAdminUtilisateur(id);
|
||||
}else {
|
||||
userService.onAdminUtilisateur(id);
|
||||
}
|
||||
return "redirect:/admin";
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,7 @@ public interface UserRepository {
|
||||
void updateCredit(float credit, int id);
|
||||
void delete(int id);
|
||||
void disable(int id);
|
||||
void enable(int id);
|
||||
void onAdmin(int id);
|
||||
void offAdmin(int id);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
userProfile.setPassword(rs.getString("mot_de_passe"));
|
||||
userProfile.setCredit(rs.getFloat("credit"));
|
||||
userProfile.setAdmin(rs.getBoolean("administrateur"));
|
||||
userProfile.setDisabled(rs.getBoolean("isDisabled"));
|
||||
return userProfile;
|
||||
}
|
||||
}
|
||||
@@ -152,4 +153,22 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
jdbcTemplate.update(sql, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(int id) {
|
||||
String sql = "UPDATE UTILISATEURS SET isDisabled = 0 WHERE no_utilisateur = ?";
|
||||
jdbcTemplate.update(sql, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdmin(int id) {
|
||||
String sql = "UPDATE UTILISATEURS SET administrateur = 1 WHERE no_utilisateur = ?";
|
||||
jdbcTemplate.update(sql, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offAdmin(int id) {
|
||||
String sql = "UPDATE UTILISATEURS SET administrateur = 0 WHERE no_utilisateur = ?";
|
||||
jdbcTemplate.update(sql, id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,17 +55,37 @@
|
||||
<td th:text="${user.nom}"></td>
|
||||
<td th:text="${user.prenom}"></td>
|
||||
<td th:text="${user.email}"></td>
|
||||
<td>
|
||||
<form th:action="@{/admin/disabled}" method="post">
|
||||
<input type="hidden" name="userDisabled" id="userDisabled" th:value="${user.id}">
|
||||
<button th:text="#{admin.users.table.disable}">Désactiver</button>
|
||||
</form>
|
||||
<form th:action="@{/admin/delete}" method="post">
|
||||
<input type="hidden" name="userDelete" id="userDelete" th:value="${user.id}">
|
||||
<button th:text="#{admin.users.table.delete}">Supprimer</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<tr th:each="user : ${userProfil}">
|
||||
<td th:text="${user.id}"></td>
|
||||
<td th:text="${user.pseudo}"></td>
|
||||
<td th:text="${user.nom}"></td>
|
||||
<td th:text="${user.prenom}"></td>
|
||||
<td th:text="${user.email}"></td>
|
||||
<td>
|
||||
<form th:action="@{/admin/update/credit}" method="post">
|
||||
<input type="number" name="newCredit" id="newCredit" th:value="${user.credit}">
|
||||
<input type="hidden" name="idUser" id="idUser" th:value="${user.id}">
|
||||
<button>Sauvegarder</button>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<form th:action="@{/admin/disabled}" method="post">
|
||||
<input type="hidden" name="userDisabled" id="userDisabled" th:value="${user.id}">
|
||||
<input type="hidden" name="isDis" id="isDis" th:value="${user.isDisabled}">
|
||||
<button th:text="${user.isDisabled} ? 'Activer' : 'Désactiver'"></button>
|
||||
</form>
|
||||
<form th:action="@{/admin/delete}" method="post">
|
||||
<input type="hidden" name="userDelete" id="userDelete" th:value="${user.id}">
|
||||
<button>Supprimer</button>
|
||||
</form>
|
||||
<form th:action="@{/admin/administrateur}" method="post">
|
||||
<input type="hidden" name="userAdmin" id="userAdmin" th:value="${user.id}">
|
||||
<input type="hidden" name="isAdmin" id="isAdmin" th:value="${user.admin}">
|
||||
<button th:text="${user.admin} ? 'Retirer admin' : 'Ajouter admin'"></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user