|
|
|
@ -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";
|
|
|
|
|
}
|
|
|
|
|