Advertisement
Guest User

prueba

a guest
Jan 10th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.30 KB | None | 0 0
  1. <?xml version='1.0' encoding='UTF-8' ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml"
  4.       xmlns:h="http://xmlns.jcp.org/jsf/html">
  5.     <h:head>
  6.         <title>Examen Práctico TSIR</title>
  7.         <h:outputStylesheet name="css/jsfcrud.css"/>
  8.     </h:head>
  9.     <h:body>
  10.         <h1>Agenda Online Counselors</h1>
  11.         <h2>Raul Llopis -- Apartado 01</h2>
  12.        
  13.         <h:button outcome="/counselor/List" value="Consultas"/>
  14.         &nbsp;&nbsp;
  15.         <h:button outcome="/login" value="Aministracion"/>
  16.     </h:body>
  17.  
  18.  
  19. </html>
  20.  
  21.  
  22. --------------login
  23. <?xml version='1.0' encoding='UTF-8' ?>
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml"
  26.       xmlns:h="http://xmlns.jcp.org/jsf/html">
  27.     <h:head>
  28.         <title>Examen Práctico TSIR</title>
  29.         <h:outputStylesheet name="css/jsfcrud.css"/>
  30.     </h:head>
  31.     <h:body>
  32.         <h1>Agenda Online Counselors</h1>
  33.         <h2>Raul Llopis -- Apartado 03</h2>
  34.         <h:panelGroup rendered="#{!login.logueado}">
  35.             <h:form>
  36.                 <h:panelGrid columns="2">
  37.                     <h:outputText value="Usuario: " />
  38.                     <h:inputText value="#{login.email}" />
  39.                     <h:outputText value="Contraseña: " />
  40.                     <h:inputSecret value="#{login.password}" />
  41.                 </h:panelGrid>
  42.                 <h:commandButton action="#{login.loguear()}" value="Login" />
  43.                 <h:button outcome="/alta" value="Alta"/>
  44.                
  45.  
  46.             </h:form>
  47.         </h:panelGroup>
  48.         <!--
  49.             <br />
  50.             <h:panelGroup rendered="#{login.logueado}" >
  51.                 <h:panelGroup rendered="#{carrito.hayFosiles() || carrito.hayMinerales()}">
  52.                     <h:outputText value="#{bundle.TotalPagar}: " /><h:outputText value="#{carrito.totalCarrito()}" />
  53.                     <br />
  54.                     <h:outputText value="#{bundle.i_nombre}" />
  55.                     <br />
  56.                     <h:inputText value="#{tienda.nombre}" required="true" requiredMessage="#{bundle.e_introducir_nombre}" />
  57.                     <br />
  58.                     <h:outputText value="#{bundle.i_apellidos}" />
  59.                     <br />
  60.                     <h:inputText value="#{tienda.apellidos}" required="true" requiredMessage="#{bundle.e_introducir_apellidos}" />
  61.                     <br />
  62.                     <h:outputText value="#{bundle.i_direccion}" />
  63.                     <br />
  64.                     <h:inputText value="#{tienda.direccion}" required="true" requiredMessage="#{bundle.e_introducir_direccion}" />
  65.                     <br />
  66.                     <h:outputText value="#{bundle.i_pais}" />
  67.                     <br />
  68.                     <h:inputText value="#{tienda.pais}" required="true" requiredMessage="#{bundle.e_introducir_pais}" />
  69.                     <br />
  70.                     <h:outputText value="#{bundle.i_tarjeta}" /><br />
  71.                     <h:inputText value="#{tienda.tarjeta}" required="true" requiredMessage="#{bundle.e_introducir_tarjeta}" />
  72.                     <br />
  73.                     <h:commandButton value="#{bundle.ContinuarPago}" action="#{tienda.facturar()}" />
  74.                 </h:panelGroup>
  75.             </h:panelGroup>
  76.         -->
  77.     </h:body>
  78.  
  79.  
  80. </html>
  81.  
  82.  
  83.  
  84. ------------- alta
  85. <?xml version='1.0' encoding='UTF-8' ?>
  86. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  87. <html xmlns="http://www.w3.org/1999/xhtml"
  88.       xmlns:h="http://xmlns.jcp.org/jsf/html">
  89.     <h:head>
  90.         <title>Examen Práctico TSIR</title>
  91.         <h:outputStylesheet name="css/jsfcrud.css"/>
  92.     </h:head>
  93.     <h:body>
  94.         <h1>Agenda Online Counselors</h1>
  95.         <h2>Raul Llopis -- Apartado 04</h2>
  96.        
  97.         <h:form>
  98.             First name:
  99.             <input type="text" name="firstname"><br></br></input>
  100.             Nick name:
  101.             <input type="text" name="nickname"><br></br></input>
  102.             Last name:
  103.             <input type="text" name="lastname"><br></br></input>
  104.             Telephone:        
  105.             <input type="text" name="telephone"><br></br></input>
  106.             Email:
  107.             <input type="text" name="email"><br></br></input>
  108.             Memeber Since:
  109.             <input type="text" name="membersince"><br></br></input>
  110.         </h:form>
  111.        
  112.         <h:button outcome="/index" value="Add"/>
  113.         &nbsp;&nbsp;
  114.         <h:button outcome="/index" value="Reset"/>
  115.         <h:button outcome="/index" value="Back"/>
  116.         -->
  117.     </h:body>
  118.  
  119.  
  120. </html>
  121.  
  122.  
  123.  
  124. -------login controller
  125. package jsf;
  126.  
  127. import java.sql.Connection;
  128. import java.sql.DriverManager;
  129. import java.sql.ResultSet;
  130. import java.sql.SQLException;
  131. import java.sql.Statement;
  132. import javax.faces.bean.ManagedBean;
  133. import javax.faces.bean.SessionScoped;
  134.  
  135. /*
  136.  * To change this license header, choose License Headers in Project Properties.
  137.  * To change this template file, choose Tools | Templates
  138.  * and open the template in the editor.
  139.  */
  140. /**
  141.  *
  142.  * @author lopoa_000
  143.  */
  144. @ManagedBean (name = "login")
  145. @SessionScoped
  146. public class LoginController{
  147.  
  148.     boolean logueado = false;
  149.     private String email;
  150.     private String password;
  151.     Connection conn = null;
  152.  
  153.     public boolean getLogueado() {
  154.         return logueado;
  155.     }
  156.  
  157.     public void setLogueado( boolean l) {
  158.         this.logueado = l;
  159.     }
  160.  
  161.     public void setEmail(String email) {
  162.         this.email = email;
  163.     }
  164.  
  165.     public String getPassword() {
  166.         return password;
  167.     }
  168.  
  169.     public void setPassword(String password) {
  170.         this.password = password;
  171.     }
  172.  
  173.     public String getEmail() {
  174.         return email;
  175.     }
  176.    
  177.     public void logout()
  178.     {
  179.         email = "";
  180.         password = "";
  181.         logueado = false;
  182.     }
  183.    
  184.     public void loguear() {
  185.         Statement stmt = null;
  186.         ResultSet rs = null;
  187.         String conexion = "jdbc:mysql://localhost:3306/tsir54?user=root&password=admin";
  188.         String query = "SELECT * FROM usuarios WHERE email = '" + getEmail() + "' AND password = '" + getPassword() + "'";
  189.  
  190.         try {
  191.             conn = DriverManager.getConnection(conexion);
  192.             stmt = conn.createStatement();
  193.             rs = stmt.executeQuery(query);
  194.  
  195.             if ( rs.first() )
  196.                 setLogueado( true );
  197.             else
  198.                 setLogueado( false );
  199.  
  200.         } catch (SQLException ex) {
  201.             System.out.println("SQLException: " + ex.getMessage());
  202.             System.out.println("SQLState: " + ex.getSQLState());
  203.             System.out.println("VendorError: " + ex.getErrorCode());
  204.         } finally {
  205.             if (rs != null) {
  206.                 try {
  207.                     rs.close();
  208.                 } catch (SQLException sqlEx) {
  209.                 } // ignore
  210.  
  211.                 rs = null;
  212.             }
  213.  
  214.             if (stmt != null) {
  215.                 try {
  216.                     stmt.close();
  217.                 } catch (SQLException sqlEx) {
  218.                 }
  219.  
  220.                 stmt = null;
  221.             }
  222.         }
  223.     }
  224.    
  225.    
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement