Skip to content

Commit

Permalink
update unsocial app with react b00tc4mp#173
Browse files Browse the repository at this point in the history
  • Loading branch information
angelzrc committed Oct 17, 2024
1 parent c073f2e commit e4f7673
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 401 deletions.
91 changes: 0 additions & 91 deletions staff/angelzrc/unsocial/compo.js

This file was deleted.

14 changes: 14 additions & 0 deletions staff/angelzrc/unsocial/data/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const posts = [
{
image: 'https://i.pinimg.com/originals/8c/60/1a/8c601a25311a1a5098896f751a784b54.jpg',
text: 'here we are',
username: 'peterpan',
date: new Date
},
{
image: 'https://pm1.aminoapps.com/8360/ad07e2d2cdf6e1733328d6e7b7848b87db38a2bbr1-1536-2048v2_hq.jpg',
text: 'here i am',
username: 'wendydarling',
date: new Date
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var users = [
const users = [
{ name: 'Peter Pan', email: '[email protected]', username: 'peterpan', password: '123123123' },
{ name: 'Wendy Darling', email: '[email protected]', username: 'wendydarling', password: '123123123' }
]
23 changes: 16 additions & 7 deletions staff/angelzrc/unsocial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@
<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="styles.css">
<link rel="stylesheet" href="style.css">
</head>

<body>
<h1>Welcome to unSociaL</h1>
<div id="root"></div>

<script src="data/users.js"></script>
<script src="data/posts.js"></script>

<script src="logic/authenticateUser.js"></script>
<script src="logic/createPost.js"></script>
<script src="logic/getPosts.js"></script>
<script src="logic/registerUser.js"></script>

<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>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>


<script src="main.jsx" type="text/babel"></script>
</body>

</html>
63 changes: 0 additions & 63 deletions staff/angelzrc/unsocial/logic.js

This file was deleted.

16 changes: 16 additions & 0 deletions staff/angelzrc/unsocial/logic/authenticateUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const authenticateUser = (username, password) => {
if (username.length < 4 || username.length > 12)
throw new Error('invalid username')

if (password.length < 8)
throw new Error('invalid password')

const user = users.find( user =>
user.username === username && user.password === password
)

if (user === undefined)
throw new Error('wrong credentials')

return user
}
15 changes: 15 additions & 0 deletions staff/angelzrc/unsocial/logic/createPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const createPost = (username, image, text) => {
if (username.length < 4 || username.length > 12)
throw new Error('invalid username')

// TODO input validation (and throw error)

var post = {
image: image,
text: text,
username: username,
date: new Date
}

posts.push(post)
}
1 change: 1 addition & 0 deletions staff/angelzrc/unsocial/logic/getPosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const getPosts = () => posts
25 changes: 25 additions & 0 deletions staff/angelzrc/unsocial/logic/registerUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const 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')

let user = users.find(user => 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)
}
7 changes: 0 additions & 7 deletions staff/angelzrc/unsocial/main.js

This file was deleted.

Loading

0 comments on commit e4f7673

Please sign in to comment.