Let Captcha be force-refreshed with idempotencyKey

merge-requests/39/merge
Alex Gleason 4 years ago
parent 3c20d7fa3e
commit 78732d8d43
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -17,6 +17,7 @@ class CaptchaField extends React.Component {
onFetchFail: PropTypes.func,
dispatch: PropTypes.func,
refreshInterval: PropTypes.number,
idempotencyKey: PropTypes.string,
}
static defaultProps = {
@ -43,6 +44,12 @@ class CaptchaField extends React.Component {
clearInterval(this.state.refresh);
}
forceRefresh = () => {
this.fetchCaptcha();
this.endRefresh();
this.startRefresh();
}
fetchCaptcha = () => {
const { dispatch, onFetch, onFetchFail } = this.props;
dispatch(fetchCaptcha()).then(response => {
@ -63,6 +70,12 @@ class CaptchaField extends React.Component {
this.endRefresh();
}
componentDidUpdate(prevProps) {
if (this.props.idempotencyKey !== prevProps.idempotencyKey) {
this.forceRefresh();
}
}
render() {
const { captcha } = this.state;
const { onChange } = this.props;

@ -12,6 +12,7 @@ import {
import { register } from 'soapbox/actions/auth';
import CaptchaField from 'soapbox/features/auth_login/components/captcha';
import { Map as ImmutableMap } from 'immutable';
import { v4 as uuidv4 } from 'uuid';
const mapStateToProps = (state, props) => ({
instance: state.get('instance'),
@ -28,6 +29,7 @@ class RegistrationForm extends ImmutablePureComponent {
captchaLoading: true,
submissionLoading: false,
params: ImmutableMap(),
captchaIdempotencyKey: uuidv4(),
}
setParams = map => {
@ -61,6 +63,10 @@ class RegistrationForm extends ImmutablePureComponent {
this.setState({ captchaLoading: false });
}
refreshCaptcha = () => {
this.setState({ captchaIdempotencyKey: uuidv4() });
}
render() {
const { instance } = this.props;
const isLoading = this.state.captchaLoading || this.state.submissionLoading;
@ -108,6 +114,7 @@ class RegistrationForm extends ImmutablePureComponent {
onFetch={this.onFetchCaptcha}
onFetchFail={this.onFetchCaptchaFail}
onChange={this.onInputChange}
idempotencyKey={this.state.captchaIdempotencyKey}
/>
<div className='fields-group'>
<Checkbox

Loading…
Cancel
Save