Browse Source

Token

master
DANIEL IVAN ESTRADA MORANDO 6 months ago
parent
commit
82004ed9d8
  1. 114
      InventarioJakartaJIN-ejb/src/java/mx/edu/tsj/chapala/sistemas/jin/modelo/Tokens.java
  2. 68
      InventarioJakartaJIN-war/src/java/mx/edu/tsj/chapala/sistemas/jin/servicios/ProductosServlet.java

114
InventarioJakartaJIN-ejb/src/java/mx/edu/tsj/chapala/sistemas/jin/modelo/Tokens.java

@ -0,0 +1,114 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package mx.edu.tsj.chapala.sistemas.jin.modelo;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author estra
*/
@Entity
@Table(name = "tokens")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Tokens.findAll", query = "SELECT t FROM Tokens t"),
@NamedQuery(name = "Tokens.findById", query = "SELECT t FROM Tokens t WHERE t.id = :id"),
@NamedQuery(name = "Tokens.findByToken", query = "SELECT t FROM Tokens t WHERE t.token = :token"),
@NamedQuery(name = "Tokens.findByServicio", query = "SELECT t FROM Tokens t WHERE t.servicio = :servicio")})
public class Tokens implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 100)
@Column(name = "token")
private String token;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 100)
@Column(name = "servicio")
private String servicio;
public Tokens() {
}
public Tokens(Integer id) {
this.id = id;
}
public Tokens(Integer id, String token, String servicio) {
this.id = id;
this.token = token;
this.servicio = servicio;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getServicio() {
return servicio;
}
public void setServicio(String servicio) {
this.servicio = servicio;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Tokens)) {
return false;
}
Tokens other = (Tokens) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "mx.edu.tsj.chapala.sistemas.jin.modelo.Tokens[ id=" + id + " ]";
}
}

68
InventarioJakartaJIN-war/src/java/mx/edu/tsj/chapala/sistemas/jin/servicios/ProductosServlet.java

@ -28,7 +28,6 @@ import mx.edu.tsj.chapala.sistemas.jin.modelo.Ubicacion;
* @author estra * @author estra
*/ */
@WebServlet(name = "ProductosServlet", urlPatterns = {"/ProductosServlet"}) @WebServlet(name = "ProductosServlet", urlPatterns = {"/ProductosServlet"})
public class ProductosServlet extends HttpServlet { public class ProductosServlet extends HttpServlet {
@ -46,7 +45,6 @@ public class ProductosServlet extends HttpServlet {
@EJB @EJB
private ProductoBLLocal productoBL; private ProductoBLLocal productoBL;
/** /**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
@ -62,32 +60,39 @@ public class ProductosServlet extends HttpServlet {
response.setContentType("text/html;charset=UTF-8"); response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) { try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */ /* TODO output your page here. You may use following sample code. */
String opcion = request.getParameter("Opc");
// Verificar el token
switch(opcion){ String token = request.getParameter("token");
if (!"4jLz8mQ1sT2nEw7Vb9XRp6Aa".equals(token)) {
out.print("Acceso Denegado");
return;
}
String opcion = request.getParameter("Opc");
switch (opcion) {
case "1": case "1":
Producto p = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id"))); Producto p = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id")));
if(p.getStatus() == 0){ if (p.getStatus() == 0) {
out.print("No existe ese producto"); out.print("No existe ese producto");
}else{ } else {
out.print("<h1>"+p.getNombre()+"</h1>"); out.print("<h1>" + p.getNombre() + "</h1>");
} }
break;
break;
case "2": case "2":
Producto pE = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id"))); Producto pE = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id")));
if(pE.getStatus() == 0){ if (pE.getStatus() == 0) {
out.print("No existe ese elemento"); out.print("No existe ese elemento");
}else{ } else {
productoBL.eliminar(pE); productoBL.eliminar(pE);
out.print("Eliminado con éxito"); out.print("Eliminado con éxito");
} }
break; break;
case "3": case "3":
Producto nuevo = new Producto(); Producto nuevo = new Producto();
Marca m = marcaBL.buscarIdInt(Integer.parseInt(request.getParameter("idMarca"))); Marca m = marcaBL.buscarIdInt(Integer.parseInt(request.getParameter("idMarca")));
Ubicacion u = ubicacionBL.buscarIdInt(Integer.parseInt(request.getParameter("idUbi"))); Ubicacion u = ubicacionBL.buscarIdInt(Integer.parseInt(request.getParameter("idUbi")));
Categoria c = categoriaBL.buscarIdInt(Integer.parseInt(request.getParameter("idCat"))); Categoria c = categoriaBL.buscarIdInt(Integer.parseInt(request.getParameter("idCat")));
@ -110,15 +115,13 @@ public class ProductosServlet extends HttpServlet {
productoBL.agregar(nuevo); productoBL.agregar(nuevo);
out.print("Agregado con éxito"); out.print("Agregado con éxito");
} }
break; break;
default: default:
out.print("<h1> No existe esa opcion </h1>"); out.print("<h1> No existe esa opcion </h1>");
break; break;
} }
} }
} }
@ -134,8 +137,7 @@ public class ProductosServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
processRequest(request, response);
processRequest(request, response);
} }
/** /**

Loading…
Cancel
Save