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 app with react b00tc4mp#173
- Loading branch information
Showing
12 changed files
with
243 additions
and
401 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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 | ||
} | ||
] |
2 changes: 1 addition & 1 deletion
2
staff/angelzrc/unsocial/data.js → staff/angelzrc/unsocial/data/users.js
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 |
---|---|---|
@@ -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' } | ||
] |
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
This file was deleted.
Oops, something went wrong.
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,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 | ||
} |
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,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) | ||
} |
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 @@ | ||
const getPosts = () => posts |
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,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) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.