Fix user management routes, enhance user management page with a table, and add CSS for styling
This commit is contained in:
parent
ccc8be6bb1
commit
ee4b48354d
|
|
@ -1,16 +1,20 @@
|
||||||
package com.ieslamar.GestionInventario.controllers;
|
package com.ieslamar.GestionInventario.controllers;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ieslamar.GestionInventario.entities.User;
|
||||||
import com.ieslamar.GestionInventario.services.UserService;
|
import com.ieslamar.GestionInventario.services.UserService;
|
||||||
|
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.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
public UserController(UserService userService) {
|
public UserController(UserService userService) {
|
||||||
|
|
@ -42,8 +46,15 @@ public class UserController {
|
||||||
public String managementPage(){
|
public String managementPage(){
|
||||||
return "management";
|
return "management";
|
||||||
}
|
}
|
||||||
@GetMapping("/user_managemment")
|
// @GetMapping("/user_management")
|
||||||
public String userManagementPage(){
|
// public String userManagementPage(){
|
||||||
|
// return "user_management";
|
||||||
|
// }
|
||||||
|
|
||||||
|
@GetMapping("/user_management")
|
||||||
|
public String listUsers(Model model) {
|
||||||
|
List<User> users = userService.getAllUsers();
|
||||||
|
model.addAttribute("users", users);
|
||||||
return "user_management";
|
return "user_management";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||||
|
|
@ -23,7 +24,6 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
User user = userRepository.findByNombre(username)
|
User user = userRepository.findByNombre(username)
|
||||||
.orElseThrow(() -> new UsernameNotFoundException("Usuario no encontrado"));
|
.orElseThrow(() -> new UsernameNotFoundException("Usuario no encontrado"));
|
||||||
|
|
||||||
return new org.springframework.security.core.userdetails.User(
|
return new org.springframework.security.core.userdetails.User(
|
||||||
user.getNombre(),
|
user.getNombre(),
|
||||||
user.getPassword(),
|
user.getPassword(),
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@ package com.ieslamar.GestionInventario.services;
|
||||||
import com.ieslamar.GestionInventario.entities.Role;
|
import com.ieslamar.GestionInventario.entities.Role;
|
||||||
import com.ieslamar.GestionInventario.entities.User;
|
import com.ieslamar.GestionInventario.entities.User;
|
||||||
import com.ieslamar.GestionInventario.repos.UserRepository;
|
import com.ieslamar.GestionInventario.repos.UserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
|
@ -25,4 +27,7 @@ public class UserService {
|
||||||
user.setMail(mail);
|
user.setMail(mail);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
public List<User> getAllUsers() {
|
||||||
|
return userRepository.findAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,54 @@
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
margin: 0;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
width: 80%;
|
||||||
|
max-width: 800px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
thead {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
th, td {
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.footer {
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.id-column {
|
||||||
|
width: 50px; /* Columna ID más estrecha */
|
||||||
|
}
|
||||||
|
.email-column {
|
||||||
|
width: 250px; /* Columna Email más ancha */
|
||||||
|
}
|
||||||
|
.table-container {
|
||||||
|
height: 400px; /* Altura fija del contenedor */
|
||||||
|
overflow-y: auto; /* Scroll vertical */
|
||||||
|
border: 1px solid #ddd; /* Borde opcional */
|
||||||
|
}
|
||||||
|
.action-buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 10px; /* Espacio entre botones */
|
||||||
|
}
|
||||||
|
|
@ -7,11 +7,11 @@
|
||||||
<body>
|
<body>
|
||||||
<h2 th:text="'Gestión'"></h2>
|
<h2 th:text="'Gestión'"></h2>
|
||||||
<div class="container1">
|
<div class="container1">
|
||||||
<a href="/Inventario/user_managemment">
|
<a href="/Inventario/user_management">
|
||||||
<button>Gestión de Usuarios</button>
|
<button>Gestión de Usuarios</button>
|
||||||
</a>
|
</a>
|
||||||
<!-- TODO: Cambiar la ruta a la de gestionar inventario -->
|
<!-- TODO: Cambiar la ruta a la de gestionar inventario -->
|
||||||
<a href="/Inventario/user_managemment">
|
<a href="/Inventario/user_management">
|
||||||
<button>Gestión de Inventario</button>
|
<button>Gestión de Inventario</button>
|
||||||
</a>
|
</a>
|
||||||
<a href="/Inventario/home">
|
<a href="/Inventario/home">
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,27 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
|
<html lang="es" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<title>User management</title>
|
<title>Gestión de Usuarios</title>
|
||||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
<!-- <link rel="stylesheet" th:href="@{/css/table_style.css}">-->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2 th:text="'Gestión de usuarios'"></h2>
|
<h2>Gestión de Usuarios</h2>
|
||||||
<div class="container1">
|
<hr>
|
||||||
<a href="/Inventario/register">
|
<table border="1px">
|
||||||
<button>Registrar usuario</button>
|
<thead>
|
||||||
</a>
|
<tr>ID</tr>
|
||||||
<!-- TODO: modificar ruta-->
|
<tr>NOMBRE</tr>
|
||||||
<a href="/Inventario/register">
|
<tr>ROL</tr>
|
||||||
<button>Borrar usuario</button>
|
<tr>EMAIL</tr>
|
||||||
</a>
|
</thead>
|
||||||
<a href="/Inventario/home">
|
<tbody>
|
||||||
<button class="button_salir">Volver al inicio</button>
|
<tr th:each="user : ${users}">
|
||||||
</a>
|
<td th:number="${user.id}"></td>
|
||||||
</div>
|
</tr>
|
||||||
<!-- TODO: añadir botón para para editar usuarios -->
|
</tbody>
|
||||||
</body>
|
</table>
|
||||||
|
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue