2022-02-13 23:39:27 +08:00
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
2020-10-20 22:37:38 +08:00
//
// 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.
2022-07-10 15:45:55 +08:00
import React , { Component } from "react" ;
import "./App.less" ;
2021-04-29 19:51:03 +08:00
import { Helmet } from "react-helmet" ;
2020-10-20 22:37:38 +08:00
import * as Setting from "./Setting" ;
2022-10-10 16:37:25 +02:00
import { BarsOutlined , DownOutlined , LogoutOutlined , SettingOutlined } from "@ant-design/icons" ;
2023-02-01 22:06:40 +08:00
import { Avatar , Button , Card , ConfigProvider , Drawer , Dropdown , FloatButton , Layout , Menu , Result } from "antd" ;
2022-07-10 15:45:55 +08:00
import { Link , Redirect , Route , Switch , withRouter } from "react-router-dom" ;
2020-12-20 20:31:48 +08:00
import OrganizationListPage from "./OrganizationListPage" ;
import OrganizationEditPage from "./OrganizationEditPage" ;
2020-10-20 23:14:03 +08:00
import UserListPage from "./UserListPage" ;
import UserEditPage from "./UserEditPage" ;
2022-01-01 15:11:16 +08:00
import RoleListPage from "./RoleListPage" ;
import RoleEditPage from "./RoleEditPage" ;
2022-01-01 16:28:06 +08:00
import PermissionListPage from "./PermissionListPage" ;
import PermissionEditPage from "./PermissionEditPage" ;
2020-12-20 21:25:23 +08:00
import ProviderListPage from "./ProviderListPage" ;
import ProviderEditPage from "./ProviderEditPage" ;
2020-12-20 23:24:09 +08:00
import ApplicationListPage from "./ApplicationListPage" ;
import ApplicationEditPage from "./ApplicationEditPage" ;
2021-08-15 00:17:53 +08:00
import ResourceListPage from "./ResourceListPage" ;
2021-07-17 14:13:00 +08:00
import LdapEditPage from "./LdapEditPage" ;
import LdapSyncPage from "./LdapSyncPage" ;
2021-03-13 23:47:35 +08:00
import TokenListPage from "./TokenListPage" ;
import TokenEditPage from "./TokenEditPage" ;
2021-07-07 14:59:03 +08:00
import RecordListPage from "./RecordListPage" ;
2021-11-07 15:41:24 +08:00
import WebhookListPage from "./WebhookListPage" ;
import WebhookEditPage from "./WebhookEditPage" ;
2021-12-17 16:32:53 +08:00
import SyncerListPage from "./SyncerListPage" ;
import SyncerEditPage from "./SyncerEditPage" ;
2021-12-31 00:36:36 +08:00
import CertListPage from "./CertListPage" ;
import CertEditPage from "./CertEditPage" ;
2022-02-27 18:20:58 +08:00
import ProductListPage from "./ProductListPage" ;
import ProductEditPage from "./ProductEditPage" ;
2022-02-27 23:50:35 +08:00
import ProductBuyPage from "./ProductBuyPage" ;
2022-02-05 01:18:13 +08:00
import PaymentListPage from "./PaymentListPage" ;
import PaymentEditPage from "./PaymentEditPage" ;
2022-03-13 18:05:16 +08:00
import PaymentResultPage from "./PaymentResultPage" ;
2021-02-13 01:33:06 +08:00
import AccountPage from "./account/AccountPage" ;
2021-02-13 17:34:32 +08:00
import HomePage from "./basic/HomePage" ;
2021-08-07 19:52:01 +08:00
import CustomGithubCorner from "./CustomGithubCorner" ;
2022-03-05 23:51:55 +08:00
import * as Conf from "./Conf" ;
2021-02-14 15:40:57 +08:00
2021-02-14 16:59:08 +08:00
import * as Auth from "./auth/Auth" ;
2022-12-22 23:39:02 +08:00
import EntryPage from "./EntryPage" ;
2021-03-26 21:57:41 +08:00
import ResultPage from "./auth/ResultPage" ;
2021-02-14 15:40:57 +08:00
import * as AuthBackend from "./auth/AuthBackend" ;
2021-02-14 14:34:03 +08:00
import AuthCallback from "./auth/AuthCallback" ;
2022-07-10 15:45:55 +08:00
import SelectLanguageBox from "./SelectLanguageBox" ;
import i18next from "i18next" ;
2021-09-25 14:54:13 +08:00
import OdicDiscoveryPage from "./auth/OidcDiscoveryPage" ;
2022-07-10 15:45:55 +08:00
import SamlCallback from "./auth/SamlCallback" ;
2022-05-24 18:27:47 +08:00
import ModelListPage from "./ModelListPage" ;
import ModelEditPage from "./ModelEditPage" ;
2022-08-20 21:22:46 +08:00
import SystemInfo from "./SystemInfo" ;
2022-09-14 22:14:13 +08:00
import AdapterListPage from "./AdapterListPage" ;
import AdapterEditPage from "./AdapterEditPage" ;
2022-10-12 13:52:02 +02:00
import { withTranslation } from "react-i18next" ;
2022-12-29 15:30:37 +01:00
import SelectThemeBox from "./SelectThemeBox" ;
2023-01-06 15:04:13 +08:00
import SessionListPage from "./SessionListPage" ;
2020-10-20 22:37:38 +08:00
2022-12-06 00:50:17 +08:00
const { Header , Footer , Content } = Layout ;
2020-10-20 22:37:38 +08:00
class App extends Component {
constructor ( props ) {
super ( props ) ;
this . state = {
classes : props ,
selectedMenuKey : 0 ,
account : undefined ,
2021-03-26 21:57:41 +08:00
uri : null ,
2022-10-10 16:37:25 +02:00
menuVisible : false ,
2023-02-01 22:06:40 +08:00
themeAlgorithm : [ "default" ] ,
themeData : Setting . ThemeDefault ,
2020-10-20 22:37:38 +08:00
} ;
2020-10-20 23:14:03 +08:00
Setting . initServerUrl ( ) ;
2021-02-14 16:59:08 +08:00
Auth . initAuthWithConfig ( {
serverUrl : Setting . ServerUrl ,
2021-12-13 16:42:46 +08:00
appName : "app-built-in" , // the application name of Casdoor itself, do not change it
2021-02-14 16:59:08 +08:00
} ) ;
2020-10-20 22:37:38 +08:00
}
2021-03-27 11:38:15 +08:00
UNSAFE _componentWillMount ( ) {
2020-10-20 22:37:38 +08:00
this . updateMenuKey ( ) ;
this . getAccount ( ) ;
}
2021-03-26 21:57:41 +08:00
componentDidUpdate ( ) {
// eslint-disable-next-line no-restricted-globals
const uri = location . pathname ;
if ( this . state . uri !== uri ) {
this . updateMenuKey ( ) ;
}
}
2020-10-20 22:37:38 +08:00
updateMenuKey ( ) {
// eslint-disable-next-line no-restricted-globals
const uri = location . pathname ;
2021-03-26 21:57:41 +08:00
this . setState ( {
uri : uri ,
} ) ;
2022-07-10 15:45:55 +08:00
if ( uri === "/" ) {
this . setState ( { selectedMenuKey : "/" } ) ;
} else if ( uri . includes ( "/organizations" ) ) {
this . setState ( { selectedMenuKey : "/organizations" } ) ;
} else if ( uri . includes ( "/users" ) ) {
this . setState ( { selectedMenuKey : "/users" } ) ;
} else if ( uri . includes ( "/roles" ) ) {
this . setState ( { selectedMenuKey : "/roles" } ) ;
} else if ( uri . includes ( "/permissions" ) ) {
this . setState ( { selectedMenuKey : "/permissions" } ) ;
} else if ( uri . includes ( "/models" ) ) {
this . setState ( { selectedMenuKey : "/models" } ) ;
2022-09-14 22:14:13 +08:00
} else if ( uri . includes ( "/adapters" ) ) {
this . setState ( { selectedMenuKey : "/adapters" } ) ;
2022-07-10 15:45:55 +08:00
} else if ( uri . includes ( "/providers" ) ) {
this . setState ( { selectedMenuKey : "/providers" } ) ;
} else if ( uri . includes ( "/applications" ) ) {
this . setState ( { selectedMenuKey : "/applications" } ) ;
} else if ( uri . includes ( "/resources" ) ) {
this . setState ( { selectedMenuKey : "/resources" } ) ;
} else if ( uri . includes ( "/tokens" ) ) {
this . setState ( { selectedMenuKey : "/tokens" } ) ;
} else if ( uri . includes ( "/records" ) ) {
this . setState ( { selectedMenuKey : "/records" } ) ;
} else if ( uri . includes ( "/webhooks" ) ) {
this . setState ( { selectedMenuKey : "/webhooks" } ) ;
} else if ( uri . includes ( "/syncers" ) ) {
this . setState ( { selectedMenuKey : "/syncers" } ) ;
} else if ( uri . includes ( "/certs" ) ) {
this . setState ( { selectedMenuKey : "/certs" } ) ;
} else if ( uri . includes ( "/products" ) ) {
this . setState ( { selectedMenuKey : "/products" } ) ;
} else if ( uri . includes ( "/payments" ) ) {
this . setState ( { selectedMenuKey : "/payments" } ) ;
} else if ( uri . includes ( "/signup" ) ) {
this . setState ( { selectedMenuKey : "/signup" } ) ;
} else if ( uri . includes ( "/login" ) ) {
this . setState ( { selectedMenuKey : "/login" } ) ;
} else if ( uri . includes ( "/result" ) ) {
this . setState ( { selectedMenuKey : "/result" } ) ;
2022-08-20 21:22:46 +08:00
} else if ( uri . includes ( "/sysinfo" ) ) {
this . setState ( { selectedMenuKey : "/sysinfo" } ) ;
2020-10-20 22:37:38 +08:00
} else {
2022-07-10 15:45:55 +08:00
this . setState ( { selectedMenuKey : - 1 } ) ;
2020-10-20 22:37:38 +08:00
}
}
2022-02-28 21:33:10 +08:00
getAccessTokenParam ( params ) {
2021-03-28 16:35:59 +08:00
// "/page?access_token=123"
2021-05-16 18:18:55 +08:00
const accessToken = params . get ( "access_token" ) ;
return accessToken === null ? "" : ` ?accessToken= ${ accessToken } ` ;
}
2022-02-28 21:33:10 +08:00
getCredentialParams ( params ) {
2021-05-16 18:18:55 +08:00
// "/page?username=abc&password=123"
if ( params . get ( "username" ) === null || params . get ( "password" ) === null ) {
return "" ;
}
return ` ?username= ${ params . get ( "username" ) } &password= ${ params . get ( "password" ) } ` ;
2021-03-28 16:35:59 +08:00
}
getUrlWithoutQuery ( ) {
2022-02-28 21:33:10 +08:00
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 "" ;
2021-03-28 16:35:59 +08:00
}
2023-02-01 22:06:40 +08:00
getLogo ( themes ) {
if ( themes . includes ( "dark" ) ) {
return ` ${ Setting . StaticBaseUrl } /img/casdoor-logo_1185x256_dark.png ` ;
} else {
return ` ${ Setting . StaticBaseUrl } /img/casdoor-logo_1185x256.png ` ;
}
2022-12-29 15:30:37 +01:00
}
2021-09-14 01:22:13 +08:00
setLanguage ( account ) {
2022-08-08 23:35:24 +08:00
const language = account ? . language ;
2021-09-14 01:22:13 +08:00
if ( language !== "" && language !== i18next . language ) {
Setting . setLanguage ( language ) ;
}
}
2023-02-01 22:06:40 +08:00
setTheme = ( theme , initThemeAlgorithm ) => {
this . setState ( {
themeData : theme ,
} ) ;
if ( initThemeAlgorithm ) {
this . setState ( {
logo : this . getLogo ( Setting . getAlgorithmNames ( theme ) ) ,
themeAlgorithm : Setting . getAlgorithmNames ( theme ) ,
} ) ;
}
} ;
2020-10-20 22:37:38 +08:00
getAccount ( ) {
2022-02-28 21:33:10 +08:00
const params = new URLSearchParams ( this . props . location . search ) ;
let query = this . getAccessTokenParam ( params ) ;
2021-05-16 18:18:55 +08:00
if ( query === "" ) {
2022-02-28 21:33:10 +08:00
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 ) ;
2021-05-16 18:18:55 +08:00
}
2022-02-28 21:33:10 +08:00
2021-05-16 18:18:55 +08:00
if ( query !== "" ) {
2021-03-28 16:35:59 +08:00
window . history . replaceState ( { } , document . title , this . getUrlWithoutQuery ( ) ) ;
}
2022-02-28 21:33:10 +08:00
2021-05-16 18:18:55 +08:00
AuthBackend . getAccount ( query )
2020-10-20 22:37:38 +08:00
. then ( ( res ) => {
2021-04-29 19:51:03 +08:00
let account = null ;
if ( res . status === "ok" ) {
account = res . data ;
account . organization = res . data2 ;
2023-02-01 22:06:40 +08:00
2021-09-14 01:22:13 +08:00
this . setLanguage ( account ) ;
2023-02-01 22:06:40 +08:00
this . setTheme ( Setting . getThemeData ( account . organization ) , Conf . InitThemeAlgorithm ) ;
2021-05-15 23:34:06 +08:00
} else {
2022-10-27 23:50:45 +08:00
if ( res . data !== "Please login first" ) {
2022-12-09 15:11:13 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "application:Failed to sign in" ) } : ${ res . msg } ` ) ;
2021-05-15 23:34:06 +08:00
}
2021-04-29 19:51:03 +08:00
}
2020-10-20 22:37:38 +08:00
this . setState ( {
2021-04-29 19:51:03 +08:00
account : account ,
2020-10-20 22:37:38 +08:00
} ) ;
} ) ;
}
logout ( ) {
this . setState ( {
expired : false ,
submitted : false ,
} ) ;
2021-02-14 15:40:57 +08:00
AuthBackend . logout ( )
2020-10-20 22:37:38 +08:00
. then ( ( res ) => {
2022-07-10 15:45:55 +08:00
if ( res . status === "ok" ) {
2022-07-26 19:27:24 +08:00
const owner = this . state . account . owner ;
2020-10-20 22:37:38 +08:00
this . setState ( {
2022-08-06 23:54:56 +08:00
account : null ,
2023-02-01 22:06:40 +08:00
themeAlgorithm : [ "default" ] ,
2020-10-20 22:37:38 +08:00
} ) ;
2022-12-09 15:11:13 +08:00
Setting . showMessage ( "success" , i18next . t ( "application:Logged out successfully" ) ) ;
2022-08-08 23:35:24 +08:00
const redirectUri = res . data2 ;
2022-03-19 19:50:05 +08:00
if ( redirectUri !== null && redirectUri !== undefined && redirectUri !== "" ) {
Setting . goToLink ( redirectUri ) ;
2022-07-26 19:27:24 +08:00
} else if ( owner !== "built-in" ) {
Setting . goToLink ( ` ${ window . location . origin } /login/ ${ owner } ` ) ;
} else {
2022-03-19 19:50:05 +08:00
Setting . goToLinkSoft ( this , "/" ) ;
}
2020-10-20 22:37:38 +08:00
} else {
2021-03-26 21:57:41 +08:00
Setting . showMessage ( "error" , ` Failed to log out: ${ res . msg } ` ) ;
2020-10-20 22:37:38 +08:00
}
} ) ;
}
2021-06-20 13:27:26 +08:00
onUpdateAccount ( account ) {
this . setState ( {
2022-08-06 23:54:56 +08:00
account : account ,
2021-06-20 13:27:26 +08:00
} ) ;
}
2021-03-28 21:18:41 +08:00
renderAvatar ( ) {
if ( this . state . account . avatar === "" ) {
return (
2022-07-10 15:45:55 +08:00
< Avatar style = { { backgroundColor : Setting . getAvatarColor ( this . state . account . name ) , verticalAlign : "middle" } } size = "large" >
2021-03-28 21:18:41 +08:00
{ Setting . getShortName ( this . state . account . name ) }
< / A v a t a r >
2022-07-10 15:45:55 +08:00
) ;
2021-03-28 21:18:41 +08:00
} else {
return (
2022-07-10 15:45:55 +08:00
< Avatar src = { this . state . account . avatar } style = { { verticalAlign : "middle" } } size = "large" >
2021-03-28 21:18:41 +08:00
{ Setting . getShortName ( this . state . account . name ) }
< / A v a t a r >
2022-07-10 15:45:55 +08:00
) ;
2021-03-28 21:18:41 +08:00
}
}
2020-10-20 22:37:38 +08:00
renderRightDropdown ( ) {
2022-12-04 23:05:30 +08:00
const items = [ ] ;
items . push ( Setting . getItem ( < > < SettingOutlined / > & nbsp ; & nbsp ; { i18next . t ( "account:My Account" ) } < / > ,
"/account"
) ) ;
items . push ( Setting . getItem ( < > < LogoutOutlined / > & nbsp ; & nbsp ; { i18next . t ( "account:Logout" ) } < / > ,
"/logout" ) ) ;
2023-02-01 22:06:40 +08:00
const onClick = ( e ) => {
if ( e . key === "/account" ) {
this . props . history . push ( "/account" ) ;
} else if ( e . key === "/logout" ) {
this . logout ( ) ;
}
} ;
2020-10-20 22:37:38 +08:00
return (
2023-02-01 22:06:40 +08:00
< Dropdown key = "/rightDropDown" menu = { { items , onClick } } >
< div className = "rightDropDown" >
2021-03-28 21:18:41 +08:00
{
this . renderAvatar ( )
}
2020-10-20 22:37:38 +08:00
& nbsp ;
& nbsp ;
2021-04-27 20:42:19 +08:00
{ Setting . isMobile ( ) ? null : Setting . getShortName ( this . state . account . displayName ) } & nbsp ; < DownOutlined / >
2020-10-20 22:37:38 +08:00
& nbsp ;
& nbsp ;
& nbsp ;
2021-03-27 11:38:15 +08:00
< / d i v >
2020-10-20 22:37:38 +08:00
< / D r o p d o w n >
2022-07-10 15:45:55 +08:00
) ;
2020-10-20 22:37:38 +08:00
}
2023-02-01 22:06:40 +08:00
renderAccountMenu ( ) {
2021-02-14 00:22:24 +08:00
if ( this . state . account === undefined ) {
return null ;
} else if ( this . state . account === null ) {
2023-02-01 22:06:40 +08:00
return null ;
2021-02-14 00:22:24 +08:00
} else {
2023-02-01 22:06:40 +08:00
return (
< React . Fragment >
{ this . renderRightDropdown ( ) }
< SelectThemeBox
themeAlgorithm = { this . state . themeAlgorithm }
onChange = { ( nextThemeAlgorithm ) => {
this . setState ( {
themeAlgorithm : nextThemeAlgorithm ,
logo : this . getLogo ( nextThemeAlgorithm ) ,
} ) ;
} } / >
< SelectLanguageBox languages = { this . state . account . organization . languages } / >
< / R e a c t . F r a g m e n t >
) ;
2020-10-20 22:37:38 +08:00
}
}
2023-02-01 22:06:40 +08:00
getMenuItems ( ) {
2022-08-08 23:35:24 +08:00
const res = [ ] ;
2020-10-20 22:37:38 +08:00
2021-02-13 01:33:06 +08:00
if ( this . state . account === null || this . state . account === undefined ) {
return [ ] ;
}
2020-10-20 22:37:38 +08:00
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/" > { i18next . t ( "general:Home" ) } < /Link>, "/ " ) ) ;
2021-02-15 22:14:19 +08:00
if ( Setting . isAdminUser ( this . state . account ) ) {
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/organizations" > { i18next . t ( "general:Organizations" ) } < / L i n k > ,
"/organizations" ) ) ;
2022-10-07 15:43:50 +08:00
}
if ( Setting . isLocalAdminUser ( this . state . account ) ) {
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/users" > { i18next . t ( "general:Users" ) } < / L i n k > ,
"/users"
) ) ;
res . push ( Setting . getItem ( < Link to = "/roles" > { i18next . t ( "general:Roles" ) } < / L i n k > ,
"/roles"
) ) ;
res . push ( Setting . getItem ( < Link to = "/permissions" > { i18next . t ( "general:Permissions" ) } < / L i n k > ,
"/permissions"
) ) ;
2022-08-15 14:09:12 +08:00
}
if ( Setting . isAdminUser ( this . state . account ) ) {
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/models" > { i18next . t ( "general:Models" ) } < / L i n k > ,
"/models"
) ) ;
res . push ( Setting . getItem ( < Link to = "/adapters" > { i18next . t ( "general:Adapters" ) } < / L i n k > ,
"/adapters"
) ) ;
2022-11-21 01:17:55 +08:00
}
2022-12-04 23:05:30 +08:00
2022-11-21 01:17:55 +08:00
if ( Setting . isLocalAdminUser ( this . state . account ) ) {
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/applications" > { i18next . t ( "general:Applications" ) } < / L i n k > ,
"/applications"
) ) ;
res . push ( Setting . getItem ( < Link to = "/providers" > { i18next . t ( "general:Providers" ) } < / L i n k > ,
"/providers"
) ) ;
res . push ( Setting . getItem ( < Link to = "/resources" > { i18next . t ( "general:Resources" ) } < / L i n k > ,
"/resources"
) ) ;
res . push ( Setting . getItem ( < Link to = "/records" > { i18next . t ( "general:Records" ) } < / L i n k > ,
"/records"
) ) ;
2022-09-18 16:16:45 +08:00
}
if ( Setting . isAdminUser ( this . state . account ) ) {
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/tokens" > { i18next . t ( "general:Tokens" ) } < / L i n k > ,
"/tokens"
) ) ;
2023-01-06 15:04:13 +08:00
res . push ( Setting . getItem ( < Link to = "/sessions" > { i18next . t ( "general:Sessions" ) } < / L i n k > ,
"/sessions"
) ) ;
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/webhooks" > { i18next . t ( "general:Webhooks" ) } < / L i n k > ,
"/webhooks"
) ) ;
res . push ( Setting . getItem ( < Link to = "/syncers" > { i18next . t ( "general:Syncers" ) } < / L i n k > ,
"/syncers"
) ) ;
res . push ( Setting . getItem ( < Link to = "/certs" > { i18next . t ( "general:Certs" ) } < / L i n k > ,
"/certs"
) ) ;
2022-03-05 23:51:55 +08:00
if ( Conf . EnableExtraPages ) {
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < Link to = "/products" > { i18next . t ( "general:Products" ) } < / L i n k > ,
"/products"
) ) ;
res . push ( Setting . getItem ( < Link to = "/payments" > { i18next . t ( "general:Payments" ) } < / L i n k > ,
"/payments"
) ) ;
res . push ( Setting . getItem ( < Link to = "/sysinfo" > { i18next . t ( "general:SysInfo" ) } < / L i n k > ,
"/sysinfo"
) ) ;
2022-03-05 23:51:55 +08:00
}
2022-12-04 23:05:30 +08:00
res . push ( Setting . getItem ( < a target = "_blank" rel = "noreferrer"
href = { Setting . isLocalhost ( ) ? ` ${ Setting . ServerUrl } /swagger ` : "/swagger" } > { i18next . t ( "general:Swagger" ) } < / a > ,
"/swagger"
) ) ;
2021-02-15 22:14:19 +08:00
}
2021-09-06 00:49:10 +08:00
2020-10-20 22:37:38 +08:00
return res ;
}
2021-02-13 01:33:06 +08:00
renderHomeIfLoggedIn ( component ) {
2020-10-20 22:37:38 +08:00
if ( this . state . account !== null && this . state . account !== undefined ) {
2022-07-10 15:45:55 +08:00
return < Redirect to = "/" / > ;
2020-10-20 22:37:38 +08:00
} else {
return component ;
}
}
2021-02-13 00:11:12 +08:00
renderLoginIfNotLoggedIn ( component ) {
2020-10-20 22:37:38 +08:00
if ( this . state . account === null ) {
2022-02-12 09:55:06 +08:00
sessionStorage . setItem ( "from" , window . location . pathname ) ;
2022-07-10 15:45:55 +08:00
return < Redirect to = "/login" / > ;
2020-10-20 22:37:38 +08:00
} else if ( this . state . account === undefined ) {
return null ;
2022-07-10 15:45:55 +08:00
} else {
2020-10-20 22:37:38 +08:00
return component ;
}
}
isStartPages ( ) {
2022-07-10 15:45:55 +08:00
return window . location . pathname . startsWith ( "/login" ) ||
window . location . pathname . startsWith ( "/signup" ) ||
window . location . pathname === "/" ;
2020-10-20 22:37:38 +08:00
}
2022-07-10 15:45:55 +08:00
renderRouter ( ) {
2022-09-04 19:40:30 +08:00
return (
2023-02-01 22:06:40 +08:00
< Switch >
< Route exact path = "/result" render = { ( props ) => this . renderHomeIfLoggedIn ( < ResultPage { ... props } / > ) } / >
< Route exact path = "/result/:applicationName" render = { ( props ) => this . renderHomeIfLoggedIn ( < ResultPage { ... props } / > ) } / >
< Route exact path = "/" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < HomePage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/account" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < AccountPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/organizations" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < OrganizationListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/organizations/:organizationName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < OrganizationEditPage account = { this . state . account } onChangeTheme = { this . setTheme } { ... props } / > ) } / >
< Route exact path = "/organizations/:organizationName/users" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < UserListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/users" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < UserListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/users/:organizationName/:userName" render = { ( props ) => < UserEditPage account = { this . state . account } { ... props } / > } / >
< Route exact path = "/roles" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < RoleListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/roles/:organizationName/:roleName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < RoleEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/permissions" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < PermissionListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/permissions/:organizationName/:permissionName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < PermissionEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/models" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ModelListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/models/:organizationName/:modelName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ModelEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/adapters" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < AdapterListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/adapters/:organizationName/:adapterName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < AdapterEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/providers" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ProviderListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/providers/:organizationName/:providerName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ProviderEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/applications" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ApplicationListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/applications/:organizationName/:applicationName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ApplicationEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/resources" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ResourceListPage account = { this . state . account } { ... props } / > ) } / >
{ /* <Route exact path="/resources/:resourceName" render={(props) => this.renderLoginIfNotLoggedIn(<ResourceEditPage account={this.state.account} {...props} />)}/>*/ }
< Route exact path = "/ldap/:ldapId" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < LdapEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/ldap/sync/:ldapId" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < LdapSyncPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/tokens" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < TokenListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/sessions" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < SessionListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/tokens/:tokenName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < TokenEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/webhooks" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < WebhookListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/webhooks/:webhookName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < WebhookEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/syncers" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < SyncerListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/syncers/:syncerName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < SyncerEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/certs" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < CertListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/certs/:certName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < CertEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/products" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ProductListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/products/:productName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ProductEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/products/:productName/buy" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < ProductBuyPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/payments" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < PaymentListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/payments/:paymentName" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < PaymentEditPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/payments/:paymentName/result" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < PaymentResultPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/records" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < RecordListPage account = { this . state . account } { ... props } / > ) } / >
< Route exact path = "/.well-known/openid-configuration" render = { ( props ) => < OdicDiscoveryPage / > } / >
< Route exact path = "/sysinfo" render = { ( props ) => this . renderLoginIfNotLoggedIn ( < SystemInfo account = { this . state . account } { ... props } / > ) } / >
< Route path = "" render = { ( ) => < Result status = "404" title = "404 NOT FOUND" subTitle = { i18next . t ( "general:Sorry, the page you visited does not exist." ) }
extra = { < a href = "/" > < Button type = "primary" > { i18next . t ( "general:Back Home" ) } < / B u t t o n > < / a > } / > } / >
< / S w i t c h >
2022-07-10 15:45:55 +08:00
) ;
2021-07-23 09:46:01 +08:00
}
2022-10-10 16:37:25 +02:00
onClose = ( ) => {
this . setState ( {
menuVisible : false ,
} ) ;
} ;
showMenu = ( ) => {
this . setState ( {
menuVisible : true ,
} ) ;
} ;
2020-10-20 22:37:38 +08:00
renderContent ( ) {
2023-02-01 22:06:40 +08:00
return (
< Layout id = "parent-area" >
{ /* https://github.com/ant-design/ant-design/issues/40394 ant design bug. If it will be fixed, we can delete the code for control the color of Header*/ }
< Header style = { { padding : "0" , marginBottom : "3px" , backgroundColor : this . state . themeAlgorithm . includes ( "dark" ) ? "black" : "white" } } >
{ Setting . isMobile ( ) ? null : (
< Link to = { "/" } >
< div className = "logo" style = { { background : ` url( ${ this . getLogo ( Setting . getAlgorithmNames ( this . state . themeData ) ) } ) ` } } / >
< / L i n k >
) }
{ Setting . isMobile ( ) ?
< React . Fragment >
< Drawer title = { i18next . t ( "general:Close" ) } placement = "left" visible = { this . state . menuVisible } onClose = { this . onClose } >
< Menu
items = { this . getMenuItems ( ) }
mode = { "inline" }
selectedKeys = { [ this . state . selectedMenuKey ] }
style = { { lineHeight : "64px" } }
onClick = { this . onClose }
>
< / M e n u >
< / D r a w e r >
< Button icon = { < BarsOutlined / > } onClick = { this . showMenu } type = "text" >
{ i18next . t ( "general:Menu" ) }
< / B u t t o n >
< / R e a c t . F r a g m e n t > :
2022-12-29 15:30:37 +01:00
< Menu
2023-02-01 22:06:40 +08:00
items = { this . getMenuItems ( ) }
mode = { "horizontal" }
selectedKeys = { [ this . state . selectedMenuKey ] }
style = { { position : "absolute" , left : "145px" , right : "260px" } }
2022-12-29 15:30:37 +01:00
/ >
2023-02-01 22:06:40 +08:00
}
{
this . renderAccountMenu ( )
}
< / H e a d e r >
< Content style = { { display : "flex" , flexDirection : "column" } } >
{ Setting . isMobile ( ) ?
this . renderRouter ( ) :
2022-12-06 00:50:17 +08:00
< Card className = "content-warp-card" >
2023-02-01 22:06:40 +08:00
{ this . renderRouter ( ) }
2022-12-06 00:50:17 +08:00
< / C a r d >
}
2023-02-01 22:06:40 +08:00
< / C o n t e n t >
{ this . renderFooter ( ) }
< / L a y o u t >
) ;
2020-10-20 22:37:38 +08:00
}
renderFooter ( ) {
return (
2022-12-22 23:39:02 +08:00
< React . Fragment >
2022-09-23 16:03:09 +08:00
{ ! this . state . account ? null : < div style = { { display : "none" } } id = "CasdoorApplicationName" value = { this . state . account . signupApplication } / > }
< Footer id = "footer" style = {
{
textAlign : "center" ,
}
} >
2023-02-01 22:06:40 +08:00
Powered by < a target = "_blank" href = "https://casdoor.org" rel = "noreferrer" > < img style = { { paddingBottom : "3px" } } height = { "20px" } alt = { "Casdoor" } src = { this . getLogo ( Setting . getAlgorithmNames ( this . state . themeData ) ) } / > < / a >
2022-09-23 16:03:09 +08:00
< / F o o t e r >
2022-12-22 23:39:02 +08:00
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2020-10-20 22:37:38 +08:00
}
2021-02-11 16:43:30 +08:00
isDoorPages ( ) {
2022-12-22 23:39:02 +08:00
return this . isEntryPages ( ) || window . location . pathname . startsWith ( "/callback" ) ;
}
isEntryPages ( ) {
2021-06-09 20:38:46 +08:00
return window . location . pathname . startsWith ( "/signup" ) ||
window . location . pathname . startsWith ( "/login" ) ||
2022-04-04 00:09:04 +08:00
window . location . pathname . startsWith ( "/forget" ) ||
2022-12-22 23:39:02 +08:00
window . location . pathname . startsWith ( "/prompt" ) ||
window . location . pathname . startsWith ( "/cas" ) ||
window . location . pathname . startsWith ( "/auto-signup" ) ;
2021-02-11 16:43:30 +08:00
}
2021-04-29 19:51:03 +08:00
renderPage ( ) {
2021-02-11 16:43:30 +08:00
if ( this . isDoorPages ( ) ) {
return (
2023-02-01 22:06:40 +08:00
< Layout id = "parent-area" >
< Content style = { { display : "flex" , justifyContent : "center" } } >
2022-12-06 00:50:17 +08:00
{
2023-02-01 22:06:40 +08:00
this . isEntryPages ( ) ?
< EntryPage
account = { this . state . account }
theme = { this . state . themeData }
onUpdateAccount = { ( account ) => {
this . onUpdateAccount ( account ) ;
} }
updataThemeData = { ( nextThemeData ) => {
this . setState ( {
themeData : nextThemeData ,
} ) ;
localStorage . setItem ( "themeAlgorithm" , Setting . getAlgorithmNames ( nextThemeData ) . toString ( ) ) ;
} }
/ > :
< Switch >
< Route exact path = "/callback" component = { AuthCallback } / >
< Route exact path = "/callback/saml" component = { SamlCallback } / >
< Route path = "" render = { ( ) => < Result status = "404" title = "404 NOT FOUND" subTitle = { i18next . t ( "general:Sorry, the page you visited does not exist." ) }
extra = { < a href = "/" > < Button type = "primary" > { i18next . t ( "general:Back Home" ) } < / B u t t o n > < / a > } / > } / >
< / S w i t c h >
2022-12-06 00:50:17 +08:00
}
2023-02-01 22:06:40 +08:00
< / C o n t e n t >
{
this . renderFooter ( )
}
< / L a y o u t >
2022-07-10 15:45:55 +08:00
) ;
2021-02-11 16:43:30 +08:00
}
2020-10-20 22:37:38 +08:00
return (
2022-12-22 23:39:02 +08:00
< React . Fragment >
2022-12-04 23:05:30 +08:00
< FloatButton . BackTop / >
2021-08-07 19:52:01 +08:00
< CustomGithubCorner / >
2020-10-20 22:37:38 +08:00
{
2022-12-06 00:50:17 +08:00
this . renderContent ( )
2020-10-20 22:37:38 +08:00
}
2022-12-22 23:39:02 +08:00
< / R e a c t . F r a g m e n t >
2020-10-20 22:37:38 +08:00
) ;
}
2021-04-29 19:51:03 +08:00
render ( ) {
2023-02-01 22:06:40 +08:00
return (
< React . Fragment >
{ ( this . state . account === undefined || this . state . account === null ) ?
2021-04-29 19:51:03 +08:00
< Helmet >
2022-02-13 23:34:29 +08:00
< link rel = "icon" href = { "https://cdn.casdoor.com/static/favicon.png" } / >
2023-02-01 22:06:40 +08:00
< / H e l m e t > :
< Helmet >
< title > { this . state . account . organization ? . displayName } < / t i t l e >
< link rel = "icon" href = { this . state . account . organization ? . favicon } / >
2021-04-29 19:51:03 +08:00
< / H e l m e t >
2023-02-01 22:06:40 +08:00
}
2022-12-04 23:05:30 +08:00
< ConfigProvider theme = { {
token : {
2023-02-01 22:06:40 +08:00
colorPrimary : this . state . themeData . colorPrimary ,
colorInfo : this . state . themeData . colorPrimary ,
borderRadius : this . state . themeData . borderRadius ,
2022-12-04 23:05:30 +08:00
} ,
2023-02-01 22:06:40 +08:00
algorithm : Setting . getAlgorithm ( this . state . themeAlgorithm ) ,
2022-12-04 23:05:30 +08:00
} } >
{
this . renderPage ( )
}
< / C o n f i g P r o v i d e r >
2021-04-29 19:51:03 +08:00
< / R e a c t . F r a g m e n t >
2022-07-10 15:45:55 +08:00
) ;
2021-04-29 19:51:03 +08:00
}
2020-10-20 21:46:44 +08:00
}
2022-10-12 13:52:02 +02:00
export default withRouter ( withTranslation ( ) ( App ) ) ;