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.
update unsocial with post and password hiding b00tc4mp#175
- Loading branch information
Showing
26 changed files
with
1,362 additions
and
55 deletions.
There are no files selected for viewing
Empty file.
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,127 @@ | ||
/** | ||
* Constructs Compo instances | ||
* @param {HTMLElement} container The DOM container of the Compo instance | ||
*/ | ||
function Compo(container) { | ||
this.children = [] | ||
this.container = container | ||
} | ||
|
||
Compo.prototype.add = function (child) { | ||
this.children.push(child) // Par poder montar nuestro comcepto | ||
this.container.appendChild(child.container) //Para poder montar el HTML | ||
} | ||
Compo.prototype.remove = function () { | ||
this.container.remove() | ||
} | ||
|
||
Compo.prototype.add = function (child) { | ||
this.children.push(child) | ||
this.container.appendChild(child.container) | ||
} | ||
|
||
Compo.prototype.remove = function () { | ||
this.container.remove() | ||
} | ||
|
||
Compo.prototype.addBehavior = function (type, callback) { | ||
this.container.addEventListener(type, callback) | ||
} | ||
/** | ||
* Construcus Form instances | ||
*/ | ||
function Form() { | ||
Compo.call(this, document.createElement("form")) | ||
} | ||
|
||
Form.prototype = Object.create(Compo.prototype) | ||
Form.prototype.constructor = Form | ||
|
||
Form.prototype.reset = function () { | ||
this.container.reset() | ||
} | ||
|
||
/** | ||
* Constructs Button instances | ||
* @param {string} text The text of the button | ||
* @param {string} type The button type | ||
*/ | ||
function Button(text, type) { | ||
Compo.call(this, document.createElement("button")) | ||
|
||
this.container.innerText = text | ||
this.container.type = type | ||
} | ||
|
||
Button.prototype = Object.create(Compo.prototype) | ||
Button.prototype.constructor = Button | ||
|
||
/** | ||
* Constructs Label instances | ||
* | ||
* @param {string} text The text of the label | ||
* @param {string} id The id of the input to relate with | ||
*/ | ||
function Label(text, id) { | ||
Compo.call(this, document.createElement("label")) | ||
|
||
this.container.innerText = text | ||
this.container.htmlFor = id | ||
} | ||
|
||
Label.prototype = Object.create(Compo.prototype) | ||
Label.prototype.constructor = Label | ||
|
||
/** | ||
* Constructs Input instances | ||
* | ||
* @param {string} type The input type | ||
* @param {string} id The input id | ||
*/ | ||
function Input(type, id) { | ||
Compo.call(this, document.createElement("input")) | ||
|
||
this.container.type = type | ||
this.container.id = id | ||
} | ||
|
||
Input.prototype = Object.create(Compo.prototype) | ||
Input.prototype.constructor = Input | ||
|
||
Input.prototype.getValue = function () { | ||
return this.container.value | ||
} | ||
|
||
Input.prototype.setValue = function (value) { | ||
this.container.value = value | ||
} | ||
|
||
/** | ||
* Constructs Heading instances | ||
* | ||
* @param {string} text The text of the heading | ||
* @param {number} level The heading level | ||
*/ | ||
function Heading(text, level) { | ||
Compo.call(this, document.createElement('h' + level)) | ||
|
||
this.container.innerText = text | ||
} | ||
|
||
Heading.prototype = Object.create(Compo.prototype) | ||
Heading.prototype.constructor = Heading | ||
|
||
/** | ||
* Constructs Link instances | ||
* | ||
* @param {string} text The text of the link | ||
*/ | ||
function Link(text) { | ||
Compo.call(this, document.createElement('a')) | ||
|
||
this.container.innerText = text | ||
this.container.href = '' | ||
} | ||
|
||
Link.prototype = Object.create(Compo.prototype) | ||
Link.prototype.constructor = Link |
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,4 @@ | ||
var users = [ | ||
{ name: 'Peter Pan', email: '[email protected]', username: 'peterpan', password: '123123123' }, | ||
{ name: 'Wendy Darling', email: '[email protected]', username: 'wendydarling', password: '123123123' } | ||
] |
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,28 @@ | ||
<!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"> | ||
|
||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
|
||
<body> | ||
|
||
|
||
<script src="data.js"></script> | ||
|
||
<script src="logic.js"></script> | ||
|
||
|
||
<script src="compo.js"></script> | ||
<script src="view.js"></script> | ||
<script src="main.js"></script> | ||
|
||
</body> | ||
|
||
</html> |
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,44 @@ | ||
function registerUser(name, email, username, password, passwordRepeat) { | ||
if (name.length < 2) | ||
throw new Error('invalid name') | ||
|
||
if (!/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(email)) | ||
throw new Error('invalid e-mail') | ||
|
||
if (username.length < 4 || username.length > 12) | ||
throw new Error('invalid username') | ||
|
||
if (password.length < 8) | ||
throw new Error('invalid password') | ||
|
||
if (password !== passwordRepeat) | ||
throw new Error('passwords do not match') | ||
|
||
var user = users.find(function (user) { | ||
return user.username === username || user.email === email | ||
}) | ||
|
||
if (user !== undefined) | ||
throw new Error('user already exists') | ||
|
||
user = { name: name, email: email, username: username, password: password } | ||
|
||
users.push(user) | ||
} | ||
|
||
function authenticateUser(username, password) { | ||
if (username.length < 4 || username.length > 12) | ||
throw new Error('invalid username') | ||
|
||
if (password.length < 8) | ||
throw new Error('invalid password') | ||
|
||
var user = users.find(function (user) { | ||
return user.username === username && user.password === password | ||
}) | ||
|
||
if (user === undefined) | ||
throw new Error('wrong credentials') | ||
|
||
return user | ||
} |
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,9 @@ | ||
var loggedInUser = null | ||
|
||
var page = new Compo(document.querySelector("body")) | ||
|
||
var title = new Heading("Unsocial", 1) | ||
page.add(title) | ||
|
||
var login = new Login() | ||
page.add(login) |
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,39 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Fontdiner+Swanky&display=swap'); | ||
|
||
:root { | ||
--color: dodgerblue; | ||
--font: "Fontdiner Swanky", serif; | ||
font-family: var(--font); | ||
} | ||
|
||
body { | ||
background-color: #fffe9a; | ||
|
||
text-align: center; | ||
width: 100%; | ||
height: 100vh; | ||
margin: 0; | ||
} | ||
|
||
.login { | ||
margin-top: 100px; | ||
} | ||
|
||
.register { | ||
margin-top: 100px; | ||
} | ||
|
||
input { | ||
background-color: inherit; | ||
font-family: inherit; | ||
display: block; | ||
width: 20px; | ||
max-width: 500px; | ||
min-width: 300px; | ||
margin: 15px auto; | ||
border-radius: 10px; | ||
} | ||
|
||
a:visited { | ||
color: black; | ||
} |
Oops, something went wrong.