Cambiando css de html y he encotrado un fallo en editar el alumno, falta revisar el metodo isValid en buscador alumno y administrador

master
vicsash 4 months ago
parent 4883c6e2ed
commit 0509a2240b

@ -1,5 +1,7 @@
package com.example.proyectofinal.controllers;
import com.example.proyectofinal.models.login.Usuario;
import com.example.proyectofinal.repositories.login.UserRepository;
import com.example.proyectofinal.servicios.user.UsuarioService;
import jakarta.annotation.security.RolesAllowed;
import jakarta.servlet.http.HttpServletRequest;
@ -10,26 +12,33 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Optional;
@Controller
public class LogOutController {
@Autowired
private UsuarioService usuarioService;
@Autowired
private UserRepository userRepository;
private static final Logger logger = LoggerFactory.getLogger(LogOutController.class);
@RolesAllowed({"ADMIN","USER"})
@RequestMapping("/logout")
public String logout(HttpServletRequest request) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
String nombreLogIn = auth.getName();
logger.info("Logging out user: " + nombreLogIn);
usuarioService.logout(nombreLogIn);
new SecurityContextLogoutHandler().logout(request, null, null);
@Transactional
public void logout(String nombreLogIn) {
Optional<Usuario> optionalUsuario = userRepository.findByNombreUsuario(nombreLogIn);
if (optionalUsuario.isPresent()) {
Usuario usuario = optionalUsuario.get();
logger.info("Resetting loggedIn status for user: " + nombreLogIn);
userRepository.resetLogedIn(usuario.getId());
} else {
// handle the situation where the user does not exist, e.g., show an error message
logger.error("User not found: " + nombreLogIn);
}
return "redirect:/login?logout";
}
}

