From 96b87492846647fefa7392d836729f571a74f51a Mon Sep 17 00:00:00 2001 From: Alain Vasquez Ramirez <zs22016095@estudiantes.uv.mx> Date: Wed, 19 Feb 2025 10:39:52 -0600 Subject: [PATCH] prueba base de datos --- bd/ticket_fei.sql | 55 +++++++++++++++++++++++++++++++ controladores/conexion.php | 15 +++++++++ controladores/login.php | 32 ++++++++++++++++++ css/estilo.css | 67 ++++++++++++++++++++++++++++++++++++++ index.html | 31 ++++++++++++++++++ js/login.js | 32 ++++++++++++++++++ ventanaPrincipal.html | 0 7 files changed, 232 insertions(+) create mode 100644 bd/ticket_fei.sql create mode 100644 controladores/conexion.php create mode 100644 ventanaPrincipal.html diff --git a/bd/ticket_fei.sql b/bd/ticket_fei.sql new file mode 100644 index 0000000..7faa400 --- /dev/null +++ b/bd/ticket_fei.sql @@ -0,0 +1,55 @@ +-- MySQL dump 10.13 Distrib 8.0.34, for Win64 (x86_64) +-- +-- Host: 127.0.0.1 Database: ticketfei +-- ------------------------------------------------------ +-- Server version 8.0.34 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `usuarios` +-- + +DROP TABLE IF EXISTS `usuarios`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `usuarios` ( + `id` int NOT NULL AUTO_INCREMENT, + `nombre` varchar(255) NOT NULL, + `apellidoPaterno` varchar(255) NOT NULL, + `apellidoMaterno` varchar(255) NOT NULL, + `usuario` varchar(255) NOT NULL, + `contraseña` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `usuarios` +-- + +LOCK TABLES `usuarios` WRITE; +/*!40000 ALTER TABLE `usuarios` DISABLE KEYS */; +INSERT INTO `usuarios` VALUES (1,'Aaron','Bonilla','Gonzalez','s22','123'),(2,'Carlos','Palestina','Alducin','s23','123'),(3,'Miguel','Diaz','Villa','s24','123'); +/*!40000 ALTER TABLE `usuarios` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2025-02-19 10:38:05 diff --git a/controladores/conexion.php b/controladores/conexion.php new file mode 100644 index 0000000..93a603e --- /dev/null +++ b/controladores/conexion.php @@ -0,0 +1,15 @@ +<?php + // Valores para la conexión + $direccion = "localhost:3306"; + $nombreBD = "TicketFei"; + $usuario = "desarrolloTicketFei"; + $password = "password"; + + // Obtener conexión + $conexionBD = new mysqli($direccion, $usuario, $password, $nombreBD); + + // Verificar si hay un error en la conexión + if ($conexionBD->connect_error) { + die("Error en la conexión: " . $conexionBD->connect_error); + } +?> diff --git a/controladores/login.php b/controladores/login.php index e69de29..0de8b92 100644 --- a/controladores/login.php +++ b/controladores/login.php @@ -0,0 +1,32 @@ +<?php + session_start(); + include 'conexion.php'; + + $usuario = $_POST['usuario']; + $password = $_POST['password']; + + // Prepara la consulta + $consulta = "SELECT id, nombre, apellidoPaterno, apellidoMaterno, usuario FROM usuarios WHERE usuario = ? AND contraseña = ?"; + + $consultaPreparada = $conexionBD->prepare($consulta); + $consultaPreparada->bind_param("ss", $usuario, $password); + $consultaPreparada->execute(); + $resultado = $consultaPreparada->get_result(); + + // Verifica si se encontró un colaborador con las credenciales correctas + if ($resultado->num_rows > 0) { + $fila = $resultado->fetch_assoc(); + + // Guarda el ID y el usuario en la sesión + $_SESSION['usuarios_id'] = $fila['id']; + $_SESSION['usuarios_nombre'] = $fila['nombre']; + + echo json_encode(['loginExitoso' => true, 'usuarios_id' => $fila['id'], 'usuarios_nombre' => $fila['nombre']]); + } else { + // Credenciales incorrectas + echo json_encode(['loginExitoso' => false, 'error' => 'Credenciales inválidas']); + } + + $consultaPreparada->close(); + $conexionBD->close(); +?> diff --git a/css/estilo.css b/css/estilo.css index e69de29..653bde3 100644 --- a/css/estilo.css +++ b/css/estilo.css @@ -0,0 +1,67 @@ +body { + background-color: #212529; + min-height: 100vh; + display: flex; + align-items: center; + justify-content: center; + font-family: Arial, sans-serif; +} + +.container { + text-align: center; +} + +h1 { + color: #ffffff; + font-size: 24px; + margin-bottom: 20px; +} + +.card { + background-color: #2d3238; + padding: 30px; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); + width: 300px; +} + +.datos { + display: flex; + flex-direction: column; + text-align: left; + margin-bottom: 15px; +} + +.datos label { + font-size: 14px; + color: #ffffff; + margin-bottom: 5px; +} + +.datos input { + padding: 10px; + border: 1px solid #495057; + border-radius: 5px; + background-color: #343a40; + color: white; +} + +.boton { + text-align: center; + margin-top: 15px; +} + +#btnIniciarSesion { + padding: 10px; + border-radius: 5px; + background-color: #007bff; + border: none; + color: white; + font-size: 16px; + cursor: pointer; + width: 100%; +} + +#btnIniciarSesion:hover { + background-color: #0056b3; +} diff --git a/index.html b/index.html index e69de29..e979bec 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<html lang="es"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Login</title> + <link rel="stylesheet" href="css/estilo.css"> +</head> +<body> + <div class="container"> + <h1>Inicio de sesión</h1> + <div class="card"> + <form id="formularioLogin"> + <div class="datos"> + <label for="user">Usuario</label> + <input type="text" id="user" name="user" placeholder="Ingresa tu usuario" required> + </div> + <div class="datos"> + <label for="pw">Contraseña</label> + <input type="password" id="pw" name="pw" placeholder="Ingresa tu contraseña" required> + </div> + <div class="boton"> + <input type="submit" id="btnIniciarSesion" value="Ingresar"> + </div> + </form> + <div id="mensaje"></div> + </div> + </div> + <script src="js/login.js"></script> +</body> +</html> diff --git a/js/login.js b/js/login.js index e69de29..275ebed 100644 --- a/js/login.js +++ b/js/login.js @@ -0,0 +1,32 @@ +const formulario = document.getElementById('formularioLogin'); +const notificacion = document.getElementById('mensaje'); + +formulario.addEventListener('submit', async (event) => { + + event.preventDefault(); + const usuario = document.getElementById("user").value; + const password = document.getElementById("pw").value; + + const data = new FormData(); + data.append('usuario', usuario); + data.append('password', password); + + try { + // Petición al servidor + const respuestaPeticion = await fetch('controladores/login.php', { + method: 'POST', + body: data + }); + const verificarCredenciales = await respuestaPeticion.json(); + if (verificarCredenciales.loginExitoso) { + window.location.href = 'ventanaPrincipal.html'; + } else { + notificacion.textContent ="Usuario o contraseña incorrecta"; + notificacion.style.color='#ffffff'; + } + } catch (error) { + console.error(error); + notificacion.textContent = 'Lo sentimos, el servicio no está disponible por el momento.'; + notificacion.style.color = '#ff0000'; + } +}); diff --git a/ventanaPrincipal.html b/ventanaPrincipal.html new file mode 100644 index 0000000..e69de29