diff --git a/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetails.java b/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetails.java index d8ad7b4..4e92c55 100644 --- a/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetails.java +++ b/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetails.java @@ -53,4 +53,8 @@ public class CustomUserDetails implements UserDetails { return user.getFirstName() + " " + user.getLastName(); } + @Override + public String toString(){ + return user.getEmail(); + } } \ No newline at end of file diff --git a/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java b/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java index d1279b2..40d1a40 100644 --- a/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java +++ b/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java @@ -55,6 +55,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers("/convocatoria*").authenticated() .antMatchers("/tecnologia*").authenticated() .antMatchers("/postulantes").authenticated() + .antMatchers("/edit-user-data").authenticated() .anyRequest().permitAll() .and() .formLogin() diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 283ab2a..5ca25d4 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -197,35 +197,35 @@ public class PostulanteController { MethodArgumentNotValidException ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(ex.getMessage()); - } + } - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler({ConstraintViolationException.class}) - public ResponseEntity handleValidationExceptions2( - ConstraintViolationException ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST) - .body(ex.getMessage()); - } - - - - @GetMapping({"/postulante/{postulanteId}"}) - public String getPostulanteDetalle(Model model, @PathVariable("postulanteId") Long postulanteId) { - Postulante p = post.findById(postulanteId).orElse(null); - model.addAttribute("postulante",p); - model.addAttribute("estadoP", EstadoPostulante.values()); - return "detallepostulante"; - - } - @PostMapping({"/postulante/{postulanteId}"}) - public String setPostulanteEstado(@ModelAttribute Postulante postulante, BindingResult result, @PathVariable("postulanteId") Long postulanteId) { - //post.setPostulanteEstadoAndComentario(postulante.getEstadoPostulante(),postulante.getComentarioRRHH(), postulante.getId()); - Postulante postulanteVd = post.getById(postulanteId); - postulanteVd.setEstadoPostulante(postulante.getEstadoPostulante()); - postulanteVd.setComentarioRRHH(postulante.getComentarioRRHH()); - post.setPostulanteEstadoAndComentario(postulante.getEstadoPostulante(), postulante.getComentarioRRHH(), postulanteId); - //post.save(postulanteVd); - return "redirect:/postulante/"+postulanteId; - } - } + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler({ConstraintViolationException.class}) + public ResponseEntity handleValidationExceptions2( + ConstraintViolationException ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(ex.getMessage()); + } + + + + @GetMapping({"/postulante/{postulanteId}"}) + public String getPostulanteDetalle(Model model, @PathVariable("postulanteId") Long postulanteId) { + Postulante p = post.findById(postulanteId).orElse(null); + model.addAttribute("postulante",p); + model.addAttribute("estadoP", EstadoPostulante.values()); + return "detallepostulante"; + + } + @PostMapping({"/postulante/{postulanteId}"}) + public String setPostulanteEstado(@ModelAttribute Postulante postulante, BindingResult result, @PathVariable("postulanteId") Long postulanteId) { + //post.setPostulanteEstadoAndComentario(postulante.getEstadoPostulante(),postulante.getComentarioRRHH(), postulante.getId()); + Postulante postulanteVd = post.getById(postulanteId); + postulanteVd.setEstadoPostulante(postulante.getEstadoPostulante()); + postulanteVd.setComentarioRRHH(postulante.getComentarioRRHH()); + post.setPostulanteEstadoAndComentario(postulante.getEstadoPostulante(), postulante.getComentarioRRHH(), postulanteId); + //post.save(postulanteVd); + return "redirect:/postulante/"+postulanteId; + } +} \ No newline at end of file diff --git a/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java b/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java index d340506..0ad17b3 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java @@ -11,6 +11,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; @@ -76,6 +80,35 @@ public class RRHHUserController { return "register_success"; } + @GetMapping("/edit-user-data") + public String editUserData(HttpServletRequest request, Model model){ + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + System.out.println(auth.getPrincipal().toString()); + System.out.println(rrhhUserRepository.findByEmail(auth.getPrincipal().toString())); + model.addAttribute("user", rrhhUserRepository.findByEmail(auth.getPrincipal().toString())); + return "edit-user-data"; + } + + @PostMapping("/edit-user-data") + public RedirectView processEditUser(HttpServletRequest request, RRHHUser user, + RedirectAttributes redirectAttributes){ + RRHHUser editUser = rrhhUserRepository.findByEmail(SecurityContextHolder.getContext().getAuthentication() + .getPrincipal().toString()); + if(user.getEmail()!=null){ + editUser.setEmail(user.getEmail()); + } + if(user.getFirstName()!=null){ + editUser.setFirstName(user.getFirstName()); + } + if(user.getLastName()!=null){ + editUser.setLastName(user.getLastName()); + } + rrhhUserRepository.save(editUser); + RedirectView redirectView = new RedirectView("/home",true); + redirectAttributes.addFlashAttribute("success", "Datos actualizados"); + return redirectView; + } + @Autowired private RRHHUserService userService; @@ -155,15 +188,6 @@ public class RRHHUserController { return "redirect:/"; } - @ResponseStatus(HttpStatus.PERMANENT_REDIRECT) - @ExceptionHandler({UsernameNotFoundException.class}) - public RedirectView handleValidationExceptions( - RedirectAttributes redir, UsernameNotFoundException ex) { - RedirectView redirectView = new RedirectView("/forgot-password", true); - redir.addAttribute("error", "Error al enviar el mail. Checkee sus credenciales" + - " y intentelo de nuevo"); - return redirectView; - } } class Utility { diff --git a/curriculumsearch/src/main/webapp/jsp/edit-user-data.jsp b/curriculumsearch/src/main/webapp/jsp/edit-user-data.jsp new file mode 100644 index 0000000..abdb26d --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/edit-user-data.jsp @@ -0,0 +1,65 @@ +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + Edit Profile + + + + + + + + + +
+
+
+
+
+ Sample photo +
+

Perfil

+ + +
+ Email + +
+
+
+
+ Nombre + +
+
+
+
+ Apellido + +
+
+
+
+
+ +
+
+ + +
+ +
+
+
+
+
+
+ + diff --git a/curriculumsearch/src/main/webapp/jsp/header.jsp b/curriculumsearch/src/main/webapp/jsp/header.jsp index 397a029..5a842fb 100644 --- a/curriculumsearch/src/main/webapp/jsp/header.jsp +++ b/curriculumsearch/src/main/webapp/jsp/header.jsp @@ -46,8 +46,12 @@ + + diff --git a/curriculumsearch/src/main/webapp/jsp/login.jsp b/curriculumsearch/src/main/webapp/jsp/login.jsp index 2662a0b..b426f3e 100644 --- a/curriculumsearch/src/main/webapp/jsp/login.jsp +++ b/curriculumsearch/src/main/webapp/jsp/login.jsp @@ -41,6 +41,9 @@ +