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 modification to unsocial app base code and implement initial code…
… for csr b00tc4mp#184
- Loading branch information
1 parent
2ffd3e4
commit 547715e
Showing
2 changed files
with
349 additions
and
118 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,213 @@ | ||
<!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="https://b00tc4mp.com/favicon.ico" type="image/x-icon"> | ||
|
||
<style> | ||
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap'); | ||
|
||
:root { | ||
--color: rgb(170, 60, 43); | ||
--font: 'Press Start 2P'; | ||
font-family: var(--font); | ||
} | ||
|
||
body { | ||
background-color: rgb(179, 176, 176); | ||
color: var(--color); | ||
margin: 50px; | ||
min-width: 370px; | ||
} | ||
|
||
form { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-evenly; | ||
min-width: 100px; | ||
width: 300px; | ||
gap: 5px; | ||
} | ||
|
||
input { | ||
background-color: inherit; | ||
font-family: inherit; | ||
} | ||
|
||
button { | ||
width: fit-content; | ||
} | ||
|
||
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" required /> | ||
|
||
<label for="password">Password</label> | ||
<input type="password" id="password" required /> | ||
|
||
<button type="submit">Login</button> | ||
</form> | ||
|
||
<p>Don't have an account? <a href="">Register</a></p> | ||
</section> | ||
|
||
<section> | ||
<h2>Register</h2> | ||
|
||
<form> | ||
<label for="name">Name</label> | ||
<input type="text" id="name" required /> | ||
|
||
<label for="email">E-mail</label> | ||
<input type="email" id="email" required /> | ||
|
||
<label for="username">Username</label> | ||
<input type="text" id="username" required /> | ||
|
||
<label for="password">Password</label> | ||
<input type="password" id="password" required /> | ||
|
||
<button type="submit">Register</button> | ||
</form> | ||
|
||
<p>Already have an account? <a href="">Login</a></p> | ||
</section> | ||
|
||
<section> | ||
<h2>Home</h2> | ||
|
||
<h3>Hello, User!</h3> | ||
|
||
<button>Logout</button> | ||
</section> | ||
|
||
<script> | ||
var users = [ | ||
{ name: 'Peter Pan', email: '[email protected]', username: 'peterpan', password: '123123123' }, | ||
{ name: 'Wendy Darling', email: '[email protected]', username: 'wendydarling', password: '123123123' } | ||
] | ||
|
||
var loggedInUser = null | ||
|
||
var sections = document.querySelectorAll('section') | ||
|
||
var loginSection = sections[0] | ||
|
||
var registerSection = sections[1] | ||
registerSection.style.display = 'none' | ||
|
||
var homeSection = sections[2] | ||
homeSection.style.display = 'none' | ||
|
||
var anchors = document.querySelectorAll('a') | ||
|
||
var registerAnchor = anchors[0] | ||
registerAnchor.addEventListener('click', function (event) { | ||
event.preventDefault() | ||
|
||
loginForm.reset() | ||
loginSection.style.display = 'none' | ||
registerSection.style.display = '' | ||
}) | ||
|
||
var loginAnchor = anchors[1] | ||
loginAnchor.addEventListener('click', function (event) { | ||
event.preventDefault() | ||
|
||
registerSection.style.display = 'none' | ||
loginSection.style.display = '' | ||
}) | ||
|
||
var forms = document.querySelectorAll('form') | ||
|
||
var loginForm = forms[0] | ||
|
||
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 | ||
|
||
var user = users.find(function (user) { | ||
return user.username === username && user.password === password | ||
}) | ||
|
||
if (user) { | ||
loggedInUser = user | ||
|
||
loginForm.reset() | ||
|
||
loginSection.style.display = 'none' | ||
homeSection.style.display = '' | ||
|
||
var h3 = homeSection.querySelector('h3') | ||
h3.innerText = 'Hello, ' + loggedInUser.name + '!' | ||
} else { | ||
alert('Wrong credentials, try again') | ||
passwordInput.value = '' | ||
} | ||
}) | ||
|
||
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) | ||
|
||
registerForm.reset() | ||
|
||
registerSection.style.display = 'none' | ||
loginSection.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.