forked from b00tc4mp/isdi-bootcamp-202409
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add index1 and index2 unsocial b00tc4mp#203
- Loading branch information
alba lomas lopez
authored and
alba lomas lopez
committed
Oct 9, 2024
1 parent
46c4300
commit 09d4203
Showing
3 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Unsocial</title> | ||
<link rel="shortcut icon" | ||
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAmVBMVEXu6eYAAAAJCQnt6OXx7OkGBgb18e7w6Oby7uvw6+kJCQvt6eXOysf18fDx7OoICgnh3dqvrqwkJCPg3dvLyMaBf37f29ifnp0zMzLm4+F6eHa8ubgcHBuMiolgX17Y1dNaWlhpZ2YSEhBFRUQ9PTylpKJRUE8jIiGFhIO0srDDwL9wb26XlpQ8OzpEREIZGhhMTEosLCv9/Pn0rnQ+AAAQEUlEQVR4nO1ca3fqOg6NsDEOjkN5FcKztEBpCj2l///HjR4OcObeNY91pisp4/1hhnIg1zuypC1ZIUkiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIivhE2UXUv4XthdrbuJXwrnB5B/74p+hMsXN2L+E7YObRgYu/ME1VyNZrfQxcGpsbVfAs6iak4DqHVasFI8x8qMfcRV1WqZjblV2bCDJeGieniYH+0T3ZUWH4+h0+VOrLZihl+sk3z4QAea13hn0O2oPJjgCefdDqJnjLDBXHXxQBgkvNH3O/e+kOQem/E3+wWA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kK3kyOE1RySgnab7+XP8XkBaxD1lZoqSsdpg2Ljt+cDhBitKcGYcZWVj1UXtWtrK+oK+uLZ/qJ41kmJvscOIqo7s9FpfnXrWllEc2O4rYGUudtFr7cB9ItxW7vWiH6azMbTgeaBa0mX9eJmgQyxtPsqk8QLPgxsszvz7668mutsve1WNhussb6IWkY0AaGi0Ze3pdX5eZenmkUjId3YP+DUGbvd7kebpBg6wODv8aih5IaFczajIKdGXYSfznbxyWt7m8uO07MsNmPvhsHjeX5iHttWV6u9Vk+KKicP5Nbupi9ts3n0Z1NYH/Hcz6cA6CZEodCHUbLMKJuDB8+6eiyDweT+GbJIDypj65Rtn6sXzr98tH85enefX6YkQY2H/Sm46/2d/t5nxE0OAHgZMkqfoZf4F/udSH47+tibSl88TGJYm/w99b4HpUEQb5/tMv/hjkbxeGWUMDyR8iHUFV+T3cO8P2Q91r+R6EAphtWPdavgdXhvdvw/tn2IsMfyiuDFt3z/D+/fD+s0Vk+FMRGf58RIY/H/r/qHq6e9UGd8vwskufm/yren+AC0O4e4bt3rDutXwPLgx7sL7PXlt4vpcY3mm/NPykROvmIbU7g1leet79xv3g3P8EN5N7dU+nfxPM+cKwub/++CeQ8WhhuEjv0RH15eiJHpmtezXfAZ75ZnRbDfw1tj+G06o65KYh8F/3x1B+HbMd0IhfuPpfQ78sFr+eK/Sm9xdqtOfxTCOzlf4u00VSTSLcpZ4RdPipxU6n1oeXIyIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi6sU/AP017ctRjAS0AAAAAElFTkSuQmCC" | ||
type="image/x-icon"> | ||
|
||
<style> | ||
/* Estilo de letra. */ | ||
@import url('https://fonts.googleapis.com/css2?family=Dancing+Script:[email protected]&family=Updock&display=swap'); | ||
|
||
/* Css del documento html en general. */ | ||
:root { | ||
--color: rgb(128, 175, 128); | ||
--font: 'Dancing Script'; | ||
font-family: var(--font); | ||
} | ||
|
||
/* Hemos creado una variable de color para que todos los css | ||
que hagamos de color copien el que ya hemos escogido. */ | ||
body { | ||
background-color: rgb(219, 224, 224); | ||
color: var(--color); | ||
} | ||
|
||
/* Color del input, creamos una variable de background color | ||
para que todos los background colors vayan automaticamente | ||
con el mismo color. */ | ||
input { | ||
background-color: inherit; | ||
font-family: inherit; | ||
} | ||
|
||
a:visited { | ||
color: var(--color); | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1>Unsocial</h1> | ||
|
||
|
||
|
||
<section> | ||
<h2>Login</h2> | ||
<form> | ||
<label for="username">Username</label> | ||
<input type="text" id="username" /> | ||
<label for="password">Password</label> | ||
<input type="password" id="password" /> | ||
|
||
<button type="submit">Login</button> | ||
</form> | ||
|
||
<a ref="">Register</a> | ||
</section> | ||
|
||
|
||
|
||
|
||
|
||
<section> | ||
<h2>Register</h2> | ||
<form> | ||
<label for="name">Name</label> | ||
<input type="text" id="name" /> | ||
|
||
<label for="email">E-mail</label> | ||
<input type="email" id="email" /> | ||
|
||
<label for="username">Username</label> | ||
<input type="text" id="username" /> | ||
|
||
<label for="password">Password</label> | ||
<input type="password" id="password" /> | ||
|
||
<button type="submit">Register</button> | ||
</form> | ||
|
||
<a ref="">Login</a> | ||
</section> | ||
|
||
|
||
|
||
|
||
<section> | ||
<h2>Home</h2> | ||
|
||
<h3>Hello, User!</h3> | ||
|
||
<button>Logout</button> | ||
</section> | ||
|
||
|
||
|
||
<script> | ||
|
||
var users = [ // Creamos un array para poder guardar los usuarios. | ||
{ name: 'alba', email: '[email protected]', username: 'alba', password: '123123' }, | ||
{ name: 'maga', email: '[email protected]', username: 'maga', password: '123123' } | ||
] | ||
|
||
var loggedInUser = null | ||
|
||
/* Aqui le decimos que cuando arranque la app la | ||
seccion 1 (Register) y la seccion 2 (Home) estén | ||
apagadas, (Es decir, que no salgan en la pantalla | ||
principal), querySelector te permite traer cualquier | ||
elemento del tipo que le dices, en este caso le | ||
pedimos las secciones. */ | ||
var sections = document.querySelectorAll('section') | ||
|
||
var loginSection = sections[0] | ||
// loginSection.style.display = 'none' | ||
|
||
var registerSection = sections[1] | ||
registerSection.style.display = 'none' | ||
|
||
var homeSection = sections[2] | ||
homeSection.style.display = 'none' | ||
|
||
|
||
/* Aqui le damos función a los anchors (anclas) */ | ||
var anchors = document.querySelectorAll('a') | ||
|
||
var registerAnchor = anchors[0] | ||
|
||
registerAnchor.addEventListener('click', function (event) { | ||
event.preventDefault() /* Se pone para evitar que navegue */ | ||
|
||
/* Aqui le estamos diciendo que cuando cliquemos en registro, | ||
se apague la seccion de login */ | ||
loginSection.style.display = 'none' | ||
/* Aqui le estamos quitando el none para que salga la seccion | ||
de register. */ | ||
registerSection.style.display = '' | ||
}) | ||
|
||
/* lo mismo que el anterior pero con la seccion del registro. */ | ||
var loginAnchor = anchors[1] | ||
|
||
loginAnchor.addEventListener('click', function (event) { | ||
event.preventDefault() | ||
|
||
registerSection.style.display = 'none' | ||
loginSection.style.display = '' | ||
}) | ||
|
||
var forms = document.querySelectorAll('form') | ||
|
||
// Aqui vamos a pedirle que guarde los inputs que pongamos. | ||
var registerForm = forms[1] | ||
|
||
registerForm.addEventListener('submit', function (event) { | ||
event.preventDefault() | ||
|
||
var inputs = registerForm.querySelectorAll('input') | ||
|
||
var nameInput = inputs[0] | ||
var name = nameInput.value | ||
|
||
var emailInput = inputs[1] | ||
var email = emailInput.value | ||
|
||
var usernameInput = inputs[2] | ||
var username = usernameInput.value | ||
|
||
var passwordInput = inputs[3] | ||
var password = passwordInput.value | ||
|
||
var user = { name: name, email: email, username: username, password: password } | ||
|
||
users.push(user) // guardar input user en el array. | ||
|
||
registerForm.reset() // cada vez que se añada un imput, reiniciar para que se limpie lo relleneado. | ||
|
||
registerSection.style.display = 'none' | ||
loginSection.style.display = '' | ||
}) | ||
|
||
var loginForm = forms[0] | ||
|
||
// submit es un evento del formulario. | ||
// funcionamiento del login | ||
loginForm.addEventListener('submit', function (event) { | ||
event.preventDefault() | ||
|
||
var inputs = loginForm.querySelectorAll('input') | ||
|
||
var usernameInput = inputs[0] | ||
var username = usernameInput.value | ||
|
||
var passwordInput = inputs[1] | ||
var password = passwordInput.value | ||
|
||
/* | ||
- buscar en users si existe el usuario con este username | ||
y password. | ||
- si existe entrar en home [1] | ||
- si no, una alerta de error. | ||
- poner un resert cuando se hace submit (se envia el formulario) | ||
- [1] poner el saludo en home con el name del usuario en el h3. | ||
- apagar login y encender home. | ||
*/ | ||
|
||
// Aqui busca en el array el nombre del usuario introducido. | ||
var user = users.find(function (user) { | ||
/* una vez encuentra el usuario, contrasta que la contraseña introducida | ||
sea la misma que la que tiene guardada.*/ | ||
return user.username === username && user.password === password | ||
}) | ||
|
||
if (user === undefined) { | ||
alert('Wrong credentials') | ||
|
||
passwordInput.value = '' | ||
} else { | ||
loggedInUser = user | ||
|
||
loginForm.reset()// Aqui le pedimos que cuando entremos el usuario y la contraseña se limpie. | ||
|
||
var homeUserTitle = homeSection.querySelector('h3') | ||
homeUserTitle.innerText = 'Hello, ' + loggedInUser.name + '!' | ||
|
||
loginSection.style.display = 'none' | ||
homeSection.style.display = '' | ||
} | ||
}) | ||
|
||
var logoutButton = homeSection.querySelector('button') | ||
|
||
logoutButton.addEventListener('click', function (event) { | ||
event.preventDefault() | ||
|
||
loggedInUser = null | ||
|
||
homeSection.style.display = 'none' | ||
loginSection.style.display = '' | ||
}) | ||
|
||
|
||
|
||
</script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.