Skip to content

Commit

Permalink
separate app into files, add view file with functions and separate th…
Browse files Browse the repository at this point in the history
…em, add compos abstractions b00tc4mp#184
  • Loading branch information
LuisMorlets committed Oct 9, 2024
1 parent 547715e commit e1dadf3
Show file tree
Hide file tree
Showing 32 changed files with 2,921 additions and 208 deletions.
Empty file.
File renamed without changes.
259 changes: 259 additions & 0 deletions staff/luis-morlets/unsocial.1/index.2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
<!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>

<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 loginSection = document.createElement('section')

var loginTitle = document.createElement('h2')
loginTitle.innerText = 'Login'
loginSection.appendChild(loginTitle)

var loginForm = document.createElement('form')
loginSection.appendChild(loginForm)

var loginUsernameLabel = document.createElement('label')
loginUsernameLabel.htmlFor = 'username'
loginUsernameLabel.innerText = 'Username'
loginForm.appendChild(loginUsernameLabel)

var loginUsernameInput = document.createElement('input')
loginUsernameInput.type = 'text'
loginUsernameInput.id = 'username'
loginUsernameInput.required = true
loginForm.appendChild(loginUsernameInput)

var loginPasswordLabel = document.createElement('label')
loginPasswordLabel.htmlFor = 'password'
loginPasswordLabel.innerText = 'Password'
loginForm.appendChild(loginPasswordLabel)

var loginPasswordInput = document.createElement('input')
loginPasswordInput.type = 'password'
loginPasswordInput.id = 'password'
loginPasswordInput.required = true
loginForm.appendChild(loginPasswordInput)

var loginSubmitButton = document.createElement('button')
loginSubmitButton.type = 'submit'
loginSubmitButton.innerText = 'Login'
loginForm.appendChild(loginSubmitButton)

var loginAnchorText = document.createElement('p')
loginAnchorText.innerText = "Don't have an account? "
loginSection.appendChild(loginAnchorText)

var loginRegisterLink = document.createElement('a')
loginRegisterLink.href = ''
loginRegisterLink.innerText = 'Register'
loginAnchorText.appendChild(loginRegisterLink)


loginRegisterLink.addEventListener('click', function (event) {
event.preventDefault()

loginSection.remove()

var registerSection = document.createElement('section')

var registerTitle = document.createElement('h2')
registerTitle.innerText = 'Register'
registerSection.appendChild(registerTitle)

var registerForm = document.createElement('form')
registerSection.appendChild(registerForm)

var registerNameLabel = document.createElement('label')
registerNameLabel.htmlFor = 'name'
registerNameLabel.innerText = 'Name'
registerForm.appendChild(registerNameLabel)

var registerNameInput = document.createElement('input')
registerNameInput.type = 'text'
registerNameInput.id = 'name'
registerNameInput.required = true
registerForm.appendChild(registerNameInput)

var registerEmailLabel = document.createElement('label')
registerEmailLabel.htmlFor = 'email'
registerEmailLabel.innerText = 'E-mail'
registerForm.appendChild(registerEmailLabel)

var registerEmailInput = document.createElement('input')
registerEmailInput.type = 'email'
registerEmailInput.id = 'email'
registerEmailInput.required = true
registerForm.appendChild(registerEmailInput)

var registerUsernameLabel = document.createElement('label')
registerUsernameLabel.htmlFor = 'username'
registerUsernameLabel.innerText = 'Username'
registerForm.appendChild(registerUsernameLabel)

var registerUsernameInput = document.createElement('input')
registerUsernameInput.type = 'text'
registerUsernameInput.id = 'username'
registerUsernameInput.required = true
registerForm.appendChild(registerUsernameInput)

var registerPasswordLabel = document.createElement('label')
registerPasswordLabel.htmlFor = 'password'
registerPasswordLabel.innerText = 'Password'
registerForm.appendChild(registerPasswordLabel)

var registerPasswordInput = document.createElement('input')
registerPasswordInput.type = 'password'
registerPasswordInput.id = 'password'
registerPasswordInput.required = true
registerForm.appendChild(registerPasswordInput)

var registerSubmitButton = document.createElement('button')
registerSubmitButton.type = 'submit'
registerSubmitButton.innerText = 'Register'
registerForm.appendChild(registerSubmitButton)

var registerAnchorText = document.createElement('p')
registerAnchorText.innerText = 'Already have an account? '
registerSection.appendChild(registerAnchorText)

var registerLoginLink = document.createElement('a')
registerLoginLink.href = ''
registerLoginLink.innerText = 'Login'
registerAnchorText.appendChild(registerLoginLink)

registerLoginLink.addEventListener('click', function (event) {
event.preventDefault()

registerSection.remove()
body.appendChild(loginSection)
})

registerForm.addEventListener('submit', function (event) {
event.preventDefault()

registerSection.remove()

var name = registerNameInput.value
var email = registerEmailInput.value
var username = registerUsernameInput.value
var password = registerPasswordInput.value

var user = { name: name, email: email, username: username, password: password }
users.push(user)

registerForm.reset()

body.appendChild(loginSection)
})

body.appendChild(registerSection)
})

loginForm.addEventListener('submit', function (event) {
event.preventDefault()

var user = users.find(function (user) {
return user.username === loginUsernameInput.value && user.password === loginPasswordInput.value
})

if (user === undefined) {
alert('Wrong credentials, try again')
loginPasswordInput.value = ''

} else {
loggedInUser = user

loginForm.reset()

loginSection.remove()

var homeSection = document.createElement('section')

var homeSectionTitle = document.createElement('h2')
homeSectionTitle.innerText = 'Home'
homeSection.appendChild(homeSectionTitle)

var homeGreetingText = document.createElement('h3')
homeGreetingText.innerText = "Hey " + loggedInUser.name + ", you're finally awake!"
homeSection.appendChild(homeGreetingText)

var homeLogoutButton = document.createElement('button')
homeLogoutButton.innerText = 'Logout'
homeSection.appendChild(homeLogoutButton)

homeLogoutButton.addEventListener('click', function (event) {
event.preventDefault()

loggedInUser = null

homeSection.remove()

body.appendChild(loginSection)
})
body.appendChild(homeSection)
}
})

var body = document.querySelector('body')
body.appendChild(loginSection)

</script>

</body>

</html>
Loading

0 comments on commit e1dadf3

Please sign in to comment.