diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index c1151638..cefff365 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -52,7 +52,6 @@ class LoginPage extends React.Component { username: null, validEmailOrPhone: false, validEmail: false, - enableCaptchaModal: CaptchaRule.Never, openCaptchaModal: false, openFaceRecognitionModal: false, verifyCaptcha: undefined, @@ -93,17 +92,6 @@ class LoginPage extends React.Component { } if (prevProps.application !== this.props.application) { this.setState({loginMethod: this.getDefaultLoginMethod(this.props.application)}); - - const captchaProviderItems = this.getCaptchaProviderItems(this.props.application); - if (captchaProviderItems) { - if (captchaProviderItems.some(providerItem => providerItem.rule === "Always")) { - this.setState({enableCaptchaModal: CaptchaRule.Always}); - } else if (captchaProviderItems.some(providerItem => providerItem.rule === "Dynamic")) { - this.setState({enableCaptchaModal: CaptchaRule.Dynamic}); - } else { - this.setState({enableCaptchaModal: CaptchaRule.Never}); - } - } } if (prevProps.account !== this.props.account && this.props.account !== undefined) { @@ -133,6 +121,19 @@ class LoginPage extends React.Component { } } + getCaptchaRule(application) { + const captchaProviderItems = this.getCaptchaProviderItems(application); + if (captchaProviderItems) { + if (captchaProviderItems.some(providerItem => providerItem.rule === "Always")) { + return CaptchaRule.Always; + } else if (captchaProviderItems.some(providerItem => providerItem.rule === "Dynamic")) { + return CaptchaRule.Dynamic; + } else { + return CaptchaRule.Never; + } + } + } + checkCaptchaStatus(values) { AuthBackend.getCaptchaStatus(values) .then((res) => { @@ -388,13 +389,14 @@ class LoginPage extends React.Component { } else { values["password"] = passwordCipher; } - if (this.state.enableCaptchaModal === CaptchaRule.Always) { + const captchaRule = this.getCaptchaRule(this.getApplicationObj()); + if (captchaRule === CaptchaRule.Always) { this.setState({ openCaptchaModal: true, values: values, }); return; - } else if (this.state.enableCaptchaModal === CaptchaRule.Dynamic) { + } else if (captchaRule === CaptchaRule.Dynamic) { this.checkCaptchaStatus(values); return; } @@ -911,7 +913,7 @@ class LoginPage extends React.Component { } renderCaptchaModal(application) { - if (this.state.enableCaptchaModal === CaptchaRule.Never) { + if (this.getCaptchaRule(this.getApplicationObj()) === CaptchaRule.Never) { return null; } const captchaProviderItems = this.getCaptchaProviderItems(application);