@ -43,6 +43,7 @@ public class UserController {
@GetMapping("/usuario/alu_update_form")
public String showUpdateForm(Model model, Authentication authentication) {
System.out.println("TEST UPDATE FORM");
String username = authentication.getName();
Usuario usuario = usuarioService.findByLogInName(username);
Alumno alumno = alumnoService.findByEmail(usuario.getEmail());
@ -51,7 +52,7 @@ public class UserController {
model.addAttribute("skills", skills);
model.addAttribute("alumno", alumno);
model.addAttribute("ciclos", ciclos);
return "admin/alumno/update";
return "user/update_alu";
}
@ -62,7 +63,15 @@ public class UserController {
Set<Skill> skillEntities = skillService.findAllByIds(skills);
alumno.setCiclo(cicloEntity);
alumno.setSkills(skillEntities);
//System.out.println("TEST UPDATE ALUMNO: "+alumno.getNombre());
Alumno existingAlumno = alumnoService.findById(alumno.getId());
if (!existingAlumno.equals(alumno)) {
Usuario usuario = usuarioService.findByEmail(existingAlumno.getCorreo());
if (usuario != null) {
usuario.setEmail(alumno.getCorreo());
usuarioService.saveUser(usuario);
}
}
alumnoService.save(alumno);
return new ResponseEntity<>("El alumno fue actualizado con exito", HttpStatus.OK);
}catch (Exception e) {
@ -84,17 +93,18 @@ public class UserController {
if (existingUser == null) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Este usuario no existe");
}
// Check if the password field is empty
if (usuario.getPassword().isEmpty()) {
// If the password field is empty, keep the original password
usuario.setPassword(existingUser.getPassword());
} else {
// If the password field is not empty, encrypt the new password
String password = usuario.getPassword();
existingUser.setPassword(passwordEncoder.encode(password));
}
usuario.setRol(usuarioService.getRolById(2));
//System.out.println("TEST UPDATE USUARIO: "+usuario.getNombreUsuario());
Alumno alumno = alumnoService.findByEmail(existingUser.getEmail());
if (alumno != null) {
alumno.setCorreo(usuario.getEmail());
alumnoService.save(alumno);
}
usuarioService.saveUser(usuario);
return "redirect:/buscador?userUpdated=true";
}

@ -126,6 +126,34 @@ public class AlumnoController {
alumno.setSkills(skillEntities);
assert keywords != null;
alumno.setKeywords(keywords);
// Fetch the existing Alumno from the database
Alumno existingAlumno = alumnoService.findById(alumno.getId());
if (!existingAlumno.equals(alumno)) {
Usuario usuario = usuarioService.findByEmail(existingAlumno.getCorreo());
if (usuario != null) {
usuario.setEmail(alumno.getCorreo());
StringBuilder nombreUsuarioBuilder = new StringBuilder();
nombreUsuarioBuilder.append(alumno.getNombre().toLowerCase());
nombreUsuarioBuilder.append(" ");
nombreUsuarioBuilder.append(alumno.getApellido().toLowerCase());
if (alumno.getApellido2() != null) {
if (!nombreUsuarioBuilder.isEmpty()) {
nombreUsuarioBuilder.append(" ");
}
nombreUsuarioBuilder.append(alumno.getApellido2().toLowerCase());
}
String nombreUsuario = nombreUsuarioBuilder.toString();
String nia = alumno.getNia();
String firstThreeLetters = nia.substring(0, 3);
String nombreLogIn="alu." +alumno.getNombre()+firstThreeLetters;
usuario.setNombreLogIn(nombreLogIn);
usuario.setNombreUsuario(nombreUsuario);
usuarioService.saveUser(usuario);
}
}
alumnoService.save(alumno);
return new ResponseEntity<>("El alumno fue actualizado con exito", HttpStatus.OK);
}catch (Exception e) {

@ -27,4 +27,7 @@ public interface UserRepository extends JpaRepository<Usuario, Long>{
@Modifying
@Query("UPDATE Usuario u SET u.logedIn = false")
void resetAllLogedIn();
@Query("SELECT u FROM Usuario u WHERE u.email = ?1")
Optional<Object> findByEmail(String correo);
}

@ -159,4 +159,7 @@ public class UsuarioService implements IUsuario {
return false;
}
public Usuario findByEmail(String correo) {
return (Usuario) userRepository.findByEmail(correo).orElse(null);
}
}

@ -25,7 +25,6 @@ th {
h1 {
text-align: center;
text-decoration: underline;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 50px;
color: white;

@ -16,9 +16,9 @@
width: 40px;
height: 40px;
}
h1 {
text-align: center;
text-decoration: underline;
background-color: #007BFF;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 50px;

@ -30,8 +30,9 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
}
@ -40,21 +41,21 @@
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
#keywords {
width: 100%;
height: auto;
min-height: 40px;
option {
font-size: 18px;
}
select {
font-size: 18px;
}
.tagify {
width: 100%; /* Limit the width to the parent's width */
height: auto; /* Adjusts the height automatically based on content */
min-height: 40px; /* Minimum height when there are no or few keywords */
display: block; /* Makes the input field a block-level element */
white-space: pre-wrap; /* Allows the input field to wrap its contents */
overflow-wrap: break-word; /* Breaks the word in case it's too long */
display: flex;
flex-direction: column;
max-height: 400px;
overflow-y: auto;
}
form label {
@ -69,6 +70,7 @@
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
@ -152,7 +154,7 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="keywords">Keywords</label>
<div class="col-sm-9">
<div class="tagify-container">
<input name="tags" id="keywords" class="tagify" placeholder="Introduce keywords">
</div>
</div>
@ -192,9 +194,6 @@
$('#skills').select2();
var tagifyInput = document.querySelector('input[name=tags]');
var tagify = new Tagify(tagifyInput, {
dropdown:{
enabled: 0
},
callbacks: {
add: function(e){
if(e.detail.data.value.trim() === ""){

@ -30,7 +30,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -38,6 +38,24 @@
form input[type="text"]{
width: 75%;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
.tagify {
display: flex;
flex-direction: column;
max-height: 400px;
overflow-y: auto;
}
form label{
font-size: 20px;
margin-bottom: 10px;
@ -134,8 +152,8 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="keywords">Keywords</label>
<div class="col-sm-9">
<input name="tags" id="keywords" placeholder="Introduce keywords">
<div class="tagify-container">
<input name="tags" id="keywords" class="tagify" placeholder="Introduce keywords">
</div>
</div>
<input type="hidden" id="joinedKeywords" name="joinedKeywords">

@ -26,7 +26,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;

@ -26,7 +26,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -39,6 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;

@ -26,7 +26,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -39,6 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;

@ -26,7 +26,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -39,6 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;

@ -28,7 +28,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -41,7 +41,24 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
.tagify {
display: flex;
flex-direction: column;
max-height: 400px;
overflow-y: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;
@ -86,8 +103,8 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="keywords">Keywords</label>
<div class="col-sm-9">
<input name="tags" id="keywords" placeholder="Introduce keywords">
<div class="tagify-container">
<input name="tags" id="keywords" class="tagify" placeholder="Introduce keywords">
</div>
</div>
<input type="hidden" id="joinedKeywords" name="joinedKeywords">

@ -28,7 +28,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -41,7 +41,24 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
.tagify {
display: flex;
flex-direction: column;
max-height: 400px;
overflow-y: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;
@ -87,8 +104,8 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="keywords">Keywords</label>
<div class="col-sm-9">
<input name="tags" id="keywords" placeholder="Introduce keywords">
<div class="tagify-container">
<input name="tags" id="keywords" class="tagify" placeholder="Introduce keywords">
</div>
</div>
<input type="hidden" id="joinedKeywords" name="joinedKeywords">

@ -26,7 +26,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -26,7 +26,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;
@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -41,7 +41,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -41,7 +41,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -39,7 +39,18 @@
margin-bottom: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input {
width: 85%;
height: 20px;
font-size: 18px;
overflow: auto;
}
option{
font-size: 18px;
}
select{
font-size: 18px;
}
body, h1 {
margin: 0;
padding: 0;

@ -54,7 +54,7 @@
position: relative;
margin-left: 50px;
padding: 0px;
background-color: #dddddd;
color: white;
width: 50px; /* Adjust as needed */
height: 50px; /* Adjust as needed */
display: flex;
@ -73,8 +73,8 @@
font-size: 10px; /* Adjust as needed */
}
.modal-content p{
background-color: antiquewhite;
.modal-content p:hover{
background-color: #f0f0f0;
}
</style>

@ -54,7 +54,7 @@
position: relative;
margin-left: 50px;
padding: 0px;
background-color: #dddddd;
color: white;
width: 50px; /* Adjust as needed */
height: 50px; /* Adjust as needed */
display: flex;
@ -73,8 +73,8 @@
font-size: 10px; /* Adjust as needed */
}
.modal-content p{
background-color: antiquewhite;
.modal-content p:hover{
background-color: #f0f0f0;
}
</style>

@ -121,7 +121,7 @@
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="correo2">Correo2</label>
<div class="col-sm-9">
<input type="email" th:field="*{correo2}" required minlength="5" maxlength="100"class="form-control" id="correo2" title="Introduce correo alternativo">
<input type="email" th:field="*{correo2}" minlength="5" maxlength="100" class="form-control" id="correo2" title="Introduce correo alternativo">
</div>
</div>
@ -180,7 +180,7 @@
formDataArray.push({name: 'skills', value: $('#skills').val()});
$.ajax({
url: '/usuario/update',
url: '/usuario/alu_update',
type: 'post',
data: $.param(formDataArray),
success: function (message) {

Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.