From 6c66df280bf11b8f31fb9e707cd50557a1a40615 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 17 Sep 2018 16:28:20 +0200 Subject: [PATCH] Checking that the Avatar can not be replaced in 24 hs --- client/src/components/UserImages.js | 67 +++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/client/src/components/UserImages.js b/client/src/components/UserImages.js index 99e78232a..57f613cfa 100644 --- a/client/src/components/UserImages.js +++ b/client/src/components/UserImages.js @@ -68,7 +68,8 @@ class UserImages extends React.Component { newAvatarHandle: '', saveDisabled: true, uploadToolDisabled: false, - showNewAvatar: false + showNewAvatar: false, + needToWait: false } } @@ -109,6 +110,25 @@ class UserImages extends React.Component { if (user.avatarHandle === null) { user.avatarHandle = '' } if (user.avatarChangeDate === null) { user.avatarChangeDate = '' } + /* Here we will check that the user does not change the avatar more often than once a day. */ + + let avatarChangeDate = (new Date(user.avatarChangeDate)).valueOf() + let now = (new Date()).valueOf() + let timePassed = now - avatarChangeDate + let oneDay = 1000 * 60 * 60 * 24 + +console.log("dates", avatarChangeDate, now, timePassed, oneDay) + + if (timePassed < oneDay) { + this.setState({ + needToWait: true + }) + } else { + this.setState({ + needToWait: false + }) + } + /* Now we are ready to set the initial state. */ this.setState({ @@ -200,25 +220,24 @@ class UserImages extends React.Component { } } - render() { + showUploadTool() { const { classes } = this.props - return ( - - - Profile Images - -
- - {this.showCurrentAvatar()} - + if (this.state.needToWait === true) { + return ( +
+ + You updated your Avatar in the last 24 hours. As a protection against denial of service attacks, the system does not allow users to update their Avatar in less than 24 hs since their last update. Please come back tomorrow. + +
+ ) + } else { + return( +
If you want, you can choose a new one by picking an image from your computer, camera or the web, and crop it with the following tool. - - -
+ - - +
+ ) + } + } + render() { + const { classes } = this.props + return ( + + + Profile Images + + + + {this.showCurrentAvatar()} + {this.showUploadTool()} {this.showNewAvatar()} - +