mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
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:
parent
9f4430ed04
commit
3211bcc777
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user