Skip to content

Commit

Permalink
Show login attempts error (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
riccio82 authored Feb 20, 2024
1 parent a21a6ac commit f17d876
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions public/js/cat_source/es6/components/modals/LoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LoginModal extends React.Component {
this.handleSubmitClicked = this.handleSubmitClicked.bind(this)
this.sendLoginData = this.sendLoginData.bind(this)
this.errorFor = this.errorFor.bind(this)
this.timerLoginAttempts
}

// TODO: find a way to abstract this into the plugin
Expand Down Expand Up @@ -87,8 +88,31 @@ class LoginModal extends React.Component {
}
}

showErrorWithTimer(time) {
this.setState({
requestRunning: true,
})
clearInterval(this.timerLoginAttempts)
this.timerLoginAttempts = setInterval(() => {
time--
if (time === 0) {
clearInterval(this.timerLoginAttempts)
this.setState({
requestRunning: false,
showErrors: false,
generalError: '',
})
} else {
let text = `Too many attempts, please retry in ${time} seconds`
this.setState({
generalError: text,
requestRunning: true,
})
}
}, 1000)
}

handleSubmitClicked() {
let self = this
this.setState({showErrors: true})
if ($.isEmptyObject(this.state.validationErrors) == false) return null
if (this.state.requestRunning) {
Expand All @@ -98,15 +122,20 @@ class LoginModal extends React.Component {
this.checkRedeemProject().then(
this.sendLoginData()
.then(() => {
if (self.props.goToManage) {
if (this.props.goToManage) {
window.location = '/manage/'
} else {
window.location.reload()
}
})
.catch(() => {
.catch((response) => {
if (response.status === 429) {
const time = response.headers.get('Retry-After')
this.showErrorWithTimer(time)
return
}
const text = 'Login failed.'
self.setState({
this.setState({
generalError: text,
requestRunning: false,
})
Expand Down

0 comments on commit f17d876

Please sign in to comment.