mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 21:30:24 +08:00
fix: detect access denied by response message for demo mode (#1565)
fix: detect access denied by response message for demo mode
This commit is contained in:
@ -21,35 +21,38 @@ import * as Setting from "../Setting";
|
|||||||
const {confirm} = Modal;
|
const {confirm} = Modal;
|
||||||
const {fetch: originalFetch} = window;
|
const {fetch: originalFetch} = window;
|
||||||
|
|
||||||
const demoModeCallback = async(url, option) => {
|
const demoModeCallback = (res) => {
|
||||||
if (option.method === "POST") {
|
res.json().then(data => {
|
||||||
confirm({
|
if (data.msg === "Unauthorized operation") {
|
||||||
title: i18next.t("general:This is a read-only demo site!"),
|
confirm({
|
||||||
icon: <ExclamationCircleFilled />,
|
title: i18next.t("general:This is a read-only demo site!"),
|
||||||
content: i18next.t("general:Go to writable demo site?"),
|
icon: <ExclamationCircleFilled />,
|
||||||
okText: i18next.t("user:OK"),
|
content: i18next.t("general:Go to writable demo site?"),
|
||||||
cancelText: i18next.t("general:Cancel"),
|
okText: i18next.t("user:OK"),
|
||||||
onOk() {
|
cancelText: i18next.t("general:Cancel"),
|
||||||
Setting.openLink(`https://demo.casdoor.com${location.path}${location.search}?username=built-in/admin&password=123`);
|
onOk() {
|
||||||
},
|
Setting.openLink(`https://demo.casdoor.com${location.path}${location.search}?username=built-in/admin&password=123`);
|
||||||
onCancel() {},
|
},
|
||||||
});
|
onCancel() {},
|
||||||
}
|
});
|
||||||
|
}
|
||||||
return option;
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestFilters = [];
|
const requestFilters = [];
|
||||||
const responseFilters = [];
|
const responseFilters = [];
|
||||||
|
|
||||||
if (Conf.IsDemoMode) {
|
if (Conf.IsDemoMode) {
|
||||||
requestFilters.push(demoModeCallback);
|
responseFilters.push(demoModeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.fetch = async(url, option = {}) => {
|
window.fetch = async(url, option = {}) => {
|
||||||
requestFilters.forEach(filter => filter(url, option));
|
requestFilters.forEach(filter => filter(url, option));
|
||||||
|
|
||||||
const response = await originalFetch(url, option);
|
return new Promise((resolve, reject) => {
|
||||||
responseFilters.forEach(filter => (response) => filter(response));
|
originalFetch(url, option).then(res => {
|
||||||
return response;
|
responseFilters.forEach(filter => filter(res.clone()));
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user