diff --git a/pom.xml b/pom.xml index 967ae10..9b4ec8b 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,12 @@ ${junit.version} test + + org.postgresql + postgresql + 42.3.5 + + diff --git a/src/main/java/Postulante/PostulanteDao.java b/src/main/java/Postulante/PostulanteDao.java deleted file mode 100644 index b0172b9..0000000 --- a/src/main/java/Postulante/PostulanteDao.java +++ /dev/null @@ -1,34 +0,0 @@ -package Postulante; -import com.roshka.proyectofinal.DataBase; -import com.roshka.proyectofinal.Postulante; - -import java.util.*; -import java.sql.*; - -public class PostulanteDao { - - - public static int save(Postulante postulante){ - int status=0; - try{ - Connection con= DataBase.getConnection(); - PreparedStatement ps=con.prepareStatement( - "insert into postulante(nombre,apellido,nro_cedula,correo,telefono,direccion,experiencia_laboral,estudio_universitario,notebook,bootcamp_id,aceptado) values (?,?,?,?,?,?,?,?,?,?,?)"); - ps.setString(1,postulante.getNombre()); - ps.setString(2,postulante.getApellido()); - ps.setInt(3,postulante.getNro_cedula()); - ps.setString(4,postulante.getCorreo()); - ps.setString(5,postulante.getTelefono()); - ps.setString(6,postulante.getDireccion()); - ps.setBoolean(7,postulante.getExpLaboral()); - ps.setBoolean(8,postulante.getEstudioUniversitario()); - ps.setBoolean(9,postulante.getNotebook()); - ps.setInt(10,postulante.getBootcampId()); - ps.setBoolean(11,postulante.getAceptado()); - status=ps.executeUpdate(); - con.close(); - }catch(Exception ex){ex.printStackTrace();} - - return status; - } -} diff --git a/src/main/java/Postulante/SaveServlet.java b/src/main/java/Postulante/SaveServlet.java deleted file mode 100644 index 20051b8..0000000 --- a/src/main/java/Postulante/SaveServlet.java +++ /dev/null @@ -1,64 +0,0 @@ -package Postulante; -import com.roshka.proyectofinal.Postulante; -import jakarta.servlet.ServletException; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - - -@WebServlet("/SaveServlet") -public class SaveServlet { - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - response.setContentType("text/html"); - PrintWriter out=response.getWriter(); - - String nombre=request.getParameter("nombre"); - String apellido=request.getParameter("apellido"); - int cedula=Integer.parseInt(request.getParameter("cedula")); - String correo=request.getParameter("correo"); - String telefono=request.getParameter("telefono"); - String direccion=request.getParameter("direccion"); - boolean experienciaProgramando = false; - boolean experienciaLaboral = false; - boolean universidad = false; - if (request.getParameter("experiencia_laboral") != null){ - experienciaLaboral = true; - } - if (request.getParameter("experiencia_programando") != null) { - experienciaProgramando = true; - } - if (request.getParameter("notebook") != null){ - boolean notebook = true; - } - if (request.getParameter("universidad") != null){ - universidad = true; - } - - - Postulante postulante=new Postulante(); - postulante.setNombre(nombre); - postulante.setApellido(apellido); - postulante.setNro_cedula(cedula); - postulante.setCorreo(correo); - postulante.setTelefono(telefono); - postulante.setDireccion(direccion); - postulante.setExpLaboral(experienciaLaboral); - postulante.setEstudioUniversitario(universidad); - - int status=PostulanteDao.save(postulante); - - - - if(status>0){ - out.print("

Record saved successfully!

"); - request.getRequestDispatcher("index.html").include(request, response); - }else{ - out.println("Sorry! unable to save record"); - } - - out.close(); - } -} diff --git a/src/main/java/com/roshka/proyectofinal/ProtectedResource.java b/src/main/java/com/roshka/proyectofinal/ProtectedResource.java index 1ce29d8..9c45921 100644 --- a/src/main/java/com/roshka/proyectofinal/ProtectedResource.java +++ b/src/main/java/com/roshka/proyectofinal/ProtectedResource.java @@ -1,11 +1,10 @@ package com.roshka.proyectofinal; -import jakarta.servlet.ServletException; +import java.io.*; +import java.util.*; +import jakarta.servlet.*; import jakarta.servlet.http.*; -import java.io.*; - - public class ProtectedResource extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { diff --git a/src/main/java/com/roshka/proyectofinal/entity/LoginBean.java b/src/main/java/com/roshka/proyectofinal/entity/LoginBean.java new file mode 100644 index 0000000..9b2ad7e --- /dev/null +++ b/src/main/java/com/roshka/proyectofinal/entity/LoginBean.java @@ -0,0 +1,22 @@ +package com.roshka.proyectofinal.entity; + +public class LoginBean { + private String username; + private String password; + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/main/java/entity/Postulante.java b/src/main/java/com/roshka/proyectofinal/entity/Postulante.java similarity index 98% rename from src/main/java/entity/Postulante.java rename to src/main/java/com/roshka/proyectofinal/entity/Postulante.java index 0e629a6..459696f 100644 --- a/src/main/java/entity/Postulante.java +++ b/src/main/java/com/roshka/proyectofinal/entity/Postulante.java @@ -1,4 +1,5 @@ -package com.roshka.proyectofinal; +package com.roshka.proyectofinal.entity; + //Creacion del objeto Postulante public class Postulante { diff --git a/src/main/java/com/roshka/proyectofinal/login/LoginDao.java b/src/main/java/com/roshka/proyectofinal/login/LoginDao.java new file mode 100644 index 0000000..8ab20f8 --- /dev/null +++ b/src/main/java/com/roshka/proyectofinal/login/LoginDao.java @@ -0,0 +1,33 @@ +package com.roshka.proyectofinal.login; + +import com.roshka.proyectofinal.DataBase; +import com.roshka.proyectofinal.entity.Lenguaje; +import com.roshka.proyectofinal.entity.LoginBean; + +import java.sql.Connection; +import java.sql.PreparedStatement; + +public class LoginDao { + + public boolean validate (LoginBean loginBean) { + int status = 0; + try { + Connection con = DataBase.getConnection(); + + PreparedStatement ps=con.prepareStatement( + "select * from usuarios where username=? and password = ?"); + ps.setString(1,loginBean.getUsername()); + ps.setString(2, loginBean.getPassword()); + status=ps.executeUpdate(); + + con.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + + if (status > 0) return true ; + else return false ; + + } + +} diff --git a/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java b/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java new file mode 100644 index 0000000..c251007 --- /dev/null +++ b/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java @@ -0,0 +1,61 @@ +package com.roshka.proyectofinal.login; + + +import java.io.IOException; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import com.roshka.proyectofinal.entity.LoginBean; + +/** + * Servlet implementation class LoginServlet + */ +@WebServlet("/login") +public class LoginServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public LoginServlet() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + response.getWriter().append("Served at: ").append(request.getContextPath()); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + LoginDao loginDao = new LoginDao(); + + String username = request.getParameter("username"); + String password = request.getParameter("password"); + LoginBean loginBean = new LoginBean(); + loginBean.setUsername(username); + loginBean.setPassword(password); + + + if (loginDao.validate(loginBean)) + { + response.sendRedirect("loginSuccess.jsp"); + + } + else { + //HttpSession session = request.getSession(); + response.sendRedirect("login.jsp"); + + } + } + +} \ No newline at end of file diff --git a/src/main/webapp/Javascript.js b/src/main/webapp/Javascript.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/webapp/Javascript.js diff --git a/src/main/webapp/formulario.html b/src/main/webapp/formulario.html index 359d3cb..1e45767 100644 --- a/src/main/webapp/formulario.html +++ b/src/main/webapp/formulario.html @@ -16,38 +16,38 @@

Si sigues interesado y cumples con los requisitos, completa el siguiente formulario:

-
+ -
+
-
+
-
+
-
+
-
+
-
+
-
+
- +
-
+
-
+
diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index dd88878..bff22f6 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -1,13 +1,18 @@ <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> - - - - JSP - Hello World - - -

<%= "Hello World!" %> -

-
-Hello Servlet - - \ No newline at end of file + + + + + JSP - Hello World + + + +

+ <%= "Hello World!" %> +

+
+ Hello Servlet
+ Postulate aqui + + + \ No newline at end of file diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp new file mode 100644 index 0000000..1f1dadf --- /dev/null +++ b/src/main/webapp/login.jsp @@ -0,0 +1,21 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + BootcampsLogin + + +
+

User Login Form

+ + + + + + +
User Name:
Password:
+ +
+ + + \ No newline at end of file diff --git a/src/main/webapp/loginSuccess.jsp b/src/main/webapp/loginSuccess.jsp new file mode 100644 index 0000000..2d4e892 --- /dev/null +++ b/src/main/webapp/loginSuccess.jsp @@ -0,0 +1,16 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + +LoginExitoso + + + +
+

LOGGIN EXITOSO

+ + +
+ + \ No newline at end of file