Paginas personalizadas de login y registro

parent 055b7cdd
......@@ -6,15 +6,8 @@ import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.roshka.modelo.Ciudad;
import com.roshka.modelo.Departamento;
import com.roshka.modelo.Postulante;
import com.roshka.modelo.PostulanteTecnologia;
import com.roshka.modelo.Tecnologia;
import com.roshka.repositorio.CiudadRepository;
import com.roshka.repositorio.DepartamentoRepository;
import com.roshka.repositorio.PostulanteRepository;
import com.roshka.repositorio.TecnologiaRepository;
import com.roshka.modelo.*;
import com.roshka.repositorio.*;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
......@@ -22,6 +15,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@SpringBootApplication
@EnableJpaRepositories("com.roshka.repositorio")
......@@ -33,7 +27,8 @@ public class CurriculumsearchApplication {
}
@Bean
CommandLineRunner runner(PostulanteRepository postRepo,TecnologiaRepository tecRepo,DepartamentoRepository depR, CiudadRepository ciudR) {
CommandLineRunner runner(PostulanteRepository postRepo, TecnologiaRepository tecRepo, DepartamentoRepository depR,
CiudadRepository ciudR, RRHHUserRepository rrhhUserRepository) {
return args -> {
try {
// read json and write to db
......@@ -53,6 +48,14 @@ public class CurriculumsearchApplication {
List<Postulante> postulantes = mapper.readValue(inputStream,typeReference);
postRepo.saveAll(postulantes);
System.out.println("postulantes Saved!");
String password = new BCryptPasswordEncoder().encode("test");
RRHHUser testuser = new RRHHUser();
testuser.setEmail("test@test.com");
testuser.setFirstName("test");
testuser.setLastName("test");
testuser.setPassword(password);
rrhhUserRepository.save(testuser);
System.out.println("Usuario Test: \nEmail: test@test.com\nPassword: test");
} catch (IOException e){
System.out.println("Unable to save tecnologias: " + e.getMessage());
......
......@@ -10,6 +10,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import javax.sql.DataSource;
......@@ -45,17 +46,27 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
http
// .csrf().disable()
.authorizeRequests()
.antMatchers("/").authenticated()
.antMatchers("/home").authenticated()
.antMatchers("/postulantes").authenticated()
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("email")
.defaultSuccessUrl("/home")
.permitAll()
.and()
.logout().logoutSuccessUrl("/").permitAll();
.logout()
.logoutUrl("/logout")
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
.clearAuthentication(true)
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID", "remember-me")
.logoutSuccessUrl("/login");
}
}
\ No newline at end of file
......@@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/")
public class PostulanteController {
PostulanteRepository post;
TecnologiaRepository tecRepo;
......@@ -101,7 +100,14 @@ public class PostulanteController {
}
System.out.println("hola");
post.save(postulante);
return "redirect:/";
return "redirect:/postulacion-correcta";
}
@GetMapping("/postulacion-correcta")
public String successPostulation(Model model){
model.addAttribute("mensaje1", "Tu informacion se ha recibido correctamente!");
model.addAttribute("mensaje2", " espera por que nos pongamos en contacto!");
return "exitoRegistro";
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
......
......@@ -22,6 +22,11 @@ public class RRHHUserController {
this.rrhhUserRepository = rrhhUserRepository;
}
@GetMapping("/")
public String redirectOnHome(){
return "redirect:/home";
}
@GetMapping("/register")
public String showRegistrationForm(Model model) {
model.addAttribute("user", new RRHHUser());
......@@ -29,6 +34,11 @@ public class RRHHUserController {
return "registration";
}
@GetMapping("/login")
public String getLogin() {
return "login";
}
@PostMapping("/process_register")
public String processRegister(HttpServletRequest request, RRHHUser user) {
if(Long.parseLong(request.getParameter("registrationCode")) != REGISTER_CODE){
......
......@@ -173,6 +173,7 @@ function serializeJSON (form) {
// Create a new FormData object
const formData = new FormData(form);
// Create an object to hold the name/value pairs
const pairs = {};
......@@ -189,20 +190,24 @@ function serializeJSON (form) {
}
async function postData(url = '', data = {}) {
var token = document.querySelector("meta[name='_csrf']").content;
var headerxs = document.querySelector("meta[name='_csrf_header']").content;
// Default options are marked with *
const response = await fetch(url, {
let senddata = {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: data // body data type must match "Content-Type" header
});
}
senddata["headers"][headerxs] = token;
const response = await fetch(url, senddata);
return response; // parses JSON response into native JavaScript objects
}
formValidator()
......
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:400,400i,700,900&display=swap" rel="stylesheet">
</head>
<style>
body {
text-align: center;
padding: 40px 0;
background: #EBF0F5;
}
h1 {
color: #506BEE;
font-family: "Nunito Sans", "Helvetica Neue", sans-serif;
font-weight: 900;
font-size: 40px;
margin-bottom: 10px;
}
p {
color: #404F5E;
font-family: "Nunito Sans", "Helvetica Neue", sans-serif;
font-size:20px;
margin: 0;
}
i {
color: #506BEE;
font-size: 100px;
line-height: 200px;
margin-left:-15px;
}
.card {
background: white;
padding: 60px;
border-radius: 4px;
box-shadow: 0 2px 3px #C8D0D8;
display: inline-block;
margin: 0 auto;
}
</style>
<body>
<div class="card">
<div style="border-radius:200px; height:200px; width:200px; background: #F8FAF5; margin:0 auto;">
<i class="checkmark"></i>
</div>
<h1>Genial!</h1>
<p>${mensaje1}<br/>${mensaje2}</p>
</div>
</body>
</html>
\ No newline at end of file
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Login</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link href="https://getbootstrap.com/docs/4.0/examples/signin/signin.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
<section class="vh-100" style="background-color: #508bfc;">
<div class="container py-5 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col-12 col-md-8 col-lg-6 col-xl-5">
<div class="card shadow-2-strong" style="border-radius: 1rem;">
<div class="card-body p-5 text-center">
<form:form method="post" action="/login">
<h3 class="mb-5">Sign in</h3>
<div class="form-outline mb-4">
<input type="email" id="typeEmailX-2" class="form-control form-control-lg" name="email" placeholder="example@example.com"/>
<label class="form-label" for="typeEmailX-2">Email</label>
</div>
<div class="form-outline mb-4">
<input type="password" id="typePasswordX-2" class="form-control form-control-lg" name="password" />
<label class="form-label" for="typePasswordX-2">Password</label>
</div>
<button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
</form:form>
<hr class="my-4">
</div>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
......@@ -468,6 +468,8 @@
</div>
</div>
</div>
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>
<!-- Optional JavaScript; choose one of the two! -->
......
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