feat: fix bug that can not get application in signup/oauth/ router (#1766)

This commit is contained in:
Yaodong Yu 2023-04-22 18:20:45 +08:00 committed by GitHub
parent e0028f5eed
commit 4f8dd771bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 42 deletions

View File

@ -25,6 +25,7 @@ import SelfForgetPage from "./auth/SelfForgetPage";
import ForgetPage from "./auth/ForgetPage"; import ForgetPage from "./auth/ForgetPage";
import PromptPage from "./auth/PromptPage"; import PromptPage from "./auth/PromptPage";
import CasLogout from "./auth/CasLogout"; import CasLogout from "./auth/CasLogout";
import {authConfig} from "./auth/Auth";
class EntryPage extends React.Component { class EntryPage extends React.Component {
constructor(props) { constructor(props) {
@ -71,7 +72,7 @@ class EntryPage extends React.Component {
<div className="loginBackground" style={{backgroundImage: Setting.inIframe() || Setting.isMobile() ? null : `url(${this.state.application?.formBackgroundUrl})`}}> <div className="loginBackground" style={{backgroundImage: Setting.inIframe() || Setting.isMobile() ? null : `url(${this.state.application?.formBackgroundUrl})`}}>
<Spin size="large" spinning={this.state.application === undefined} tip={i18next.t("login:Loading")} style={{margin: "0 auto"}} /> <Spin size="large" spinning={this.state.application === undefined} tip={i18next.t("login:Loading")} style={{margin: "0 auto"}} />
<Switch> <Switch>
<Route exact path="/signup" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} /> <Route exact path="/signup" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...this.props} application={this.state.application} applicationName={authConfig.appName} onUpdateApplication={onUpdateApplication} {...props} />)} />
<Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} /> <Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} />
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} /> <Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} />
<Route exact path="/login/:owner" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} /> <Route exact path="/login/:owner" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage {...this.props} application={this.state.application} onUpdateApplication={onUpdateApplication} {...props} />)} />

View File

@ -147,7 +147,6 @@ class LoginPage extends React.Component {
}); });
} }
}); });
return null;
} }
getApplication() { getApplication() {
@ -600,33 +599,20 @@ class LoginPage extends React.Component {
} }
renderFooter(application) { renderFooter(application) {
if (this.state.mode === "signup") { return (
return ( <span style={{float: "right"}}>
<div style={{float: "right"}}> {
{i18next.t("signup:Have account?")}&nbsp; !application.enableSignUp ? null : (
{ <React.Fragment>
Setting.renderLoginLink(application, i18next.t("signup:sign in now")) {i18next.t("login:No account?")}&nbsp;
} {
</div> Setting.renderSignupLink(application, i18next.t("login:sign up now"))
); }
} else { </React.Fragment>
return ( )
<React.Fragment> }
<span style={{float: "right"}}> </span>
{ );
!application.enableSignUp ? null : (
<React.Fragment>
{i18next.t("login:No account?")}&nbsp;
{
Setting.renderSignupLink(application, i18next.t("login:sign up now"))
}
</React.Fragment>
)
}
</span>
</React.Fragment>
);
}
} }
sendSilentSigninData(data) { sendSilentSigninData(data) {
@ -775,13 +761,9 @@ class LoginPage extends React.Component {
renderMethodChoiceBox() { renderMethodChoiceBox() {
const application = this.getApplicationObj(); const application = this.getApplicationObj();
const items = [ const items = [];
{label: i18next.t("general:Password"), key: "password"}, items.push({label: i18next.t("general:Password"), key: "password"});
]; application.enableCodeSignin ? items.push({label: i18next.t("login:Verification code"), key: "verificationCode"}) : null;
application.enableCodeSignin ? items.push({
label: i18next.t("login:Verification code"),
key: "verificationCode",
}) : null;
application.enableWebAuthn ? items.push({label: i18next.t("login:WebAuthn"), key: "webAuthn"}) : null; application.enableWebAuthn ? items.push({label: i18next.t("login:WebAuthn"), key: "webAuthn"}) : null;
if (application.enableCodeSignin || application.enableWebAuthn) { if (application.enableCodeSignin || application.enableWebAuthn) {

View File

@ -66,7 +66,7 @@ class SignupPage extends React.Component {
super(props); super(props);
this.state = { this.state = {
classes: props, classes: props,
applicationName: props.match?.params?.applicationName ?? authConfig.appName, applicationName: props.match?.params?.applicationName ?? null,
email: "", email: "",
phone: "", phone: "",
countryCode: "", countryCode: "",
@ -92,8 +92,11 @@ class SignupPage extends React.Component {
if (this.getApplicationObj() === undefined) { if (this.getApplicationObj() === undefined) {
if (this.state.applicationName !== null) { if (this.state.applicationName !== null) {
this.getApplication(this.state.applicationName); this.getApplication(this.state.applicationName);
} else if (oAuthParams !== null) {
this.getApplicationLogin(oAuthParams);
} else { } else {
Setting.showMessage("error", `Unknown application name: ${this.state.applicationName}`); Setting.showMessage("error", `Unknown application name: ${this.state.applicationName}`);
this.onUpdateApplication(null);
} }
} }
} }
@ -109,6 +112,21 @@ class SignupPage extends React.Component {
}); });
} }
getApplicationLogin(oAuthParams) {
AuthBackend.getApplicationLogin(oAuthParams)
.then((res) => {
if (res.status === "ok") {
const application = res.data;
this.onUpdateApplication(application);
} else {
this.onUpdateApplication(null);
this.setState({
msg: res.msg,
});
}
});
}
getResultPath(application) { getResultPath(application) {
if (authConfig.appName === application.name) { if (authConfig.appName === application.name) {
return "/result"; return "/result";
@ -178,11 +196,7 @@ class SignupPage extends React.Component {
} }
isProviderVisible(providerItem) { isProviderVisible(providerItem) {
if (this.state.mode === "signup") { return Setting.isProviderVisibleForSignUp(providerItem);
return Setting.isProviderVisibleForSignUp(providerItem);
} else {
return Setting.isProviderVisibleForSignIn(providerItem);
}
} }
renderFormItem(application, signupItem) { renderFormItem(application, signupItem) {