-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
131 lines (122 loc) · 4.42 KB
/
index.php
File metadata and controls
131 lines (122 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
session_start();
// Verificar si la sesión está iniciada
if(isset($_SESSION['id_cliente'])) {
// Si el usuario ya inició sesión, redirigir a bienvenido.php
header("Location: home.php");
exit; // Asegurarse de que el script se detenga después de redirigir
}
header("Cache-Control: no-cache, no-store, must-revalidate");
header("Pragma: no-cache");
header("Expires: 0");
// Si el usuario no ha iniciado sesión, muestra el formulario de inicio de sesión normalmente
?>
<html>
<head>
<title>Iniciar sesion</title>
<script src="Administrador/js/jquery-3.3.1.min.js"></script>
<style>
h1 {
font-size: 40px; /* Tamaño grande */
margin-bottom: 20px; /* Espacio entre el título y el formulario */
position: relative; /* Posición relativa para el texto */
display: inline-block; /* Muestra como bloque en línea */
text-align: center;
}
body {
background-color:cornflowerblue; /* Color de fondo gris */
display: flex;
justify-content: center; /* Centra horizontalmente */
align-items: center; /* Centra verticalmente */
height: 100vh; /* Establece el alto de la vista al 100% */
margin: 0; /* Elimina el margen predeterminado */
}
form {
text-align: center; /* Centra el contenido del formulario */
}
.diseño input {
width: 250px;
background-color: aquamarine;
height: 35px;
margin-bottom: 10px; /* Espacio entre campos */
}
.diseño2 input {
width: 250px;
background-color: beige;
height: 35px;
margin-bottom: 10px; /* Espacio entre campos */
}
#mensaje {
display: none;
background-color: #f2f2f2;
color: #333;
border: 1px solid #ccc;
padding: 10px;
margin-top: 10px;
text-align: center;
width: 200px;
margin-left: auto; /* Centra el mensaje de error */
margin-right: auto; /* Centra el mensaje de error */
}
.container {
background-color: #ddd; /* Color de fondo gris claro */
padding: 40px;
border-radius: 10px; /* Borde redondeado */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Sombra */
}
</style>
<script>
function validar(event) {
event.preventDefault(); // Previene el envío estándar del formulario
var correo = $("#correo").val();
var pass = $("#pass").val();
var pregunta = $("#pregunta").val();
if (correo === "" || pass === "" || pregunta==="") {
$('#mensaje').show().html('Faltan campos por llenar');
setTimeout(function() {
$('#mensaje').html('').hide();
}, 5000);
} else {
$.ajax({
url: "validar_cliente.php",
method: "POST",
data: { correo: correo, pass: pass, pregunta: pregunta},
success: function(respuesta) {
if (respuesta.trim() === "Usuario encontrado") {
window.location.href = 'home.php';
} else {
$("#mensaje").html(respuesta).show();
setTimeout(function() {
$('#mensaje').html('').hide();
}, 5000);
}
},
error: function() {
$("#mensaje").html("Error al procesar la solicitud").show();
}
});
}
}
</script>
</head>
<body>
<div class="fondo">
<a href="registro_cliente.php">Registrarse</a>
<div class="container">
<form name="alta" method="post">
<h1>Iniciar sesion</h1>
<div class="diseño2">
<input id="correo" type="email" name="correo" placeholder="Correo" >
</div>
<div class="diseño">
<input type="password" name="pass" id="pass" placeholder="Password" /><br>
</div>
<div class="diseño2">
<input type="text" name="pregunta" id="pregunta" placeholder="Animal favorito" /><br>
</div>
<input id="iniciar" type="button" value="Iniciar" onclick="validator(event);"><br><br>
<div id="mensaje"></div>
</form>
</div>
</div>
</body>