forked from b00tc4mp/isdi-parttime-202410
-
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 last version web-server b00tc4mp#8
- Loading branch information
Showing
26 changed files
with
1,272 additions
and
149 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
19 changes: 19 additions & 0 deletions
19
staff/quique-cabrera/playground/web-server/logic/authenticateUser.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const validate = require('./helpers/validate') | ||
|
||
const localStorage = require('../data/localStorage') | ||
|
||
const authenticateUser = (username, password) => { | ||
validate.username(username) | ||
validate.password(password) | ||
|
||
const users = JSON.parse(localStorage.users) | ||
|
||
const user = users.find(user => user.username === username && user.password === password) | ||
|
||
if (!user) | ||
throw new Error('wrong credentials') | ||
|
||
return user.id | ||
} | ||
|
||
module.exports = authenticateUser |
5 changes: 2 additions & 3 deletions
5
staff/quique-cabrera/playground/web-server/logic/getUserName.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
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,21 +1,11 @@ | ||
const loginUser = require('./loginUser') | ||
const isUserLoggedIn = require('./isUserLoggedIn') | ||
const authenticateUser = require('./authenticateUser') | ||
const getUserName = require('./getUserName') | ||
const logoutUser = require('./logoutUser') | ||
const registerUser = require('./registerUser') | ||
const getPosts = require('./getPosts') | ||
const createPost = require('./createPost') | ||
const deletePost = require('./deletePost') | ||
|
||
const logic = { | ||
loginUser, | ||
isUserLoggedIn, | ||
authenticateUser, | ||
getUserName, | ||
logoutUser, | ||
registerUser, | ||
getPosts, | ||
createPost, | ||
deletePost | ||
registerUser | ||
} | ||
|
||
module.exports = logic |
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 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,5 @@ | ||
const parseCookies = require('./parseCookies.js') | ||
|
||
module.exports = { | ||
parseCookies | ||
} |
20 changes: 20 additions & 0 deletions
20
staff/quique-cabrera/playground/web-server/util/parseCookies.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function parseCookies(cookieString) { | ||
if (!cookieString) return {} | ||
|
||
const keyValues = cookieString.split('; ') | ||
|
||
const cookies = keyValues.reduce((accum, keyValue) => { | ||
const keyAndValue = keyValue.split('=') | ||
|
||
const key = keyAndValue[0] | ||
const value = keyAndValue[1] | ||
|
||
accum[key] = value | ||
|
||
return accum | ||
}, {}) | ||
|
||
return cookies | ||
} | ||
|
||
module.exports = parseCookies |
Oops, something went wrong.