editar datos de usuario

parent 9d28912b
......@@ -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
......@@ -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()
......
......@@ -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<String> 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<String> 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
......@@ -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 {
......
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Edit Profile</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<style>
@media (min-width: 1025px) {
.h-custom {
height: 100vh !important;
}
}
</style>
<body>
<section class="h-100 h-custom">
<div class="container py-5 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-lg-8 col-xl-6">
<div class="card rounded-3">
<img src="https://cdn.pixabay.com/photo/2013/08/09/05/54/layer-170971_960_720.jpg" class="w-100" style="border-top-left-radius: .3rem; border-top-right-radius: .3rem;height: 250px;" alt="Sample photo";>
<div class="card-body p-4 p-md-5">
<h3 class="mb-4 pb-2 pb-md-0 mb-md-5 px-md-2">Perfil</h3>
<form:form action="/edit-user-data" class="px-md-2" method="POST" modelAttribute="user">
<div class="form-outline mb-4">
<form:label path="email" class="form-label">Email</form:label>
<form:input path="email" type="email" class="form-control" required="required"></form:input>
</div>
<div class="row">
<div class="col-md-6 mb-4">
<div class="form-outline">
<form:label path="firstName" class="form-label">Nombre </form:label>
<form:input path="firstName" class="form-control"></form:input>
</div>
</div>
<div class="col-md-6 mb-4">
<div class="form-outline">
<form:label path="lastName" class="form-label">Apellido </form:label>
<form:input path="lastName" class="form-control"></form:input>
</div>
</div>
</div>
<div class="row mb-4 pb-2 pb-md-0 mb-md-5">
<div class="col-md-6">
</div>
</div>
<button type="submit" class="btn btn-success btn-lg mb-1">Submit</button>
</form:form>
</div>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
......@@ -46,8 +46,12 @@
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="/edit-user-data">Editar mis datos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout">Salir</a>
</li>
</ul>
</div>
</div>
......
......@@ -41,6 +41,9 @@
<div class="row">
<a href="/forgot-password">Olvidaste tu contrasena?</a>
</div>
<div class="row">
<a href="/register">Registrate</a>
</div>
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment