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