Fix page links.

This commit is contained in:
Yang Luo 2021-04-28 22:40:21 +08:00
parent 35e482f24e
commit c26c9ba0e8
4 changed files with 60 additions and 8 deletions

View File

@ -347,6 +347,7 @@ class App extends Component {
<Route exact path="/signup" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...props} />)}/>
<Route exact path="/signup/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<SignupPage {...props} />)}/>
<Route exact path="/result" render={(props) => this.renderHomeIfLoggedIn(<ResultPage {...props} />)}/>
<Route exact path="/result/:applicationName" render={(props) => this.renderHomeIfLoggedIn(<ResultPage {...props} />)}/>
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<SelfLoginPage {...props} />)}/>
<Route exact path="/callback" component={AuthCallback}/>
<Route exact path="/" render={(props) => this.renderLoginIfNotLoggedIn(<HomePage account={this.state.account} {...props} />)}/>

View File

@ -18,6 +18,7 @@ import {isMobile as isMobileDevice} from "react-device-detect";
import "./i18n";
import i18next from "i18next";
import copy from "copy-to-clipboard";
import {authConfig} from "./auth/Auth";
export let ServerUrl = "";
@ -197,3 +198,15 @@ export function renderLogo(application) {
);
}
}
export function goToLogin(ths, application) {
if (application === null) {
return;
}
if (authConfig.appName === application.name) {
goToLinkSoft(ths, "/login");
} else {
goToLink(`${application.homepageUrl}/login`);
}
}

View File

@ -13,19 +13,47 @@
// limitations under the License.
import React from "react";
import {Link} from "react-router-dom";
import {Result, Button} from 'antd';
import i18next from "i18next";
import {authConfig} from "./Auth";
import * as Util from "./Util";
import * as ApplicationBackend from "../backend/ApplicationBackend";
import * as Setting from "../Setting";
class ResultPage extends React.Component {
constructor(props) {
super(props);
this.state = {
classes: props,
applicationName: props.match.params.applicationName !== undefined ? props.match.params.applicationName : authConfig.appName,
application: null,
};
}
UNSAFE_componentWillMount() {
if (this.state.applicationName !== undefined) {
this.getApplication();
} else {
Util.showMessage("error", `Unknown application name: ${this.state.applicationName}`);
}
}
getApplication() {
if (this.state.applicationName === undefined) {
return;
}
ApplicationBackend.getApplication("admin", this.state.applicationName)
.then((application) => {
this.setState({
application: application,
});
});
}
render() {
const application = this.state.application;
return (
<div>
<Result
@ -33,11 +61,11 @@ class ResultPage extends React.Component {
title={i18next.t("signup:Your account has been created!")}
subTitle={i18next.t("signup:Please click the below button to sign in")}
extra={[
<Link to="/login">
<Button type="primary" key="login">
{i18next.t("login:Sign In")}
</Button>
</Link>
<Button type="primary" key="login" onClick={() => {
Setting.goToLogin(this, application);
}}>
{i18next.t("login:Sign In")}
</Button>
]}
/>
</div>

View File

@ -89,11 +89,19 @@ class SignupPage extends React.Component {
});
}
getResultPath(application) {
if (authConfig.appName === application.name) {
return "/result";
} else {
return `/result/${application.name}`;
}
}
onFinish(values) {
AuthBackend.signup(values)
.then((res) => {
if (res.status === 'ok') {
this.props.history.push('/result');
Setting.goToLinkSoft(this, this.getResultPath(this.state.application));
} else {
Setting.showMessage("error", `Failed to sign up: ${res.msg}`);
}
@ -264,7 +272,9 @@ class SignupPage extends React.Component {
{i18next.t("account:Sign Up")}
</Button>
&nbsp;&nbsp;{i18next.t("signup:Have account?")}&nbsp;
<Link to={"/login"}>
<Link onClick={() => {
Setting.goToLogin(this, application);
}}>
{i18next.t("signup:sign in now")}
</Link>
</Form.Item>