From 545f36dc02ce652b8929fc7247475a4007648c7b Mon Sep 17 00:00:00 2001 From: devfzn Date: Sun, 3 Sep 2023 16:06:35 -0300 Subject: [PATCH] Encrypt passwords, Controller+DAO & db bash script --- .gitignore | 1 + README.md | 61 ++++--- createdb.sh | 17 ++ database/create_populate.sql | 57 +++++++ database/creation_stmnt.sql | 24 ++- database/er_diagram.mwb | Bin 6103 -> 6903 bytes pom.xml | 5 + .../hotel/controller/HuespedController.java | 26 +++ .../hotel/controller/ReservaController.java | 39 +++++ src/cl/com/alura/hotel/dao/HuespedDAO.java | 60 +++++++ src/cl/com/alura/hotel/dao/ReservaDAO.java | 156 ++++++++++++++++++ .../hotel/factory/ConnectionFactory.java | 12 +- src/cl/com/alura/hotel/modelo/Huesped.java | 91 +++++++++- src/cl/com/alura/hotel/modelo/Reserva.java | 14 +- .../hotel/pruebas/PruebaEncryptPass.java | 21 +++ .../hotel/pruebas/PruebaQueryInsert.java | 42 +++++ .../alura/hotel/pruebas/PruebaQueryJoin.java | 57 +++++++ .../hotel/pruebas/PruebaQuerySelect.java | 46 ++++++ .../com/alura/hotel/pruebas/PruebasDao.java | 28 ++++ src/cl/com/alura/hotel/utils/GetEnvVars.java | 33 ++++ src/cl/com/alura/hotel/utils/PassEncrypt.java | 16 ++ .../alura/hotel/views/RegistroHuesped.java | 101 ++++++------ src/module-info.java | 15 -- 23 files changed, 804 insertions(+), 118 deletions(-) create mode 100755 createdb.sh create mode 100644 database/create_populate.sql create mode 100644 src/cl/com/alura/hotel/controller/HuespedController.java create mode 100644 src/cl/com/alura/hotel/controller/ReservaController.java create mode 100644 src/cl/com/alura/hotel/dao/HuespedDAO.java create mode 100644 src/cl/com/alura/hotel/dao/ReservaDAO.java create mode 100644 src/cl/com/alura/hotel/pruebas/PruebaEncryptPass.java create mode 100644 src/cl/com/alura/hotel/pruebas/PruebaQueryInsert.java create mode 100644 src/cl/com/alura/hotel/pruebas/PruebaQueryJoin.java create mode 100644 src/cl/com/alura/hotel/pruebas/PruebaQuerySelect.java create mode 100644 src/cl/com/alura/hotel/pruebas/PruebasDao.java create mode 100644 src/cl/com/alura/hotel/utils/GetEnvVars.java create mode 100644 src/cl/com/alura/hotel/utils/PassEncrypt.java delete mode 100644 src/module-info.java diff --git a/.gitignore b/.gitignore index e12a3c8..aa9e0be 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .settings/ bin/ target/*/ +*.bak diff --git a/README.md b/README.md index 31b7c8d..8317683 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ DBADDR=address DBNAME=database DBUSER=user DBPASS=password +PEPPER=random-string ``` #### Modelo entidad relación @@ -73,26 +74,26 @@ DBPASS=password ```mermaid erDiagram HUESPED ||..o{ RESERVA : tiene - HUESPED { - id int PK "NN" - nombre varchar - apellido varchar - fecha_nacimiento date "AAAA-MM-DD" - nacionalidad varchar - telefono varchar "+00 123456789" - } - - RESERVA { - Id int PK "NN" - fecha_entrada date "AAAA-MM-DD" - fecha_salida date "AAAA-MM-DD" - valor int "Costo total de la reserva" - forma_pago varchar "debito, credito, efectivo, cheque" - id_huesped int FK "Huesped a quien pertenece la reserva" - } + HUESPED { + id int PK + usuario varchar UK + nombre varchar + varchar apellido + fecha_nacimiento date "AAAA-MM-DD" + nacionalidad varchar + telefono varchar + password varchar + } + RESERVA { + id int PK + fecha_entrada date "AAAA-MM-DD" + fecha_salida date "AAAA-MM-DD" + valor double + forma_pago varchar "Débito, Crédito, Efectivo" + id_huesped int FK + } ``` -
Database creation statement @@ -100,32 +101,39 @@ erDiagram [SQL script](./database/creation_stmnt.sql) ```sql -CREATE DATABASE IF NOT EXISTS `hotel_alura` DEFAULT CHARACTER SET utf8mb4 -COLLATE utf8mb4_general_ci; +CREATE DATABASE IF NOT EXISTS `hotel_alura` +DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; USE `hotel_alura`; +DELETE FROM `hotel_alura`.`huesped`; +DROP TABLE IF EXISTS `hotel_alura`.`reserva`; +DROP TABLE IF EXISTS `hotel_alura`.`huesped`; + CREATE TABLE IF NOT EXISTS `huesped` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `usuario` varchar(20) NOT NULL UNIQUE, `nombre` varchar(20) NOT NULL, `apellido` varchar(20) NOT NULL, - `fecha_nacimiento` date DEFAULT NULL, - `nacionalidad` varchar(20) DEFAULT NULL, + `fecha_nacimiento` date DEFAULT '1000-01-01', + `nacionalidad` varchar(20) DEFAULT 'chilena', `telefono` varchar(20) NOT NULL, + `password` varchar(60) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE IF NOT EXISTS `reserva` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `fecha_entrada` date NOT NULL, `fecha_salida` date NOT NULL, `valor` double NOT NULL, `forma_pago` varchar(20) NOT NULL, - `id_huesped` int(11) NOT NULL, + `id_huesped` int(11) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `id_huesped_idx` (`id_huesped`), - CONSTRAINT `id_huesped` FOREIGN KEY (`id_huesped`) REFERENCES `huesped` (`id`) + CONSTRAINT `id_huesped` FOREIGN KEY (`id_huesped`) + REFERENCES `huesped` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; @@ -147,4 +155,3 @@ etiqueta **challengeonehotelaluralatam4** ¿5? :blue_heart: Alura Latam
[](https://www.linkedin.com/company/alura-latam/mycompany/) - diff --git a/createdb.sh b/createdb.sh new file mode 100755 index 0000000..8d3e1a7 --- /dev/null +++ b/createdb.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +VersionStr='2023-09-02' +rutaprgrm=$(dirname $(realpath -s $0)) + +while read line; do + declare "$line" 2>/dev/null +done < $rutaprgrm/.env + +mysql -u ${DBUSER} \ + -p${DBPASS} \ + -h ${DBADDR%%:*} ${DBNAME} \ + -P ${DBADDR##*:} < ./database/create_populate.sql &>/dev/null && \ + echo "DB creada y poblada" || \ + echo "Ocurrio un error al intentar crear y/o poblar la DB" + +unset DBNAME DBUSER DBPASS DBADDR diff --git a/database/create_populate.sql b/database/create_populate.sql new file mode 100644 index 0000000..8e5de6a --- /dev/null +++ b/database/create_populate.sql @@ -0,0 +1,57 @@ +-- Creación de base de datos para hotel alura +CREATE DATABASE IF NOT EXISTS `hotel_alura` +DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; + +USE `hotel_alura`; + +DELETE FROM `hotel_alura`.`huesped`; +DROP TABLE IF EXISTS `hotel_alura`.`reserva`; +DROP TABLE IF EXISTS `hotel_alura`.`huesped`; + +CREATE TABLE IF NOT EXISTS `huesped` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `usuario` varchar(20) NOT NULL UNIQUE, + `nombre` varchar(20) NOT NULL, + `apellido` varchar(20) NOT NULL, + `fecha_nacimiento` date DEFAULT '1000-01-01', + `nacionalidad` varchar(20) DEFAULT 'chilena', + `telefono` varchar(20) NOT NULL, + `password` varchar(60) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +CREATE TABLE IF NOT EXISTS `reserva` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `fecha_entrada` date NOT NULL, + `fecha_salida` date NOT NULL, + `valor` double NOT NULL, + `forma_pago` varchar(20) NOT NULL, + `id_huesped` int(11) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `id_huesped_idx` (`id_huesped`), + CONSTRAINT `id_huesped` FOREIGN KEY (`id_huesped`) REFERENCES `huesped` (`id`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- Borrado de registros +DELETE FROM `hotel_alura`.`huesped`; + +-- Creación de usuarios y reservas de prueba +INSERT INTO `hotel_alura`.`huesped`(usuario, nombre, apellido, telefono, password) + VALUES('Usuario1', 'Primer', 'Huesped', '+56 123456789', + '$2a$12$Pt7d9sZxHMZHfGivVgrVvergqz.VBNFY5.oJa8g9CK3lst7/Pqeuu'); +INSERT INTO `hotel_alura`.`huesped`(usuario, nombre, apellido, telefono, password) + VALUES('Usuario2', 'Segundo', 'Huesped', '+56 123456789', + '$2a$12$Pt7d9sZxHMZHfGivVgrVvergqz.VBNFY5.oJa8g9CK3lst7/Pqeuu'); +INSERT INTO `hotel_alura`.`huesped`(usuario, nombre, apellido, telefono, password) + VALUES('Usuario3', 'Tercer', 'Huesped', '+56 123456789', + '$2a$12$Pt7d9sZxHMZHfGivVgrVvergqz.VBNFY5.oJa8g9CK3lst7/Pqeuu'); + +INSERT INTO `hotel_alura`.`reserva`(fecha_entrada, fecha_salida, valor, forma_pago, id_huesped) + VALUES('2023-09-01', '2023-09-03', 90000.00, 'efectivo', 1); +INSERT INTO `hotel_alura`.`reserva`(fecha_entrada, fecha_salida, valor, forma_pago, id_huesped) + VALUES('2023-09-04', '2023-09-05', 60000.00, 'crédito', 2); +INSERT INTO `hotel_alura`.`reserva`(fecha_entrada, fecha_salida, valor, forma_pago, id_huesped) + VALUES('2023-09-07', '2023-09-10', 120000.00, 'débito', 3); +INSERT INTO `hotel_alura`.`reserva`(fecha_entrada, fecha_salida, valor, forma_pago, id_huesped) + VALUES('2023-09-11', '2023-09-21', 330000.00, 'crédito', 1); diff --git a/database/creation_stmnt.sql b/database/creation_stmnt.sql index 6f6a6f6..6c92cb3 100644 --- a/database/creation_stmnt.sql +++ b/database/creation_stmnt.sql @@ -1,25 +1,35 @@ -CREATE DATABASE IF NOT EXISTS `hotel_alura` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; +-- Creación de base de datos para hotel alura +CREATE DATABASE IF NOT EXISTS `hotel_alura` +DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; USE `hotel_alura`; +DELETE FROM `hotel_alura`.`huesped`; +DROP TABLE IF EXISTS `hotel_alura`.`reserva`; +DROP TABLE IF EXISTS `hotel_alura`.`huesped`; + CREATE TABLE IF NOT EXISTS `huesped` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `usuario` varchar(20) NOT NULL UNIQUE, `nombre` varchar(20) NOT NULL, `apellido` varchar(20) NOT NULL, - `fecha_nacimiento` date DEFAULT NULL, - `nacionalidad` varchar(20) DEFAULT NULL, + `fecha_nacimiento` date DEFAULT '1000-01-01', + `nacionalidad` varchar(20) DEFAULT 'chilena', `telefono` varchar(20) NOT NULL, + `password` varchar(60) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE IF NOT EXISTS `reserva` ( - `id` int(11) NOT NULL AUTO_INCREMENT, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `fecha_entrada` date NOT NULL, `fecha_salida` date NOT NULL, `valor` double NOT NULL, `forma_pago` varchar(20) NOT NULL, - `id_huesped` int(11) NOT NULL, + `id_huesped` int(11) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `id_huesped_idx` (`id_huesped`), - CONSTRAINT `id_huesped` FOREIGN KEY (`id_huesped`) REFERENCES `huesped` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `id_huesped` FOREIGN KEY (`id_huesped`) REFERENCES `huesped` (`id`) + ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + diff --git a/database/er_diagram.mwb b/database/er_diagram.mwb index f23263987751fc0d17c5325c7ba92c3bf80d056c..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X)A7`tim#A^YERTOwdA9zesZ5oeW@OMpmX-qF#7#v{tbo z5)Nv3wzU?a_B0>M*qq8v?T4$Ei2RkxmXnf{ejamxA3kb)9dI*G*s$!SGBhEW)k5fG zdMo*(GeJG~Q&#SWLxiomOGkaqdp#T5nb>^P)uv@KOw}w{_ c{{LImzis`um4&F1q$X3+pv;n{)>F#=7dTQcx&QzG diff --git a/pom.xml b/pom.xml index b4f7a70..f81a4e2 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,11 @@ dotenv-java 3.0.0 + + org.mindrot + jbcrypt + 0.4 + src diff --git a/src/cl/com/alura/hotel/controller/HuespedController.java b/src/cl/com/alura/hotel/controller/HuespedController.java new file mode 100644 index 0000000..19e7e69 --- /dev/null +++ b/src/cl/com/alura/hotel/controller/HuespedController.java @@ -0,0 +1,26 @@ +package cl.com.alura.hotel.controller; + +import java.util.List; + +import cl.com.alura.hotel.dao.HuespedDAO; +import cl.com.alura.hotel.factory.ConnectionFactory; +import cl.com.alura.hotel.modelo.Huesped; + +public class HuespedController { + + private HuespedDAO huespedDAO; + + public HuespedController() { + ConnectionFactory factory = new ConnectionFactory(); + this.huespedDAO = new HuespedDAO(factory.getConexion()); + } + + public List listar(Huesped huesped) { + return huespedDAO.listar(huesped.getId()); + } + +// public List cargaReporte() { +// return this.huespedDAO.listarConReservas(); +// } + +} diff --git a/src/cl/com/alura/hotel/controller/ReservaController.java b/src/cl/com/alura/hotel/controller/ReservaController.java new file mode 100644 index 0000000..5062ea4 --- /dev/null +++ b/src/cl/com/alura/hotel/controller/ReservaController.java @@ -0,0 +1,39 @@ +package cl.com.alura.hotel.controller; + +import java.util.List; + +import cl.com.alura.hotel.factory.ConnectionFactory; +import cl.com.alura.hotel.dao.ReservaDAO; +import cl.com.alura.hotel.modelo.Huesped; +import cl.com.alura.hotel.modelo.Reserva; + +public class ReservaController { + + private ReservaDAO reservaDAO; + + public ReservaController() { + this.reservaDAO = new ReservaDAO(new ConnectionFactory().getConexion()); + } + + public int modificar(Reserva reserva) { + return reservaDAO.modificar(reserva); + } + + public int eliminar(Integer id) { + return reservaDAO.eliminar(id); + } + + public List listar() { + return reservaDAO.listar(0); + } + + public List listar(Huesped huesped) { + return reservaDAO.listar(huesped.getId()); + } + + public void guardar(Reserva reserva, Integer huespedId) { + reserva.setIdHuesped(huespedId); + reservaDAO.guardar(reserva); + } + +} diff --git a/src/cl/com/alura/hotel/dao/HuespedDAO.java b/src/cl/com/alura/hotel/dao/HuespedDAO.java new file mode 100644 index 0000000..7d6d3f7 --- /dev/null +++ b/src/cl/com/alura/hotel/dao/HuespedDAO.java @@ -0,0 +1,60 @@ +package cl.com.alura.hotel.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import cl.com.alura.hotel.modelo.Huesped; + +public class HuespedDAO { + + private final Connection con; + + public HuespedDAO(Connection conexion) { + this.con = conexion; + } + + public List listar(Integer huesped_id) { + final String query; + if (huesped_id != 0) { + query = "SELECT * FROM huesped WHERE id=?;"; + } else { + query = "SELECT * FROM huesped;"; + } + List resultado = new ArrayList<>(); + try { + final PreparedStatement statement; + if (huesped_id != 0) { + statement = con.prepareStatement(query); + statement.setInt(1, huesped_id); + System.out.println(statement.toString()); + } else { + statement = con.prepareStatement(query); + System.out.println(statement.toString()); + } + try (statement) { + statement.execute(); + ResultSet resultSet = statement.getResultSet(); + while (resultSet.next()) { + Huesped fila = new Huesped( + resultSet.getInt("id"), + resultSet.getString("usuario"), + resultSet.getString("nombre"), + resultSet.getString("apellido"), + resultSet.getDate("fecha_nacimiento"), + resultSet.getString("nacionalidad"), + resultSet.getString("telefono") + ); + resultado.add(fila); + } + return resultado; + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/src/cl/com/alura/hotel/dao/ReservaDAO.java b/src/cl/com/alura/hotel/dao/ReservaDAO.java new file mode 100644 index 0000000..50120f7 --- /dev/null +++ b/src/cl/com/alura/hotel/dao/ReservaDAO.java @@ -0,0 +1,156 @@ +package cl.com.alura.hotel.dao; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import cl.com.alura.hotel.modelo.Reserva; +//import cl.com.alura.hotel.modelo.Huesped; + +public class ReservaDAO { + + private final Connection con; + + public ReservaDAO(Connection conexion) { + this.con = conexion; + } + + public void guardar(Reserva reserva) { + final String query = "INSERT INTO reserva(huesped_id,checkin,checkout,valor,pago)" + + "VALUES(?,?,?,?)"; + try { + final PreparedStatement statement = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); + try (statement) { + ejecutaRegistro(reserva, statement); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + private void ejecutaRegistro(Reserva reserva, PreparedStatement statement) + throws SQLException { + statement.setInt(1, reserva.getIdHuesped()); + statement.setDate(2, (Date) reserva.getFechaEntrada()); + statement.setDate(3, (Date) reserva.getFechaSalida()); + statement.setDouble(4, reserva.getValor()); + statement.setString(5, reserva.getFormaPago()); + statement.execute(); + final ResultSet resultSet = statement.getGeneratedKeys(); + try (resultSet) { + while (resultSet.next()) { + reserva.setId(resultSet.getInt(1)); + System.out.println(String.format("Reserva agregada %s: ", reserva)); + } + } + } + + public List listar(Integer huesped_id) { + final String query; + if (huesped_id != 0) { + query = "SELECT * FROM reserva WHERE id_huesped=?;"; + } else { + query = "SELECT * FROM reserva;"; + } + List resultado = new ArrayList<>(); + try { + final PreparedStatement statement; + if (huesped_id != 0) { + statement = con.prepareStatement(query); + statement.setInt(1, huesped_id); + System.out.println(statement.toString()); + } else { + statement = con.prepareStatement(query); + System.out.println(statement.toString()); + } + try (statement) { + statement.execute(); + ResultSet resultSet = statement.getResultSet(); + while (resultSet.next()) { + Reserva fila = new Reserva( + resultSet.getInt("id"), + resultSet.getDate("fecha_entrada"), + resultSet.getDate("fecha_salida"), + resultSet.getDouble("valor"), + resultSet.getString("forma_pago"), + resultSet.getInt("id_huesped") + ); + resultado.add(fila); + } + return resultado; + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + public int modificar(Reserva reserva) { + try { + final String query = "UPDATE categoria SET valor=? WHERE id=?;"; + final PreparedStatement statement = con.prepareStatement(query); + try (statement) { + statement.setInt(1, reserva.getId()); + statement.setDouble(2, reserva.getValor()); + statement.execute(); + int resultado = statement.getUpdateCount(); + return resultado; + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + public int eliminar(Integer id) { + try { + final PreparedStatement statement = con.prepareStatement("DELETE FROM reserva WHERE id=?;"); + try (statement) { + statement.setInt(1, id); + statement.execute(); + int resultado = statement.getUpdateCount(); + return resultado; + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + +// public List listarConProductos() { +// List resultado = new ArrayList<>(); +// final String query = "SELECT C.ID, C.NOMBRE, P.ID, P.NOMBRE, P.CANTIDAD FROM categoria C " +// + "INNER JOIN producto P ON C.ID = P.CATEGORIA_ID "; +// System.out.println(query); +// try { +// final PreparedStatement statement = con.prepareStatement(query); +// try (statement) { +// statement.execute(); +// final ResultSet resultSet = statement.getResultSet(); +// try (resultSet){ +// while (resultSet.next()) { +// Integer categoriaId = resultSet.getInt("C.ID"); +// String categoriaNombre = resultSet.getString("C.NOMBRE"); +// var categoria = resultado +// .stream() +// .filter(cat -> cat.getId().equals(categoriaId)) +// .findAny().orElseGet(() -> { +// Categoria cat = new Categoria(categoriaId, categoriaNombre); +// resultado.add(cat); +// return cat; +// }); +// Reserva producto = new Reserva(resultSet.getInt("P.ID"), +// resultSet.getString("P.NOMBRE"), +// resultSet.getInt("P.CANTIDAD")); +// categoria.agregar(producto); +// } +// }; +// } +// } catch (SQLException e) { +// throw new RuntimeException(e); +// } +// return resultado; +// } + +} \ No newline at end of file diff --git a/src/cl/com/alura/hotel/factory/ConnectionFactory.java b/src/cl/com/alura/hotel/factory/ConnectionFactory.java index 250c6b9..2ace3fd 100644 --- a/src/cl/com/alura/hotel/factory/ConnectionFactory.java +++ b/src/cl/com/alura/hotel/factory/ConnectionFactory.java @@ -4,7 +4,8 @@ import java.sql.Connection; import javax.sql.DataSource; import com.mchange.v2.c3p0.ComboPooledDataSource; -import io.github.cdimascio.dotenv.Dotenv; + +import cl.com.alura.hotel.utils.GetEnvVars; public class ConnectionFactory { @@ -15,14 +16,13 @@ public class ConnectionFactory { private DataSource datasource; public ConnectionFactory() { - Dotenv dotenv = Dotenv.load(); - dbname = dotenv.get("DBNAME"); - dbaddr = dotenv.get("DBADDR"); + dbname = GetEnvVars.getDbname(); + dbaddr = GetEnvVars.getDbaddr(); final String dburl = driver + dbaddr +"/"+ dbname + params; var pooledDataSource = new ComboPooledDataSource(); pooledDataSource.setJdbcUrl(dburl); - pooledDataSource.setUser(dotenv.get("DBUSER")); - pooledDataSource.setPassword(dotenv.get("DBPASS")); + pooledDataSource.setUser(GetEnvVars.getDbuser()); + pooledDataSource.setPassword(GetEnvVars.getDbpass()); pooledDataSource.setMaxPoolSize(500); this.datasource = pooledDataSource; } diff --git a/src/cl/com/alura/hotel/modelo/Huesped.java b/src/cl/com/alura/hotel/modelo/Huesped.java index 3861dd3..1101871 100644 --- a/src/cl/com/alura/hotel/modelo/Huesped.java +++ b/src/cl/com/alura/hotel/modelo/Huesped.java @@ -7,16 +7,31 @@ import java.util.List; public class Huesped { private Integer id; - private Integer nombre; - private Integer apellido; + private String usuario; + private String nombre; + private String apellido; private Date fechaNacimiento; private String nacionalidad; private String telefono; + private String password; private List reservas; - public Huesped(Integer id, Integer nombre, Integer apellido, Date fechaNacimiento, - String nacionalidad, String telefono) { + public Huesped(Integer id, String usuario, String nombre, String apellido, + Date fechaNacimiento, String nacionalidad, String telefono, + String password) { this.id = id; + this.usuario = usuario; + this.nombre = nombre; + this.apellido = apellido; + this.fechaNacimiento = fechaNacimiento; + this.nacionalidad = nacionalidad; + this.telefono = telefono; + this.password = password; + } + + public Huesped(String usuario, String nombre, String apellido, + Date fechaNacimiento, String nacionalidad, String telefono) { + this.usuario = usuario; this.nombre = nombre; this.apellido = apellido; this.fechaNacimiento = fechaNacimiento; @@ -24,6 +39,38 @@ public class Huesped { this.telefono = telefono; } + public Huesped(String usuario, String nombre, String apellido, + String nacionalidad, String telefono, String password) { + this.usuario = usuario; + this.nombre = nombre; + this.apellido = apellido; + this.nacionalidad = nacionalidad; + this.telefono = telefono; + this.password = password; + } + + public Huesped(Integer id, String usuario, String nombre, String apellido, + Date fechaNacimiento, String password, String telefono) { + this.id = id; + this.usuario = usuario; + this.nombre = nombre; + this.apellido = apellido; + this.fechaNacimiento = fechaNacimiento; + this.telefono = telefono; + this.password = password; + } + + public Huesped(String usuario, String nombre, String apellido, + String telefono, String password) { + this.usuario = usuario; + this.nombre = nombre; + this.apellido = apellido; + this.telefono = telefono; + this.password = password; + } + + public Huesped() {} + public Integer getId() { return id; } @@ -32,22 +79,38 @@ public class Huesped { this.id = id; } - public Integer getNombre() { + public String getUsuario() { + return usuario; + } + + public void setUsuario(String usuario) { + this.usuario = usuario; + } + + public String getNombre() { return nombre; } - public void setNombre(Integer nombre) { + public void setNombre(String nombre) { this.nombre = nombre; } - public Integer getApellido() { + public String getApellido() { return apellido; } - public void setApellido(Integer apellido) { + public void setApellido(String apellido) { this.apellido = apellido; } + + public void setPassword(String password) { + this.password = password; + } + public String getPassword() { + return this.password; + } + public Date getFechaNacimiento() { return fechaNacimiento; } @@ -83,5 +146,15 @@ public class Huesped { this.reservas.add(reserva); } - // TODO toString(); + @Override + public String toString() { + return "Huesped [" + (id != null ? "id=" + id + ", " : "") + + (usuario != null ? "usuario=" + usuario + ", " : "") + + (nombre != null ? "nombre=" + nombre + ", " : "") + + (apellido != null ? "apellido=" + apellido + ", " : "") + + (fechaNacimiento != null ? "fechaNacimiento=" + fechaNacimiento + ", " : "") + + (nacionalidad != null ? "nacionalidad=" + nacionalidad + ", " : "") + + (telefono != null ? "telefono=" + telefono : "") + "]"; + } + } \ No newline at end of file diff --git a/src/cl/com/alura/hotel/modelo/Reserva.java b/src/cl/com/alura/hotel/modelo/Reserva.java index d0fc4f9..0116db4 100644 --- a/src/cl/com/alura/hotel/modelo/Reserva.java +++ b/src/cl/com/alura/hotel/modelo/Reserva.java @@ -20,6 +20,8 @@ public class Reserva { this.idHuesped = idHuesped; } + public Reserva() {} + public Integer getId() { return id; } @@ -67,6 +69,14 @@ public class Reserva { public void setIdHuesped(Integer idHuesped) { this.idHuesped = idHuesped; } - - // TODO toString(); + + @Override + public String toString() { + return "Reserva [" + (idHuesped != null ? "idHuesped=" + idHuesped + ", " : "") + + (id != null ? "id=" + id + ", " : "") + + (fechaEntrada != null ? "fechaEntrada=" + fechaEntrada + ", " : "") + + (fechaSalida != null ? "fechaSalida=" + fechaSalida + ", " : "") + + (valor != null ? "valor=" + valor + ", " : "") + (formaPago != null ? "formaPago=" + formaPago : "") + + "]"; + } } diff --git a/src/cl/com/alura/hotel/pruebas/PruebaEncryptPass.java b/src/cl/com/alura/hotel/pruebas/PruebaEncryptPass.java new file mode 100644 index 0000000..ca0d81f --- /dev/null +++ b/src/cl/com/alura/hotel/pruebas/PruebaEncryptPass.java @@ -0,0 +1,21 @@ +package cl.com.alura.hotel.pruebas; + +import cl.com.alura.hotel.utils.PassEncrypt; + +public class PruebaEncryptPass { + + public static void main(String[] args) { + + String password = "ést@ és 1 pru3ba!"; + String password2 = "ést@"; + + String hashed = PassEncrypt.passEncrypt(password); + String hashed2 = PassEncrypt.passEncrypt(password2); + String hashed3 = PassEncrypt.passEncrypt("test"); + + System.out.println(PassEncrypt.passMatch(password, hashed)); // true + System.out.println(PassEncrypt.passMatch(password, hashed2)); // false + System.out.println(PassEncrypt.passMatch("test", hashed3)); // true + } + +} diff --git a/src/cl/com/alura/hotel/pruebas/PruebaQueryInsert.java b/src/cl/com/alura/hotel/pruebas/PruebaQueryInsert.java new file mode 100644 index 0000000..992f3b2 --- /dev/null +++ b/src/cl/com/alura/hotel/pruebas/PruebaQueryInsert.java @@ -0,0 +1,42 @@ +package cl.com.alura.hotel.pruebas; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +import cl.com.alura.hotel.factory.ConnectionFactory; +import cl.com.alura.hotel.modelo.Huesped; +import cl.com.alura.hotel.utils.PassEncrypt; + +public class PruebaQueryInsert { + + public static void main(String[] args) { + + Huesped huesped = new Huesped("UsuarioTest", "NombreTest", "ApellidoTest", + "+56 987654321", "test"); + String query = "INSERT INTO huesped(usuario, nombre, apellido, telefono, password)" + + " VALUES(?,?,?,?,?);"; + + try { + Connection con = new ConnectionFactory().getConexion(); + final PreparedStatement stmnt = con.prepareStatement(query); + stmnt.setString(1, huesped.getUsuario()); + stmnt.setString(2, huesped.getNombre()); + stmnt.setString(3, huesped.getApellido()); + stmnt.setString(4, huesped.getTelefono()); + stmnt.setString(5, PassEncrypt.passEncrypt(huesped.getPassword())); + System.out.println(stmnt.toString()); + stmnt.execute(); + int resultado = stmnt.getUpdateCount(); + System.out.println(resultado+" huesped registrado"); + } catch (SQLException e) { + if (e.getSQLState().startsWith("23")) { + System.out.println("Usuario ya existe"); + } else { + e.printStackTrace(); + //throw new RuntimeException(e); + } + } + } + +} diff --git a/src/cl/com/alura/hotel/pruebas/PruebaQueryJoin.java b/src/cl/com/alura/hotel/pruebas/PruebaQueryJoin.java new file mode 100644 index 0000000..e5e6955 --- /dev/null +++ b/src/cl/com/alura/hotel/pruebas/PruebaQueryJoin.java @@ -0,0 +1,57 @@ +package cl.com.alura.hotel.pruebas; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import com.mysql.cj.jdbc.result.ResultSetMetaData; + +import cl.com.alura.hotel.factory.ConnectionFactory; + +public class PruebaQueryJoin { + + public static void main(String[] args) throws SQLException { + Connection con = new ConnectionFactory().getConexion(); + String query = "SELECT H.id, H.usuario, R.valor, R.forma_pago," + + " DATEDIFF(R.fecha_salida, R.fecha_entrada)+1 AS estadia" + + " FROM huesped H INNER JOIN reserva R on R.id_huesped = H.id" + + " ORDER BY id;"; + System.out.println(query); + final PreparedStatement stmnt = con.prepareStatement(query); + stmnt.execute(); + final ResultSet resultSet = stmnt.getResultSet(); + printResult(resultSet); + } + + public static void printResult(ResultSet result) throws SQLException { + ResultSetMetaData rsmd = (ResultSetMetaData) result.getMetaData(); + int colsNum = rsmd.getColumnCount(); + + for (int i = 1; i <= colsNum; i++) { + if (i > 1) System.out.print(" "); + String header = "| "+rsmd.getColumnName(i); + System.out.print(padRight(header.toUpperCase(), 12)); + if (i == colsNum) System.out.println(" |"); + } + while (result.next()) { + for (int i = 1; i <= colsNum; i++) { + if (i > 1) System.out.print(" "); + String columnValue = result.getString(i); + System.out.print("| "+ padLeft(columnValue, 10)); + if (i == colsNum) System.out.print(" |"); + } + System.out.println(""); + } + + } + + public static String padRight(String s, int n) { + return String.format("%-" + n + "s", s); + } + + public static String padLeft(String s, int n) { + return String.format("%" + n + "s", s); + } + +} diff --git a/src/cl/com/alura/hotel/pruebas/PruebaQuerySelect.java b/src/cl/com/alura/hotel/pruebas/PruebaQuerySelect.java new file mode 100644 index 0000000..a8a7ee6 --- /dev/null +++ b/src/cl/com/alura/hotel/pruebas/PruebaQuerySelect.java @@ -0,0 +1,46 @@ +package cl.com.alura.hotel.pruebas; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import cl.com.alura.hotel.factory.ConnectionFactory; +import cl.com.alura.hotel.modelo.Huesped; +import cl.com.alura.hotel.utils.PassEncrypt; + +public class PruebaQuerySelect { + + @SuppressWarnings("static-access") + public static void main(String[] args) { + new PruebaQueryInsert().main(null);; + String query = "SELECT * FROM huesped WHERE usuario=?;"; + + try { + Connection con = new ConnectionFactory().getConexion(); + final PreparedStatement stmnt = con.prepareStatement(query); + stmnt.setString(1, "UsuarioTest"); + System.out.println(stmnt.toString()); + stmnt.execute(); + final ResultSet resultSet = stmnt.getResultSet(); + Huesped huesped = new Huesped(); + while (resultSet.next()) { + if (PassEncrypt.passMatch("test",resultSet.getString("password"))) { + huesped.setId(resultSet.getInt("id")); + huesped.setNombre(resultSet.getString("usuario")); + huesped.setNombre(resultSet.getString("nombre")); + huesped.setApellido(resultSet.getString("apellido")); + huesped.setFechaNacimiento(resultSet.getDate("fecha_nacimiento")); + huesped.setNacionalidad(resultSet.getString("nacionalidad")); + huesped.setTelefono(resultSet.getString("telefono")); + System.out.println(huesped.toString()); + } else { + System.out.println("Verifica el nombre y/o contraseña"); + } + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/src/cl/com/alura/hotel/pruebas/PruebasDao.java b/src/cl/com/alura/hotel/pruebas/PruebasDao.java new file mode 100644 index 0000000..aa161af --- /dev/null +++ b/src/cl/com/alura/hotel/pruebas/PruebasDao.java @@ -0,0 +1,28 @@ +package cl.com.alura.hotel.pruebas; + +import cl.com.alura.hotel.controller.HuespedController; +import cl.com.alura.hotel.controller.ReservaController; +import cl.com.alura.hotel.modelo.Huesped; + +public class PruebasDao { + + public static void main(String[] args) { + + HuespedController huespedControler = new HuespedController(); + Huesped huesped = new Huesped(); + huesped.setId(0); + var huesped_list = huespedControler.listar(huesped); + huesped_list.forEach(huesped_ -> System.out.println(huesped_)); + + huesped.setId(1); + var huesped_info = huespedControler.listar(huesped); + huesped_info.forEach(huesped_ -> System.out.println(huesped_)); + + ReservaController reservaController = new ReservaController(); + var reservas = reservaController.listar(); + reservas.forEach(reserva_ -> System.out.println(reserva_)); + var reserva_huesped = reservaController.listar(huesped); + reserva_huesped.forEach(reserva_ -> System.out.println(reserva_)); + } + +} diff --git a/src/cl/com/alura/hotel/utils/GetEnvVars.java b/src/cl/com/alura/hotel/utils/GetEnvVars.java new file mode 100644 index 0000000..4c46c13 --- /dev/null +++ b/src/cl/com/alura/hotel/utils/GetEnvVars.java @@ -0,0 +1,33 @@ +package cl.com.alura.hotel.utils; + +import io.github.cdimascio.dotenv.Dotenv; + +public abstract class GetEnvVars { + private final static Dotenv dotenv = Dotenv.load(); + private final static String dbname = dotenv.get("DBNAME"); + private final static String dbaddr = dotenv.get("DBADDR"); + private final static String dbuser = dotenv.get("DBUSER"); + private final static String dbpass = dotenv.get("DBPASS"); + private final static String pepper = dotenv.get("PEPPER"); + + public static String getDbname() { + return dbname; + } + + public static String getDbaddr() { + return dbaddr; + } + + public static String getDbuser() { + return dbuser; + } + + public static String getDbpass() { + return dbpass; + } + + public static String getPepper() { + return pepper; + } + +} diff --git a/src/cl/com/alura/hotel/utils/PassEncrypt.java b/src/cl/com/alura/hotel/utils/PassEncrypt.java new file mode 100644 index 0000000..1e33cb7 --- /dev/null +++ b/src/cl/com/alura/hotel/utils/PassEncrypt.java @@ -0,0 +1,16 @@ +package cl.com.alura.hotel.utils; + +import org.mindrot.jbcrypt.BCrypt; + +public abstract class PassEncrypt { + + private final static String pepper = GetEnvVars.getPepper(); + + public final static String passEncrypt(String password) { + return BCrypt.hashpw(password, BCrypt.gensalt(12) + pepper); + } + + public final static Boolean passMatch(String candidate, String password) { + return BCrypt.checkpw(candidate, password); + } +} diff --git a/src/cl/com/alura/hotel/views/RegistroHuesped.java b/src/cl/com/alura/hotel/views/RegistroHuesped.java index e33ed96..54bc783 100644 --- a/src/cl/com/alura/hotel/views/RegistroHuesped.java +++ b/src/cl/com/alura/hotel/views/RegistroHuesped.java @@ -32,7 +32,7 @@ public class RegistroHuesped extends JFrame { private JTextField txtNombre; private JTextField txtApellido; private JTextField txtTelefono; - private JTextField txtNreserva; + private JTextField txtNombreUsuario; private JDateChooser txtFechaN; private JComboBox txtNacionalidad; private JLabel labelExit; @@ -128,7 +128,7 @@ public class RegistroHuesped extends JFrame { txtNombre = new JTextField(); txtNombre.setFont(new Font("Roboto", Font.PLAIN, 16)); - txtNombre.setBounds(560, 135, 285, 33); + txtNombre.setBounds(598, 209, 243, 33); txtNombre.setBackground(Color.WHITE); txtNombre.setColumns(10); txtNombre.setBorder(javax.swing.BorderFactory.createEmptyBorder()); @@ -136,75 +136,72 @@ public class RegistroHuesped extends JFrame { txtApellido = new JTextField(); txtApellido.setFont(new Font("Roboto", Font.PLAIN, 16)); - txtApellido.setBounds(560, 204, 285, 33); + txtApellido.setBounds(598, 278, 243, 33); txtApellido.setColumns(10); txtApellido.setBackground(Color.WHITE); txtApellido.setBorder(javax.swing.BorderFactory.createEmptyBorder()); contentPane.add(txtApellido); txtFechaN = new JDateChooser(); - txtFechaN.setBounds(560, 278, 285, 36); + txtFechaN.setBounds(558, 349, 287, 36); txtFechaN.getCalendarButton() .setIcon(new ImageIcon(RegistroHuesped.class.getResource("/imagenes/icon-reservas.png"))); txtFechaN.getCalendarButton().setBackground(SystemColor.textHighlight); txtFechaN.setDateFormatString("yyyy-MM-dd"); + txtFechaN.setFont(new Font("Roboto", Font.PLAIN, 18)); contentPane.add(txtFechaN); txtNacionalidad = new JComboBox(); - txtNacionalidad.setBounds(560, 350, 289, 36); + txtNacionalidad.setBounds(558, 423, 287, 36); txtNacionalidad.setBackground(SystemColor.text); txtNacionalidad.setFont(new Font("Roboto", Font.PLAIN, 16)); - txtNacionalidad.setModel(new DefaultComboBoxModel(new String[] { "afgano-afgana", "alemán-", "alemana", - "árabe-árabe", "argentino-argentina", "australiano-australiana", "belga-belga", "boliviano-boliviana", - "brasileño-brasileña", "camboyano-camboyana", "canadiense-canadiense", "chileno-chilena", "chino-china", - "colombiano-colombiana", "coreano-coreana", "costarricense-costarricense", "cubano-cubana", - "danés-danesa", "ecuatoriano-ecuatoriana", "egipcio-egipcia", "salvadoreño-salvadoreña", - "escocés-escocesa", "español-española", "estadounidense-estadounidense", "estonio-estonia", - "etiope-etiope", "filipino-filipina", "finlandés-finlandesa", "francés-francesa", "galés-galesa", - "griego-griega", "guatemalteco-guatemalteca", "haitiano-haitiana", "holandés-holandesa", - "hondureño-hondureña", "indonés-indonesa", "inglés-inglesa", "iraquí-iraquí", "iraní-iraní", - "irlandés-irlandesa", "israelí-israelí", "italiano-italiana", "japonés-japonesa", "jordano-jordana", - "laosiano-laosiana", "letón-letona", "letonés-letonesa", "malayo-malaya", "marroquí-marroquí", - "mexicano-mexicana", "nicaragüense-nicaragüense", "noruego-noruega", "neozelandés-neozelandesa", - "panameño-panameña", "paraguayo-paraguaya", "peruano-peruana", "polaco-polaca", "portugués-portuguesa", - "puertorriqueño-puertorriqueño", "dominicano-dominicana", "rumano-rumana", "ruso-rusa", "sueco-sueca", - "suizo-suiza", "tailandés-tailandesa", "taiwanes-taiwanesa", "turco-turca", "ucraniano-ucraniana", - "uruguayo-uruguaya", "venezolano-venezolana", "vietnamita-vietnamita" })); + txtNacionalidad.setModel(new DefaultComboBoxModel(new String[] { "afgana", "alemana", + "árabe", "argentina", "australiana", "belga", "boliviana", "brasileña", + "camboyana", "canadiense", "chilena", "china", "colombiana", "coreana", + "costarricense", "cubana", "danesa", "ecuatoriana", "egipcia", "salvadoreña", + "escocesa", "española", "estadounidense", "estonia", "etiope", "filipina", + "finlandesa", "francesa", "galesa", "griega", "guatemalteca", "haitiana", + "holandesa", "hondureña", "indonesa", "inglesa", "iraquí", "iraní", "irlandesa", + "israelí", "italiana", "japonesa", "jordana", "laosiana", "letona", "letonesa", + "malaya", "marroquí", "mexicana", "nicaragüense", "noruega", "neozelandesa", + "panameña", "paraguaya", "peruana", "polaca", "portuguesa", "puertorriqueño", + "dominicana", "rumana", "rusa", "sueca", "suizo-suiza", "tailandesa", "taiwanesa", + "turca", "ucraniana", "uruguaya", "venezolana", "vietnamita" })); contentPane.add(txtNacionalidad); JLabel lblNombre = new JLabel("NOMBRE"); - lblNombre.setBounds(562, 119, 253, 14); + lblNombre.setBounds(558, 191, 253, 14); lblNombre.setForeground(SystemColor.textInactiveText); lblNombre.setFont(new Font("Roboto Black", Font.PLAIN, 18)); contentPane.add(lblNombre); JLabel lblApellido = new JLabel("APELLIDO"); - lblApellido.setBounds(560, 189, 255, 14); + lblApellido.setBounds(556, 259, 255, 14); lblApellido.setForeground(SystemColor.textInactiveText); lblApellido.setFont(new Font("Roboto Black", Font.PLAIN, 18)); contentPane.add(lblApellido); JLabel lblFechaN = new JLabel("FECHA DE NACIMIENTO"); - lblFechaN.setBounds(560, 256, 255, 14); + lblFechaN.setBounds(556, 323, 255, 14); lblFechaN.setForeground(SystemColor.textInactiveText); lblFechaN.setFont(new Font("Roboto Black", Font.PLAIN, 18)); contentPane.add(lblFechaN); JLabel lblNacionalidad = new JLabel("NACIONALIDAD"); - lblNacionalidad.setBounds(560, 326, 255, 14); + lblNacionalidad.setBounds(556, 397, 255, 14); lblNacionalidad.setForeground(SystemColor.textInactiveText); lblNacionalidad.setFont(new Font("Roboto Black", Font.PLAIN, 18)); contentPane.add(lblNacionalidad); JLabel lblTelefono = new JLabel("TELÉFONO"); - lblTelefono.setBounds(562, 406, 253, 14); + lblTelefono.setBounds(558, 477, 253, 14); lblTelefono.setForeground(SystemColor.textInactiveText); lblTelefono.setFont(new Font("Roboto Black", Font.PLAIN, 18)); contentPane.add(lblTelefono); txtTelefono = new JTextField(); txtTelefono.setFont(new Font("Roboto", Font.PLAIN, 16)); - txtTelefono.setBounds(560, 424, 285, 33); + txtTelefono.setBounds(598, 497, 243, 33); txtTelefono.setColumns(10); txtTelefono.setBackground(Color.WHITE); txtTelefono.setBorder(javax.swing.BorderFactory.createEmptyBorder()); @@ -216,52 +213,32 @@ public class RegistroHuesped extends JFrame { lblTitulo.setFont(new Font("Roboto Black", Font.PLAIN, 23)); contentPane.add(lblTitulo); - JLabel lblNumeroReserva = new JLabel("NÚMERO DE RESERVA"); - lblNumeroReserva.setBounds(560, 474, 253, 14); - lblNumeroReserva.setForeground(SystemColor.textInactiveText); - lblNumeroReserva.setFont(new Font("Roboto Black", Font.PLAIN, 18)); - contentPane.add(lblNumeroReserva); - - txtNreserva = new JTextField(); - txtNreserva.setFont(new Font("Roboto", Font.PLAIN, 16)); - txtNreserva.setBounds(560, 495, 285, 33); - txtNreserva.setColumns(10); - txtNreserva.setBackground(Color.WHITE); - txtNreserva.setBorder(javax.swing.BorderFactory.createEmptyBorder()); - contentPane.add(txtNreserva); - JSeparator separator_1_2 = new JSeparator(); - separator_1_2.setBounds(560, 170, 289, 2); + separator_1_2.setBounds(556, 244, 289, 2); separator_1_2.setForeground(new Color(12, 138, 199)); separator_1_2.setBackground(new Color(12, 138, 199)); contentPane.add(separator_1_2); JSeparator separator_1_2_1 = new JSeparator(); - separator_1_2_1.setBounds(560, 240, 289, 2); + separator_1_2_1.setBounds(556, 314, 289, 2); separator_1_2_1.setForeground(new Color(12, 138, 199)); separator_1_2_1.setBackground(new Color(12, 138, 199)); contentPane.add(separator_1_2_1); JSeparator separator_1_2_2 = new JSeparator(); - separator_1_2_2.setBounds(560, 314, 289, 2); + separator_1_2_2.setBounds(556, 386, 289, 2); separator_1_2_2.setForeground(new Color(12, 138, 199)); separator_1_2_2.setBackground(new Color(12, 138, 199)); contentPane.add(separator_1_2_2); JSeparator separator_1_2_3 = new JSeparator(); - separator_1_2_3.setBounds(560, 386, 289, 2); + separator_1_2_3.setBounds(556, 461, 289, 2); separator_1_2_3.setForeground(new Color(12, 138, 199)); separator_1_2_3.setBackground(new Color(12, 138, 199)); contentPane.add(separator_1_2_3); - JSeparator separator_1_2_4 = new JSeparator(); - separator_1_2_4.setBounds(560, 457, 289, 2); - separator_1_2_4.setForeground(new Color(12, 138, 199)); - separator_1_2_4.setBackground(new Color(12, 138, 199)); - contentPane.add(separator_1_2_4); - JSeparator separator_1_2_5 = new JSeparator(); - separator_1_2_5.setBounds(560, 529, 289, 2); + separator_1_2_5.setBounds(556, 537, 289, 2); separator_1_2_5.setForeground(new Color(12, 138, 199)); separator_1_2_5.setBackground(new Color(12, 138, 199)); contentPane.add(separator_1_2_5); @@ -333,6 +310,26 @@ public class RegistroHuesped extends JFrame { labelExit.setHorizontalAlignment(SwingConstants.CENTER); labelExit.setForeground(SystemColor.black); labelExit.setFont(new Font("Roboto", Font.PLAIN, 18)); + + txtNombreUsuario = new JTextField(); + txtNombreUsuario.setBounds(598, 143, 243, 33); + contentPane.add(txtNombreUsuario); + txtNombreUsuario.setFont(new Font("Roboto", Font.PLAIN, 16)); + txtNombreUsuario.setColumns(10); + txtNombreUsuario.setBackground(Color.WHITE); + txtNombreUsuario.setBorder(javax.swing.BorderFactory.createEmptyBorder()); + + JLabel lblNombreUsuario = new JLabel("NOMBRE DE USUARIO"); + lblNombreUsuario.setBounds(556, 121, 253, 14); + contentPane.add(lblNombreUsuario); + lblNombreUsuario.setForeground(SystemColor.textInactiveText); + lblNombreUsuario.setFont(new Font("Roboto Black", Font.PLAIN, 18)); + + JSeparator separator_1_2_4 = new JSeparator(); + separator_1_2_4.setBounds(556, 179, 289, 2); + contentPane.add(separator_1_2_4); + separator_1_2_4.setForeground(new Color(12, 138, 199)); + separator_1_2_4.setBackground(new Color(12, 138, 199)); } // Código que permite mover la ventana por la pantalla según la posición de "x" diff --git a/src/module-info.java b/src/module-info.java deleted file mode 100644 index 6ab6307..0000000 --- a/src/module-info.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - */ -/** - * - */ -module hotel_alura { - exports cl.com.alura.hotel.pruebas; - - requires io.github.cdimascio.dotenv.java; - requires java.sql; - requires java.desktop; - requires jcalendar; - requires c3p0; -} \ No newline at end of file