-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e69e157
commit fd451da
Showing
9 changed files
with
69 additions
and
12 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
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
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
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,42 @@ | ||
const utils = require('../lib/utils') | ||
const challenges = require('../data/datacache').challenges | ||
const db = require('../data/mongodb') | ||
const insecurity = require('../lib/insecurity') | ||
const sleep = require('sleep') | ||
|
||
module.exports = function productReviews () { | ||
return (req, res, next) => { | ||
const id = req.body.id | ||
const user = insecurity.authenticatedUsers.from(req) | ||
|
||
db.reviews.findOne({ _id: id }).then(review => { | ||
var likedBy = review.likedBy | ||
if(!likedBy.includes(user.data.email)){ | ||
db.reviews.update( | ||
{ _id: id }, | ||
{ '$inc': { likesCount: 1 } } | ||
).then( | ||
result => { | ||
// Artificial wait for timing attack challenge | ||
sleep.msleep(800) | ||
likedBy.push(user.data.email) | ||
db.reviews.update( | ||
{ _id: id }, | ||
{ '$set': { likedBy: likedBy } } | ||
).then( | ||
result => { | ||
res.json(result) | ||
}, err => { | ||
res.status(500).json(err) | ||
}) | ||
}, err => { | ||
res.status(500).json(err) | ||
}) | ||
}else{ | ||
res.status(403).json({ error: 'Not allowed' }) | ||
} | ||
}, () => { | ||
res.status(400).json({ error: 'Wrong Params' }) | ||
}) | ||
} | ||
} |
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
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