email resend requests limited to once per thirty seconds

This commit is contained in:
jessop 2020-10-06 22:53:20 -04:00 committed by Sean Yesmunt
parent 2311fbdaae
commit 9fb13975b4

View file

@ -4,7 +4,7 @@ import Button from 'component/button';
import UserSignOutButton from 'component/userSignOutButton'; import UserSignOutButton from 'component/userSignOutButton';
import I18nMessage from 'component/i18nMessage'; import I18nMessage from 'component/i18nMessage';
import Card from 'component/common/card'; import Card from 'component/common/card';
const THIRTY_SECONDS_IN_MS = 30000;
type Props = { type Props = {
email: string, email: string,
isReturningUser: boolean, isReturningUser: boolean,
@ -17,10 +17,15 @@ type Props = {
}, },
}; };
class UserEmailVerify extends React.PureComponent<Props> { type State = {
wait: boolean,
};
class UserEmailVerify extends React.PureComponent<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.emailVerifyCheckInterval = null; this.emailVerifyCheckInterval = null;
this.state = { wait: false };
(this: any).handleResendVerificationEmail = this.handleResendVerificationEmail.bind(this); (this: any).handleResendVerificationEmail = this.handleResendVerificationEmail.bind(this);
} }
@ -46,8 +51,16 @@ class UserEmailVerify extends React.PureComponent<Props> {
handleResendVerificationEmail() { handleResendVerificationEmail() {
const { email, resendVerificationEmail, toast } = this.props; const { email, resendVerificationEmail, toast } = this.props;
resendVerificationEmail(email); if (!this.state.wait) {
toast(__('New email sent.')); resendVerificationEmail(email);
toast(__('New email sent.'));
this.setState({
wait: true,
});
setTimeout(() => this.setState({ wait: false }), THIRTY_SECONDS_IN_MS);
} else {
toast(__('Please wait a bit longer before requesting again.'));
}
} }
checkIfVerified() { checkIfVerified() {