1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Login Proyecto CoderHouse</ title >
6+ < link rel ="stylesheet " href ="../../css/estilosMain.css ">
7+ </ head >
8+ < body >
9+ < div class ="formContainer ">
10+ < div class ="menu ">
11+ < button id ="login " class ="btnLogin " onclick ="mostrarLogin() "> Login </ button >
12+ < button id ="register " class ="btnRegistro " onclick ="mostrarRegistro() "> Registro</ button >
13+ </ div >
14+ < div id ="contenido ">
15+ <!-- Aquí es donde aparecerán los formularios LOGIN y REGISTRO -->
16+ </ div >
17+ </ div >
18+
19+
20+
21+ < script src ="js/jquery-3.1.1.min.js "> </ script >
22+ < script >
23+ {
24+ /**
25+ * FUNCION REGISTRO DE USUARIOS
26+ * @returns usuarios registrados
27+ */
28+ let registro = function ( ) {
29+
30+ let nom = document . querySelector ( '#SetNombre' ) . value ; //
31+ let ape = document . querySelector ( '#SetApellido' ) . value ; //
32+ let mai = document . querySelector ( '#SetMail' ) . value ; //
33+ let usu = document . querySelector ( '#SetUsuario' ) . value ; //
34+ let pas = document . querySelector ( '#SetPassword' ) . value ; //
35+ const datosU = [ {
36+ nombre : nom ,
37+ apellido : ape ,
38+ email : mai ,
39+ usuario : usu ,
40+ pass : pas
41+ } ]
42+
43+ /**
44+ * PRUEBAS JSON
45+ */
46+
47+ // Obtener los datos existentes en localStorage (si existen)
48+ let usuarios = JSON . parse ( localStorage . getItem ( 'usuarios' ) ) || [ ] ;
49+
50+ // Agregar el nuevo usuario al array de usuarios
51+ usuarios . push ( datosU ) ;
52+
53+ // Guardar el array actualizado en localStorage
54+ localStorage . setItem ( 'usuarios' , JSON . stringify ( usuarios ) ) ;
55+
56+ // Limpiar los campos del formulario
57+ document . querySelector ( '#SetNombre' ) . reset ( ) ;
58+ document . querySelector ( '#SetApellido' ) . reset ( ) ;
59+ document . querySelector ( '#SetMail' ) . reset ( ) ;
60+ document . querySelector ( '#SetUsuario' ) . reset ( ) ;
61+ document . querySelector ( '#SetPassword' ) . reset ( ) ;
62+
63+ //Envia mensaje a DIV con ID "mensajeRegistro" en el documento
64+ document . querySelector ( '#SetPassword' ) . innerText = "Usuario y password REGISTRADO" ;
65+
66+
67+
68+ return registroUsuarios ;
69+ }
70+
71+
72+ /**
73+ * EFECTO EN FORMULARIOS CON BOTONES
74+ */
75+ function mostrarLogin ( ) {
76+
77+ document . getElementById ( 'contenido' ) . innerHTML = `
78+ <div id="formlogin">
79+ <h2>Iniciar Sesión</h2>
80+ <form action="#">
81+ <input type="text" id="GetUsuario" placeholder="Usuario" required>
82+ <input type="password" id="GetPass" placeholder="Contraseña" required>
83+ <input type="submit" id="login" value="Iniciar Sesión" onclick="validacion()">
84+ <div id="mensajeLogin"></div>
85+ </form>
86+ </div>
87+ ` ;
88+
89+ document . getElementById ( 'formlogin' ) . style . display = 'block' ;
90+ document . getElementById ( 'formregistro' ) . style . display = 'none' ;
91+ }
92+
93+
94+ function mostrarRegistro ( ) {
95+ document . getElementById ( 'contenido' ) . innerHTML = `
96+
97+ <div class="formregistro">
98+ <h2>Crea tu Cuenta</h2>
99+ <form action="#">
100+ <input type="text" id="SetNombre" placeholder="Nombre" required>
101+ <input type="text" id="SetApellido" placeholder="Apellido" required>
102+ <input type="email" id="SetMail" placeholder="Correo Electronico" required>
103+ <input type="text" id="SetUsuario" placeholder="Usuario" required>
104+ <input type="password" id="SetPassword" placeholder="Contraseña" required>
105+ <input type="submit" id="register" value="Registrarse" onclick="registro()" >
106+ </form>
107+ </div>
108+ ` ;
109+
110+ document . getElementById ( 'formuser' ) . style . display = 'block' ;
111+ document . getElementById ( 'formregistro' ) . style . display = 'none' ;
112+ }
113+
114+
115+ /**
116+ * FUNCION PARA VALIDACIONES USUARIO
117+ */
118+ let validacion = function ( ) {
119+ //Informacion del registro de Usuario
120+ let reg = registro ( ) ;
121+ let usuario = reg [ 0 ] [ "usuario" ] ;
122+ let pass = reg [ 0 ] [ "pass" ] ;
123+
124+ //Datos que ingresa usuario desde login page
125+ let usr = document . querySelector ( '#GetUsuario' ) . value ; //Toma valor ingresado en campo Usuario
126+ let pas = document . querySelector ( '#GetPass' ) . value ; //Toma valor ingresado en campo PAssword
127+
128+ console . log ( "Validado Usuario: " + usuario ) ;
129+ console . log ( "Validado Usuario: " + pass ) ;
130+ console . log ( registro ( ) ) ;
131+
132+ if ( usr == usuario && pas == pass ) {
133+ //Envia mensaje a DIV con ID "mensajeLogin" en el documento
134+ document . querySelector ( '#mensajeLogin' ) . innerText = "Usuario y password correcto" ;
135+ window . location . href = 'https://juangralarg.github.io/CoderHouse/Entregas/PruebasEntrega/principal.html' ; //redirecciona a pagina. NO FUNCIONA AUN
136+ } else {
137+ document . querySelector ( '#mensajeLogin' ) . innerText = "Datos incorrectos" ;
138+ }
139+ }
140+
141+
142+ }
143+ </ script >
144+ </ body >
145+ </ html >
0 commit comments