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