mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 21:30:24 +08:00
Support language param.
This commit is contained in:
@ -146,16 +146,14 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
getAccessTokenParam() {
|
||||
getAccessTokenParam(params) {
|
||||
// "/page?access_token=123"
|
||||
const params = new URLSearchParams(this.props.location.search);
|
||||
const accessToken = params.get("access_token");
|
||||
return accessToken === null ? "" : `?accessToken=${accessToken}`;
|
||||
}
|
||||
|
||||
getCredentialParams() {
|
||||
getCredentialParams(params) {
|
||||
// "/page?username=abc&password=123"
|
||||
const params = new URLSearchParams(this.props.location.search);
|
||||
if (params.get("username") === null || params.get("password") === null) {
|
||||
return "";
|
||||
}
|
||||
@ -163,8 +161,17 @@ class App extends Component {
|
||||
}
|
||||
|
||||
getUrlWithoutQuery() {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
return location.toString().replace(location.search, "");
|
||||
return window.location.toString().replace(window.location.search, "");
|
||||
}
|
||||
|
||||
getLanguageParam(params) {
|
||||
// "/page?language=en"
|
||||
const language = params.get("language");
|
||||
if (language !== null) {
|
||||
Setting.setLanguage(language);
|
||||
return `language=${language}`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
setLanguage(account) {
|
||||
@ -175,13 +182,23 @@ class App extends Component {
|
||||
}
|
||||
|
||||
getAccount() {
|
||||
let query = this.getAccessTokenParam();
|
||||
const params = new URLSearchParams(this.props.location.search);
|
||||
|
||||
let query = this.getAccessTokenParam(params);
|
||||
if (query === "") {
|
||||
query = this.getCredentialParams();
|
||||
query = this.getCredentialParams(params);
|
||||
}
|
||||
|
||||
const query2 = this.getLanguageParam(params);
|
||||
if (query2 !== "") {
|
||||
const url = window.location.toString().replace(new RegExp(`[?&]${query2}`), "");
|
||||
window.history.replaceState({}, document.title, url);
|
||||
}
|
||||
|
||||
if (query !== "") {
|
||||
window.history.replaceState({}, document.title, this.getUrlWithoutQuery());
|
||||
}
|
||||
|
||||
AuthBackend.getAccount(query)
|
||||
.then((res) => {
|
||||
let account = null;
|
||||
@ -417,20 +434,20 @@ class App extends Component {
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
);
|
||||
// res.push(
|
||||
// <Menu.Item key="/products">
|
||||
// <Link to="/products">
|
||||
// {i18next.t("general:Products")}
|
||||
// </Link>
|
||||
// </Menu.Item>
|
||||
// );
|
||||
// res.push(
|
||||
// <Menu.Item key="/payments">
|
||||
// <Link to="/payments">
|
||||
// {i18next.t("general:Payments")}
|
||||
// </Link>
|
||||
// </Menu.Item>
|
||||
// );
|
||||
res.push(
|
||||
<Menu.Item key="/products">
|
||||
<Link to="/products">
|
||||
{i18next.t("general:Products")}
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
);
|
||||
res.push(
|
||||
<Menu.Item key="/payments">
|
||||
<Link to="/payments">
|
||||
{i18next.t("general:Payments")}
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
);
|
||||
res.push(
|
||||
<Menu.Item key="/swagger">
|
||||
<a target="_blank" rel="noreferrer" href={Setting.isLocalhost() ? `${Setting.ServerUrl}/swagger` : "/swagger"}>
|
||||
|
Reference in New Issue
Block a user