feat: add getCaptchaRule() to fix bug (#3281)

* feat: update captcha rule when the login page component is mounted

* fix: remove enableCaptchaModel from the state of the login page to avoid inconsistency issues

* fix: use this.getApplicationObj() instead of this.props.application
This commit is contained in:
ZhaoYP 2001 2024-10-12 10:02:45 +08:00 committed by GitHub
parent 9f4430ed04
commit 3211bcc777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,7 +52,6 @@ class LoginPage extends React.Component {
username: null, username: null,
validEmailOrPhone: false, validEmailOrPhone: false,
validEmail: false, validEmail: false,
enableCaptchaModal: CaptchaRule.Never,
openCaptchaModal: false, openCaptchaModal: false,
openFaceRecognitionModal: false, openFaceRecognitionModal: false,
verifyCaptcha: undefined, verifyCaptcha: undefined,
@ -93,17 +92,6 @@ class LoginPage extends React.Component {
} }
if (prevProps.application !== this.props.application) { if (prevProps.application !== this.props.application) {
this.setState({loginMethod: this.getDefaultLoginMethod(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) { 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) { checkCaptchaStatus(values) {
AuthBackend.getCaptchaStatus(values) AuthBackend.getCaptchaStatus(values)
.then((res) => { .then((res) => {
@ -388,13 +389,14 @@ class LoginPage extends React.Component {
} else { } else {
values["password"] = passwordCipher; values["password"] = passwordCipher;
} }
if (this.state.enableCaptchaModal === CaptchaRule.Always) { const captchaRule = this.getCaptchaRule(this.getApplicationObj());
if (captchaRule === CaptchaRule.Always) {
this.setState({ this.setState({
openCaptchaModal: true, openCaptchaModal: true,
values: values, values: values,
}); });
return; return;
} else if (this.state.enableCaptchaModal === CaptchaRule.Dynamic) { } else if (captchaRule === CaptchaRule.Dynamic) {
this.checkCaptchaStatus(values); this.checkCaptchaStatus(values);
return; return;
} }
@ -911,7 +913,7 @@ class LoginPage extends React.Component {
} }
renderCaptchaModal(application) { renderCaptchaModal(application) {
if (this.state.enableCaptchaModal === CaptchaRule.Never) { if (this.getCaptchaRule(this.getApplicationObj()) === CaptchaRule.Never) {
return null; return null;
} }
const captchaProviderItems = this.getCaptchaProviderItems(application); const captchaProviderItems = this.getCaptchaProviderItems(application);