mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
feat: add IsDemoMode
for frontend (#1555)
* feat: add `IsDemoMode` for frontend * fix: add i18n * fix: support autologin and go same page * fix: use i18n for button text
This commit is contained in:
parent
e877045671
commit
14fa914e6f
@ -57,7 +57,7 @@ func AutoSigninFilter(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// "/page?username=abc&password=123"
|
||||
// "/page?username=built-in/admin&password=123"
|
||||
userId = ctx.Input.Query("username")
|
||||
password := ctx.Input.Query("password")
|
||||
if userId != "" && password != "" && ctx.Input.Query("grant_type") == "" {
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
export const ShowGithubCorner = false;
|
||||
export const GithubRepo = "https://github.com/casdoor/casdoor";
|
||||
export const IsDemoMode = false;
|
||||
|
||||
export const ForceLanguage = "";
|
||||
export const DefaultLanguage = "en";
|
||||
|
63
web/src/backend/FetchInterceptor.js
Normal file
63
web/src/backend/FetchInterceptor.js
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright 2022 The Casdoor Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import {ExclamationCircleFilled} from "@ant-design/icons";
|
||||
import {Modal} from "antd";
|
||||
import i18next from "i18next";
|
||||
import * as Conf from "../Conf";
|
||||
|
||||
const {confirm} = Modal;
|
||||
const {fetch: originalFetch} = window;
|
||||
|
||||
/**
|
||||
* When modify data, prompt it's read-only and ask whether to go writable site
|
||||
*/
|
||||
const demoModePrompt = async(url, option) => {
|
||||
if (option.method === "POST") {
|
||||
confirm({
|
||||
title: i18next.t("general:This is a read-only demo site!"),
|
||||
icon: <ExclamationCircleFilled />,
|
||||
content: i18next.t("general:Go Writable demo site?"),
|
||||
okText: i18next.t("user:OK"),
|
||||
cancelText: i18next.t("general:Cancel"),
|
||||
onOk() {
|
||||
const fullURL = document.location.toString();
|
||||
window.open("https://demo.casdoor.com" + fullURL.substring(fullURL.lastIndexOf("/")) + "?username=built-in/admin&password=123", "_blank");
|
||||
},
|
||||
onCancel() {},
|
||||
});
|
||||
}
|
||||
return option;
|
||||
};
|
||||
|
||||
const requsetInterceptors = [];
|
||||
const responseInterceptors = [];
|
||||
|
||||
// when it's in DemoMode, demoModePrompt() should run before fetch
|
||||
if (Conf.IsDemoMode) {
|
||||
requsetInterceptors.push(demoModePrompt);
|
||||
}
|
||||
|
||||
/**
|
||||
* rewrite fetch to support interceptors
|
||||
*/
|
||||
window.fetch = async(url, option = {}) => {
|
||||
for (const fn of requsetInterceptors) {
|
||||
fn(url, option);
|
||||
}
|
||||
|
||||
const response = await originalFetch(url, option);
|
||||
responseInterceptors.forEach(fn => (response) => fn(response));
|
||||
return response;
|
||||
};
|
@ -22,6 +22,7 @@ import "./App.less";
|
||||
import App from "./App";
|
||||
import * as serviceWorker from "./serviceWorker";
|
||||
import {BrowserRouter} from "react-router-dom";
|
||||
import "./backend/FetchInterceptor";
|
||||
|
||||
const container = document.getElementById("root");
|
||||
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "First name",
|
||||
"Forget URL": "URL vergessen",
|
||||
"Forget URL - Tooltip": "Unique string-style identifier",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "Zuhause",
|
||||
"Home - Tooltip": "Application homepage",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sync",
|
||||
"Syncers": "Syncers",
|
||||
"SysInfo": "SysInfo",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "Zeitstempel",
|
||||
"Tokens": "Token",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "First name",
|
||||
"Forget URL": "Forget URL",
|
||||
"Forget URL - Tooltip": "Forget URL - Tooltip",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "Home",
|
||||
"Home - Tooltip": "Home - Tooltip",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sync",
|
||||
"Syncers": "Syncers",
|
||||
"SysInfo": "SysInfo",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "Timestamp",
|
||||
"Tokens": "Tokens",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "Nombre",
|
||||
"Forget URL": "URL de olvido",
|
||||
"Forget URL - Tooltip": "URL de olvido - Tooltip",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "Inicio",
|
||||
"Home - Tooltip": "Inicio - Tooltip",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sincronizador",
|
||||
"Syncers": "Sincronizadores",
|
||||
"SysInfo": "SysInfo",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "Timestamp",
|
||||
"Tokens": "Tokens",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "First name",
|
||||
"Forget URL": "Oublier l'URL",
|
||||
"Forget URL - Tooltip": "Unique string-style identifier",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "Domicile",
|
||||
"Home - Tooltip": "Application homepage",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sync",
|
||||
"Syncers": "Synchronisateurs",
|
||||
"SysInfo": "SysInfo",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "Horodatage",
|
||||
"Tokens": "Jetons",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "First name",
|
||||
"Forget URL": "URLを忘れた",
|
||||
"Forget URL - Tooltip": "Unique string-style identifier",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "ホーム",
|
||||
"Home - Tooltip": "Application homepage",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sync",
|
||||
"Syncers": "Syncers",
|
||||
"SysInfo": "システム情報",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "タイムスタンプ",
|
||||
"Tokens": "トークン",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "First name",
|
||||
"Forget URL": "Forget URL",
|
||||
"Forget URL - Tooltip": "Unique string-style identifier",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "Home",
|
||||
"Home - Tooltip": "Application homepage",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sync",
|
||||
"Syncers": "Syncers",
|
||||
"SysInfo": "SysInfo",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "Timestamp",
|
||||
"Tokens": "Tokens",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "Имя",
|
||||
"Forget URL": "Забыть URL",
|
||||
"Forget URL - Tooltip": "Unique string-style identifier",
|
||||
"Go Writable demo site?": "Go Writable demo site?",
|
||||
"Home": "Домашний",
|
||||
"Home - Tooltip": "Application homepage",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "Sync",
|
||||
"Syncers": "Синхронизаторы",
|
||||
"SysInfo": "Информация о системе",
|
||||
"This is a read-only demo site!": "This is a read-only demo site!",
|
||||
"Timestamp": "Отметка времени",
|
||||
"Tokens": "Жетоны",
|
||||
"URL": "URL",
|
||||
|
@ -181,6 +181,7 @@
|
||||
"First name": "名字",
|
||||
"Forget URL": "忘记密码URL",
|
||||
"Forget URL - Tooltip": "忘记密码URL",
|
||||
"Go Writable demo site?": "跳转至可写演示站点?",
|
||||
"Home": "首页",
|
||||
"Home - Tooltip": "应用的首页",
|
||||
"ID": "ID",
|
||||
@ -255,6 +256,7 @@
|
||||
"Sync": "同步",
|
||||
"Syncers": "同步器",
|
||||
"SysInfo": "系统信息",
|
||||
"This is a read-only demo site!": "这是一个只读演示站点!",
|
||||
"Timestamp": "时间戳",
|
||||
"Tokens": "令牌",
|
||||
"URL": "链接",
|
||||
|
Loading…
x
Reference in New Issue
Block a user