Browse Source

prueba , datos 2

master
Josue 4 months ago
parent
commit
b390d01d90
  1. 6
      si-war/nbproject/faces-config.NavData
  2. 62
      si-war/src/java/hola/seguridad/AutorizacionListener.java
  3. 138
      si-war/src/java/hola/seguridad/DemoBeanLogin.java
  4. 24
      si-war/src/java/hola/vista/DemoBeanUsuario.java
  5. 134
      si-war/web/Marca.xhtml
  6. 8
      si-war/web/MarcaCrear.xhtml
  7. 6
      si-war/web/Provedor.xhtml
  8. 38
      si-war/web/Usuario.xhtml
  9. 41
      si-war/web/WEB-INF/faces-config.xml
  10. 8
      si-war/web/WEB-INF/web.xml
  11. 66
      si-war/web/index.xhtml
  12. 11
      si-war/web/template/Principal.xhtml

6
si-war/nbproject/faces-config.NavData

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scene Scope="Project" version="2">
<Scope Scope="Faces Configuration Only"/>
<Scope Scope="Project"/>
<Scope Scope="All Faces Configurations"/>
</Scene>

62
si-war/src/java/hola/seguridad/AutorizacionListener.java

@ -0,0 +1,62 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
*/
package hola.seguridad;
import java.io.IOException;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
/**
*
* @author Josue
*/
@Named(value = "autorizacionListener")
@SessionScoped
public class AutorizacionListener implements PhaseListener {
/**
* Creates a new instance of AutorizacionListener
*/
public AutorizacionListener() {
}
private static final long serialVersionUID = 1L;
@Override
public void afterPhase(PhaseEvent event) {
try {
//Obtener la pagina actual para validar la sesion
String paginaActual = event.getFacesContext().getViewRoot().getViewId();
//inicializar la sesion en caso de no haber sesion
DemoBeanLogin.getSession();
//Revisar que no sea la pafina index y que no estes logueado
//para redireccionar
if (!paginaActual.contains("index.xhtml") && DemoBeanLogin.getEstatus() == false) {
FacesContext.getCurrentInstance().getExternalContext().redirect("faces/index.xhtml?faces-redirect=true");
NavigationHandler nh = event.getFacesContext().getApplication().getNavigationHandler();
nh.handleNavigation(event.getFacesContext(), null, "index");
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void beforePhase(PhaseEvent event) {}
@Override
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}
}

138
si-war/src/java/hola/seguridad/DemoBeanLogin.java

@ -0,0 +1,138 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
*/
package hola.seguridad;
import hola.BL.LoginBLLocal;
import hola.modelo.Usuario;
import hola.msg.Mensaje;
import static hola.msg.Mensaje.CAMPOS_INCOMPLETOS;
import static hola.msg.Mensaje.DATOS_INCORRECTOS;
import static hola.msg.Mensaje.ELEMENTO_DUPLICADO;
import static hola.msg.Mensaje.SIN_ERROR;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
/**
*
* @author Josue
*/
@Named(value = "demoBeanLogin")
@SessionScoped
public class DemoBeanLogin implements Serializable {
@EJB
private LoginBLLocal loginBL;
private String rol;
private boolean permisos =false ;
//variable para manejar la sesion
public static HttpSession httpSession;
/**
* Creates a new instance of DemoBeanLogin
*/
public DemoBeanLogin() {
}
public String getRol() {
return rol;
}
public void setRol(String rol) {
this.rol = rol;
}
public boolean isPermisos() {
return permisos;
}
public void setPermisos(boolean permisos) {
this.permisos = permisos;
}
private Usuario usuarios = new Usuario();
private static String http = "caba";
public Usuario getUsuarios() {
return usuarios;
}
public void setUsuarios(Usuario usuarios) {
this.usuarios = usuarios;
}
public static void getSession() {
httpSession = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
}
public String logout() {
//quitar atributo
//invalidar la session
System.out.println(http);
httpSession.removeAttribute(http);
httpSession.invalidate();
return "index.xhtml";
}
public String login() {
//BL de autenticacion de usuario
//poner atributo
Mensaje mensaje = loginBL.login(usuarios);
switch (mensaje) {
case SIN_ERROR:
rol = loginBL.rol(usuarios);
System.out.println(rol);
httpSession.setAttribute(http, "true");
usuarios = new Usuario();
return "Producto.xhtml";
case ELEMENTO_DUPLICADO:
return null;
case CAMPOS_INCOMPLETOS:
return null;
case DATOS_INCORRECTOS:
return null;
default:
return null;
}
}
public static boolean getEstatus() {
if (httpSession != null
&& httpSession.getId() != null
&& !httpSession.getId().isEmpty()
&& httpSession.getAttribute("caba") != null) {
return true;
} else {
return false;
}
}
public void permiso() {
switch (rol) {
case "admin":
permisos = true;
break;
case "capturista":
permisos = false;
break;
case "usuario":
permisos = false;
break;
default:
throw new AssertionError();
}
}
}

24
si-war/src/java/hola/vista/DemoBeanUsuario.java

@ -6,7 +6,6 @@ package hola.vista;
import hola.BL.UsuarioBLLocal;
import hola.modelo.Usuario;
import hola.msg.Mensaje;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
@ -61,24 +60,9 @@ public class DemoBeanUsuario implements Serializable {
public String agregarUsuario() {
usuario.setStatus(1);
usuarioBL.agregar(usuario);
usuarioBL.agregar(usuario);
// limpiarFormulario();
Mensaje mensaje = usuarioBL.agregar(usuario);
switch (mensaje) {
case SIN_ERROR:
usuario = new Usuario();
return "Usuario.xhtml";//"productoLista?faces-redirect=true"; // Redirecciona a la lista de productos
case ELEMENTO_DUPLICADO:
return null;
case CAMPOS_INCOMPLETOS:
return null;
case DATOS_INCORRECTOS:
return null;
default:
return null;
}
return "Usuario.xhtml";
}
public List<Usuario> getUsuarios() {
@ -95,7 +79,7 @@ public class DemoBeanUsuario implements Serializable {
public void prepararEditar(Usuario usuario) {
nuevo = false;
titulo = "Editar usuario";
titulo = "Editando usuario";
this.usuario = usuario;
}
@ -110,7 +94,7 @@ public class DemoBeanUsuario implements Serializable {
public void preparar() {
nuevo = true;
titulo = "Agregar Usuario";
titulo = "Agregando Usuario";
usuario = new Usuario();
}

134
si-war/web/Marca.xhtml

@ -13,15 +13,13 @@
<body>
<center>
<ui:composition template="./template/Principal.xhtml">
<ui:define name="top">
<ui:composition template="./template/Principal.xhtml">
<ui:define name="top">
SISTEMA DE INVENTARIO
</ui:define>
<ui:define name="left">
<div class="card">
<ui:define name="left">
<div class="card">
<h:form>
<p:growl id="messages"/>
@ -34,7 +32,6 @@
<p:menuitem value="Marca" icon="pi pi-fw pi-tag" disabled="true" action="Marca.xhtml"/>
<p:menuitem value="Producto" icon="pi pi-fw pi-shopping-bag" action="Producto.xhtml"/>
<p:menuitem value="Proveedor" icon="pi pi-fw pi-truck" action="Provedor.xhtml"/>
<!-- comment <p:menuitem value="Registro" icon="pi pi-fw pi-book " disabled="true" action="Registro.xhtml"/> -->
<p:menuitem value="Tipo" icon="pi pi-fw pi-table" action="Tipo.xhtml"/>
<p:menuitem value="Usuario" icon="pi pi-fw pi-user" action="Usuario.xhtml"/>
<p:menuitem value="Inicio" icon="pi pi-fw pi-home" action="Menu.xhtml"/>
@ -42,79 +39,76 @@
</p:menubar>
</h:form>
</div>
</ui:define>
<ui:define name="right">
</ui:define>
<ui:define name="content">
<h:form style="text-align: left; margin-top: 20px;">
<div style="margin-bottom: 10px;">
</div>
</h:form>
<f:view>
</ui:define>
<ui:define name="right">
<h:form>
</ui:define>
<h3><h:outputText value="Marcas "/></h3>
<ui:define name="content">
<h:form style="text-align: left; margin-top: 20px;">
<div style="margin-bottom: 10px;">
</div>
</h:form>
<f:view>
<h:form>
<h3><h:outputText value="Marcas "/></h3>
<p:dataTable value="#{demoBeanMarca.marcas}" var="item">
<f:facet name="header">
<p:dataTable value="#{demoBeanMarca.marcas}" var="item">
<f:facet name="header">
<div class="flex justify-content-end" style="position: absolute; right: 40px; top: 190px; ">
<p:inputText id="globalFilter" onkeyup="PF('usuarios').filter()" style="width:300px"
<p:inputText id="globalFilter" onkeyup="PF('marcas').filter()" style="width:300px"
placeholder="Buscar" />
</div>
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nombre"/>
</f:facet>
<h:outputText value="#{item.nombre}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Status"/>
</f:facet>
<h:outputText value="#{item.status == 1 ? 'activo':'inactivo'}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Opciones"/>
<p:column>
<f:facet name="header">
<h:outputText value="Id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nombre"/>
</f:facet>
<h:outputText value="#{item.nombre}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Status"/>
</f:facet>
<h:outputText value="#{item.status == 1 ? 'activo':'inactivo'}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Imagen"/>
</f:facet>
<h:graphicImage library="imagenes" name="ni.jpg" alt="Nike Logo" width="100"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Opciones"/>
</f:facet>
<p:commandButton action="MarcaCrear.xhtml"
style="padding: 2px 8px; font-size: 11px; font-weight: bold; color: #3366FF; background-color: #fff; border: 2px solid #3366FF; border-radius: 8px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease ; margin-right: 6px;"
actionListener="#{demoBeanMarca.prepararEditar(item)}"
value="Editar"
ajax="false"/>
<p:commandButton action="MarcaEliminar.xhtml"
style=" padding: 2px 8px; font-size: 11px; font-weight: bold; color: #990000; background-color: #fff; border: 2px solid #FF0000; border-radius: 8px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease; margin-right: 6px;"
actionListener="#{demoBeanMarca.prepararEliminar(item)}"
value="Eliminar"
ajax="false"/>
</p:column>
</p:dataTable>
</h:form>
</f:view>
</ui:define>
<p:commandButton action="MarcaCrear.xhtml"
style="padding: 2px 8px; font-size: 11px; font-weight: bold; color: #3366FF; background-color: #fff; border: 2px solid #3366FF; border-radius: 8px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease ; margin-right: 6px;"
actionListener="#{demoBeanMarca.prepararEditar(item)}"
value="Editar"
ajax="false"/>
<p:commandButton action="MarcaEliminar.xhtml"
style=" padding: 2px 8px; font-size: 11px; font-weight: bold; color: #990000; background-color: #fff; border: 2px solid #FF0000; border-radius: 8px; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); transition: transform 0.3s ease; margin-right: 6px;"
actionListener="#{demoBeanMarca.prepararEliminar(item)}"
value="Eliminar"
ajax="false"/>
</p:column>
</p:dataTable>
</h:form>
</f:view>
</ui:define>
<ui:define name="bottom">
</ui:define>
<ui:define name="bottom">
</ui:composition>
</center>
</ui:define>
</ui:composition>
</center>
</body>
</html>

8
si-war/web/MarcaCrear.xhtml

@ -29,7 +29,7 @@
<h:form>
<h1><h:outputText value="Create/Edit"/></h1>
<p:panelGrid columns="4">
<p:panelGrid columns="6">
<p:outputLabel value="Nombre:" for="nombre" />
<p:inputText id="nombre" value="#{demoBeanMarca.marca.nombre}"
@ -37,6 +37,12 @@
required="true"/>
<p:message for="nombre"/>
<p:outputLabel value="Rutafoto:" for="rutafoto" />
<p:inputText id="rutafoto" value="#{demoBeanMarca.marca.rutafoto}"
title="Direccion Imagen"
required="true"/>
<p:message for="nombre"/>
</p:panelGrid>
<p:commandButton action="#{demoBeanMarca.agregarMarca()}"

6
si-war/web/Provedor.xhtml

@ -23,8 +23,8 @@
<h:form>
<p:growl id="messages"/>
<!-- <p:menubar>
<p:menuitem value="Agregar" icon="pi pi-fw pi-plus" action="ProvedorCrear.xhtml"
<p:menubar>
<p:menuitem value="Agregar" disabled="#{!demoBeanLogin.permisos}" icon="pi pi-fw pi-plus" action="ProvedorCrear.xhtml "
actionListener="#{demoBeanProvedor.prepararNuevo()}"/>
@ -37,7 +37,7 @@
<p:menuitem value="Usuario" icon="pi pi-fw pi-user" action="Usuario.xhtml"/>
<p:menuitem value="Inicio" icon="pi pi-fw pi-home" action="Menu.xhtml"/>
<p:divider layout="vertical"/>
</p:menubar>-->
</p:menubar>
</h:form>
</div>
</ui:define>

38
si-war/web/Usuario.xhtml

@ -31,7 +31,7 @@
<!-- comment <p:menuitem value="Registro" icon="pi pi-fw pi-book " disabled="true" action="Registro.xhtml"/> -->
<p:menuitem value="Tipo" icon="pi pi-fw pi-table" action="Tipo.xhtml"/>
<p:menuitem value="Usuario" icon="pi pi-fw pi-user" disabled="true" action="Usuario.xhtml"/>
<p:menuitem value="Inicio" icon="pi pi-fw pi-home" action="Menu.xhtml"/>
<!-- comment <p:menuitem value="Inicio" icon="pi pi-fw pi-home" action="Menu.xhtml"/>-->
<p:divider layout="vertical"/>
</p:menubar>
</h:form>
@ -65,25 +65,19 @@
placeholder="Buscar" />
</div>
</f:facet>
<p:column style="width: 10px;">
<p:column>
<f:facet name="header">
<h:outputText value="Id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column >
<p:column>
<f:facet name="header">
<h:outputText value="Nombre"/>
</f:facet>
<h:outputText value="#{item.nombre}"/>
</p:column>
<p:column style="width: 20px;">
<f:facet name="header">
<h:outputText value="Sexo"/>
</f:facet>
<h:outputText value="#{item.sexo}"/>
</p:column>
<p:column style="width: 50px;">
<p:column>
<f:facet name="header">
<h:outputText value="Telefono"/>
</f:facet>
@ -101,30 +95,6 @@
</f:facet>
<h:outputText value="#{item.direccion}"/>
</p:column>
<p:column style="width: 50px;">
<f:facet name="header">
<h:outputText value="Estado"/>
</f:facet>
<h:outputText value="#{item.estadoIdestado}"/>
</p:column>
<p:column style="width: 15px;">
<f:facet name="header">
<h:outputText value="Rol"/>
</f:facet>
<h:outputText value="#{item.rolIdrol}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Password"/>
</f:facet>
<h:outputText value="#{item.npila}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Username"/>
</f:facet>
<h:outputText value="#{item.username}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Status"/>

41
si-war/web/WEB-INF/faces-config.xml

@ -0,0 +1,41 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<lifecycle>
<phase-listener>
hola.seguridad.AutorizacionListener
</phase-listener>
</lifecycle>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>accesoDenegado</from-outcome>
<to-view-id>/producto.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>

8
si-war/web/WEB-INF/web.xml

@ -19,6 +19,12 @@
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/Menu.xhtml</welcome-file>
<welcome-file>faces/Producto.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
</web-app>

66
si-war/web/index.xhtml

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/Other/xhtml.xhtml to edit this template
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="./css/default.css"/>
<h:outputStylesheet name="./css/cssLayout.css"/>
<title>Facelets Template</title>
<style>
</style>
</h:head>
<center>
<h:body style="text-align: center">
<h2> Inventario almacen </h2>
<h:form>
<p:panel header="Login" style="width:300px">
<h:panelGrid columns="1" cellpadding="5">
<p:inputText id="usuario"
value="#{demoBeanLogin.usuarios.username}"
title='nombre'
required="true"
requiredMessage="Este campo no puede estar vacio"
placeholder="Ingrese el usuario">
</p:inputText>
<p:password id="contrasenia"
value="#{demoBeanLogin.usuarios.npila}"
title="contraseña"
redisplay="true"
required="true"
requiredMessage="Este campo no puede estar vacio"
placeholder="Ingrse la contraseña"
style="width: 223px">
</p:password>
<p:commandButton value="Login"
action="#{demoBeanLogin.login()}"
ajax="false" />
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</center>
</html>

11
si-war/web/template/Principal.xhtml

@ -2,7 +2,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
@ -21,6 +22,14 @@
<h:body>
<div id="top">
<h:form>
<p:commandButton action="#{demoBeanLogin.logout()}"
immediate="true"
ajax="false"
style="margin-left: 5px; width: 50px; "
icon="pi pi-times"
styleClass="ui-button-danger"/>
</h:form>
<ui:insert name="top">Top</ui:insert>
</div>
<div>

Loading…
Cancel
Save