2022-02-13 23:39:27 +08:00
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
2021-02-13 13:30:51 +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.
2021-02-13 12:15:19 +08:00
import React from "react" ;
2024-02-07 00:00:10 +08:00
import { Button , Card , Checkbox , Col , Input , InputNumber , Radio , Row , Select , Switch } from "antd" ;
2021-05-14 23:45:20 +08:00
import { LinkOutlined } from "@ant-design/icons" ;
2021-02-13 12:15:19 +08:00
import * as ProviderBackend from "./backend/ProviderBackend" ;
2023-09-07 15:45:54 +08:00
import * as OrganizationBackend from "./backend/OrganizationBackend" ;
import * as CertBackend from "./backend/CertBackend" ;
2021-02-13 12:15:19 +08:00
import * as Setting from "./Setting" ;
2021-02-19 23:23:59 +08:00
import i18next from "i18next" ;
2022-07-10 15:45:55 +08:00
import { authConfig } from "./auth/Auth" ;
2023-03-26 18:44:47 +08:00
import * as ProviderEditTestEmail from "./common/TestEmailWidget" ;
2023-08-19 12:33:00 +08:00
import * as ProviderNotification from "./common/TestNotificationWidget" ;
2023-03-26 18:44:47 +08:00
import * as ProviderEditTestSms from "./common/TestSmsWidget" ;
2022-07-10 15:45:55 +08:00
import copy from "copy-to-clipboard" ;
import { CaptchaPreview } from "./common/CaptchaPreview" ;
2023-03-26 18:44:47 +08:00
import { CountryCodeSelect } from "./common/select/CountryCodeSelect" ;
2023-08-13 23:58:57 +08:00
import * as Web3Auth from "./auth/Web3Auth" ;
2021-02-13 12:15:19 +08:00
2023-12-29 23:31:50 +08:00
import { Controlled as CodeMirror } from "react-codemirror2" ;
import "codemirror/lib/codemirror.css" ;
require ( "codemirror/theme/material-darker.css" ) ;
require ( "codemirror/mode/htmlmixed/htmlmixed" ) ;
require ( "codemirror/mode/xml/xml" ) ;
require ( "codemirror/mode/css/css" ) ;
2022-07-10 15:45:55 +08:00
const { Option } = Select ;
const { TextArea } = Input ;
2021-02-14 10:20:42 +08:00
2024-03-18 23:01:17 +08:00
const defaultUserMapping = {
id : "id" ,
username : "username" ,
displayName : "displayName" ,
email : "email" ,
avatarUrl : "avatarUrl" ,
} ;
2021-02-13 12:15:19 +08:00
class ProviderEditPage extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
classes : props ,
providerName : props . match . params . providerName ,
2022-11-04 21:31:08 +08:00
owner : props . organizationName !== undefined ? props . organizationName : props . match . params . organizationName ,
2021-02-13 12:15:19 +08:00
provider : null ,
2023-09-07 15:45:54 +08:00
certs : [ ] ,
2022-11-21 01:17:55 +08:00
organizations : [ ] ,
2022-02-25 18:16:02 +08:00
mode : props . location . mode !== undefined ? props . location . mode : "edit" ,
2021-02-13 12:15:19 +08:00
} ;
}
2021-03-27 11:38:15 +08:00
UNSAFE _componentWillMount ( ) {
2022-11-21 01:17:55 +08:00
this . getOrganizations ( ) ;
2021-02-13 12:15:19 +08:00
this . getProvider ( ) ;
2023-09-07 15:45:54 +08:00
this . getCerts ( this . state . owner ) ;
2021-02-13 12:15:19 +08:00
}
getProvider ( ) {
2022-11-04 21:31:08 +08:00
ProviderBackend . getProvider ( this . state . owner , this . state . providerName )
2023-06-02 11:49:38 +08:00
. then ( ( res ) => {
2023-07-23 09:49:16 +08:00
if ( res . data === null ) {
2023-06-09 21:52:30 +08:00
this . props . history . push ( "/404" ) ;
return ;
}
2023-06-02 11:49:38 +08:00
if ( res . status === "ok" ) {
2023-07-05 20:35:02 +08:00
const provider = res . data ;
2024-03-18 23:01:17 +08:00
provider . userMapping = provider . userMapping || defaultUserMapping ;
2023-06-02 11:49:38 +08:00
this . setState ( {
2023-07-05 20:35:02 +08:00
provider : provider ,
2023-06-02 11:49:38 +08:00
} ) ;
} else {
Setting . showMessage ( "error" , res . msg ) ;
}
2021-02-13 12:15:19 +08:00
} ) ;
}
2022-11-21 01:17:55 +08:00
getOrganizations ( ) {
if ( Setting . isAdminUser ( this . props . account ) ) {
OrganizationBackend . getOrganizations ( "admin" )
. then ( ( res ) => {
this . setState ( {
2023-07-23 09:49:16 +08:00
organizations : res . data || [ ] ,
2022-11-21 01:17:55 +08:00
} ) ;
} ) ;
}
}
2023-09-07 15:45:54 +08:00
getCerts ( owner ) {
CertBackend . getCerts ( owner )
. then ( ( res ) => {
if ( res . status === "ok" ) {
this . setState ( {
certs : res . data || [ ] ,
} ) ;
}
} ) ;
}
2021-02-13 12:15:19 +08:00
parseProviderField ( key , value ) {
2021-05-14 23:45:20 +08:00
if ( [ "port" ] . includes ( key ) ) {
value = Setting . myParseInt ( value ) ;
}
2021-02-13 12:15:19 +08:00
return value ;
}
updateProviderField ( key , value ) {
value = this . parseProviderField ( key , value ) ;
2022-08-08 23:35:24 +08:00
const provider = this . state . provider ;
2023-09-07 15:45:54 +08:00
if ( key === "owner" && provider [ "owner" ] !== value ) {
// the provider change the owner, reset the cert
provider [ "cert" ] = "" ;
this . getCerts ( value ) ;
}
2024-02-07 00:00:10 +08:00
2021-02-13 12:15:19 +08:00
provider [ key ] = value ;
2024-02-07 00:00:10 +08:00
if ( provider [ "type" ] === "WeChat" ) {
if ( ! provider [ "clientId" ] ) {
provider [ "signName" ] = "media" ;
provider [ "disableSsl" ] = true ;
}
if ( ! provider [ "clientId2" ] ) {
provider [ "signName" ] = "open" ;
provider [ "disableSsl" ] = false ;
}
if ( ! provider [ "disableSsl" ] ) {
provider [ "signName" ] = "open" ;
}
}
2021-02-13 12:15:19 +08:00
this . setState ( {
provider : provider ,
} ) ;
}
2023-07-05 20:35:02 +08:00
updateUserMappingField ( key , value ) {
2024-03-18 23:01:17 +08:00
const requiredKeys = [ "id" , "username" , "displayName" ] ;
2023-07-05 20:35:02 +08:00
const provider = this . state . provider ;
2024-03-18 23:01:17 +08:00
if ( value === "" && requiredKeys . includes ( key ) ) {
Setting . showMessage ( "error" , i18next . t ( "provider:This field is required" ) ) ;
return ;
}
2023-07-05 20:35:02 +08:00
provider . userMapping [ key ] = value ;
2024-03-18 23:01:17 +08:00
2023-07-05 20:35:02 +08:00
this . setState ( {
provider : provider ,
} ) ;
}
renderUserMappingInput ( ) {
return (
< React . Fragment >
{ Setting . getLabel ( i18next . t ( "general:ID" ) , i18next . t ( "general:ID - Tooltip" ) ) } :
< Input value = { this . state . provider . userMapping . id } onChange = { e => {
this . updateUserMappingField ( "id" , e . target . value ) ;
} } / >
{ Setting . getLabel ( i18next . t ( "signup:Username" ) , i18next . t ( "signup:Username - Tooltip" ) ) } :
< Input value = { this . state . provider . userMapping . username } onChange = { e => {
this . updateUserMappingField ( "username" , e . target . value ) ;
} } / >
{ Setting . getLabel ( i18next . t ( "general:Display name" ) , i18next . t ( "general:Display name - Tooltip" ) ) } :
< Input value = { this . state . provider . userMapping . displayName } onChange = { e => {
this . updateUserMappingField ( "displayName" , e . target . value ) ;
} } / >
{ Setting . getLabel ( i18next . t ( "general:Email" ) , i18next . t ( "general:Email - Tooltip" ) ) } :
< Input value = { this . state . provider . userMapping . email } onChange = { e => {
this . updateUserMappingField ( "email" , e . target . value ) ;
} } / >
{ Setting . getLabel ( i18next . t ( "general:Avatar" ) , i18next . t ( "general:Avatar - Tooltip" ) ) } :
< Input value = { this . state . provider . userMapping . avatarUrl } onChange = { e => {
this . updateUserMappingField ( "avatarUrl" , e . target . value ) ;
} } / >
< / R e a c t . F r a g m e n t >
) ;
}
2023-02-22 12:27:34 +08:00
getClientIdLabel ( provider ) {
switch ( provider . category ) {
2023-10-31 23:09:49 +08:00
case "OAuth" :
if ( provider . type === "Apple" ) {
return Setting . getLabel ( i18next . t ( "provider:Service ID identifier" ) , i18next . t ( "provider:Service ID identifier - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client ID" ) , i18next . t ( "provider:Client ID - Tooltip" ) ) ;
}
2022-07-10 15:45:55 +08:00
case "Email" :
return Setting . getLabel ( i18next . t ( "signup:Username" ) , i18next . t ( "signup:Username - Tooltip" ) ) ;
case "SMS" :
2023-08-07 00:59:17 +08:00
if ( provider . type === "Volc Engine SMS" || provider . type === "Amazon SNS" || provider . type === "Baidu Cloud SMS" ) {
2022-07-10 15:45:55 +08:00
return Setting . getLabel ( i18next . t ( "provider:Access key" ) , i18next . t ( "provider:Access key - Tooltip" ) ) ;
2023-02-22 12:27:34 +08:00
} else if ( provider . type === "Huawei Cloud SMS" ) {
2022-07-10 15:45:55 +08:00
return Setting . getLabel ( i18next . t ( "provider:App key" ) , i18next . t ( "provider:App key - Tooltip" ) ) ;
2023-08-07 00:59:17 +08:00
} else if ( provider . type === "UCloud SMS" ) {
return Setting . getLabel ( i18next . t ( "provider:Public key" ) , i18next . t ( "provider:Public key - Tooltip" ) ) ;
2024-03-03 22:05:53 +05:00
} else if ( provider . type === "Msg91 SMS" || provider . type === "Infobip SMS" || provider . type === "OSON SMS" ) {
2023-08-07 00:59:17 +08:00
return Setting . getLabel ( i18next . t ( "provider:Sender Id" ) , i18next . t ( "provider:Sender Id - Tooltip" ) ) ;
2022-07-10 15:45:55 +08:00
} else {
2021-08-13 14:36:46 +08:00
return Setting . getLabel ( i18next . t ( "provider:Client ID" ) , i18next . t ( "provider:Client ID - Tooltip" ) ) ;
2022-07-10 15:45:55 +08:00
}
case "Captcha" :
2023-02-22 12:27:34 +08:00
if ( provider . type === "Aliyun Captcha" ) {
2022-07-10 15:45:55 +08:00
return Setting . getLabel ( i18next . t ( "provider:Access key" ) , i18next . t ( "provider:Access key - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Site key" ) , i18next . t ( "provider:Site key - Tooltip" ) ) ;
}
2023-09-24 18:35:58 +08:00
case "Notification" :
if ( provider . type === "DingTalk" ) {
return Setting . getLabel ( i18next . t ( "provider:Access key" ) , i18next . t ( "provider:Access key - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client ID" ) , i18next . t ( "provider:Client ID - Tooltip" ) ) ;
}
2022-07-10 15:45:55 +08:00
default :
return Setting . getLabel ( i18next . t ( "provider:Client ID" ) , i18next . t ( "provider:Client ID - Tooltip" ) ) ;
2021-08-13 14:36:46 +08:00
}
}
2023-02-22 12:27:34 +08:00
getClientSecretLabel ( provider ) {
switch ( provider . category ) {
2023-10-31 23:09:49 +08:00
case "OAuth" :
if ( provider . type === "Apple" ) {
return Setting . getLabel ( i18next . t ( "provider:Team ID" ) , i18next . t ( "provider:Team ID - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client secret" ) , i18next . t ( "provider:Client secret - Tooltip" ) ) ;
}
2023-12-14 00:06:38 +08:00
case "Storage" :
if ( provider . type === "Google Cloud Storage" ) {
return Setting . getLabel ( i18next . t ( "provider:Service account JSON" ) , i18next . t ( "provider:Service account JSON - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client secret" ) , i18next . t ( "provider:Client secret - Tooltip" ) ) ;
}
2022-07-10 15:45:55 +08:00
case "Email" :
2024-04-09 22:16:01 +08:00
if ( provider . type === "Azure ACS" || provider . type === "SendGrid" ) {
2023-09-24 18:35:58 +08:00
return Setting . getLabel ( i18next . t ( "provider:Secret key" ) , i18next . t ( "provider:Secret key - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "general:Password" ) , i18next . t ( "general:Password - Tooltip" ) ) ;
}
2022-07-10 15:45:55 +08:00
case "SMS" :
2024-03-03 22:05:53 +05:00
if ( provider . type === "Volc Engine SMS" || provider . type === "Amazon SNS" || provider . type === "Baidu Cloud SMS" || provider . type === "OSON SMS" ) {
2023-03-18 10:16:35 +08:00
return Setting . getLabel ( i18next . t ( "provider:Secret access key" ) , i18next . t ( "provider:Secret access key - Tooltip" ) ) ;
2023-02-22 12:27:34 +08:00
} else if ( provider . type === "Huawei Cloud SMS" ) {
2022-07-10 15:45:55 +08:00
return Setting . getLabel ( i18next . t ( "provider:App secret" ) , i18next . t ( "provider:AppSecret - Tooltip" ) ) ;
2023-08-07 00:59:17 +08:00
} else if ( provider . type === "UCloud SMS" ) {
return Setting . getLabel ( i18next . t ( "provider:Private Key" ) , i18next . t ( "provider:Private Key - Tooltip" ) ) ;
} else if ( provider . type === "Msg91 SMS" ) {
return Setting . getLabel ( i18next . t ( "provider:Auth Key" ) , i18next . t ( "provider:Auth Key - Tooltip" ) ) ;
} else if ( provider . type === "Infobip SMS" ) {
return Setting . getLabel ( i18next . t ( "provider:Api Key" ) , i18next . t ( "provider:Api Key - Tooltip" ) ) ;
2022-07-10 15:45:55 +08:00
} else {
2021-08-13 14:36:46 +08:00
return Setting . getLabel ( i18next . t ( "provider:Client secret" ) , i18next . t ( "provider:Client secret - Tooltip" ) ) ;
2022-07-10 15:45:55 +08:00
}
case "Captcha" :
2023-02-22 12:27:34 +08:00
if ( provider . type === "Aliyun Captcha" ) {
2023-03-18 10:16:35 +08:00
return Setting . getLabel ( i18next . t ( "provider:Secret access key" ) , i18next . t ( "provider:Secret access key - Tooltip" ) ) ;
2022-07-10 15:45:55 +08:00
} else {
return Setting . getLabel ( i18next . t ( "provider:Secret key" ) , i18next . t ( "provider:Secret key - Tooltip" ) ) ;
}
2023-09-05 17:05:34 +08:00
case "Notification" :
2023-09-24 18:35:58 +08:00
if ( provider . type === "Line" || provider . type === "Telegram" || provider . type === "Bark" || provider . type === "DingTalk" || provider . type === "Discord" || provider . type === "Slack" || provider . type === "Pushover" || provider . type === "Pushbullet" ) {
2023-09-05 17:05:34 +08:00
return Setting . getLabel ( i18next . t ( "provider:Secret key" ) , i18next . t ( "provider:Secret key - Tooltip" ) ) ;
2023-09-24 18:35:58 +08:00
} else if ( provider . type === "Lark" || provider . type === "Microsoft Teams" ) {
return Setting . getLabel ( i18next . t ( "provider:Endpoint" ) , i18next . t ( "provider:Endpoint - Tooltip" ) ) ;
2023-09-05 17:05:34 +08:00
} else {
return Setting . getLabel ( i18next . t ( "provider:Client secret" ) , i18next . t ( "provider:Client secret - Tooltip" ) ) ;
}
2022-07-10 15:45:55 +08:00
default :
return Setting . getLabel ( i18next . t ( "provider:Client secret" ) , i18next . t ( "provider:Client secret - Tooltip" ) ) ;
2021-08-13 14:36:46 +08:00
}
}
2023-05-04 23:41:37 +08:00
getClientId2Label ( provider ) {
switch ( provider . category ) {
2023-10-31 23:09:49 +08:00
case "OAuth" :
if ( provider . type === "Apple" ) {
return Setting . getLabel ( i18next . t ( "provider:Key ID" ) , i18next . t ( "provider:Key ID - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client ID 2" ) , i18next . t ( "provider:Client ID 2 - Tooltip" ) ) ;
}
2023-05-04 23:41:37 +08:00
case "Email" :
return Setting . getLabel ( i18next . t ( "provider:From address" ) , i18next . t ( "provider:From address - Tooltip" ) ) ;
default :
if ( provider . type === "Aliyun Captcha" ) {
return Setting . getLabel ( i18next . t ( "provider:Scene" ) , i18next . t ( "provider:Scene - Tooltip" ) ) ;
} else if ( provider . type === "WeChat Pay" ) {
return Setting . getLabel ( i18next . t ( "provider:App ID" ) , i18next . t ( "provider:App ID - Tooltip" ) ) ;
2025-01-17 08:35:31 +08:00
} else if ( provider . type === "CUCloud" ) {
return Setting . getLabel ( i18next . t ( "provider:Account ID" ) , i18next . t ( "provider:Account ID - Tooltip" ) ) ;
2023-05-04 23:41:37 +08:00
} else {
return Setting . getLabel ( i18next . t ( "provider:Client ID 2" ) , i18next . t ( "provider:Client ID 2 - Tooltip" ) ) ;
}
}
}
getClientSecret2Label ( provider ) {
switch ( provider . category ) {
2023-10-31 23:09:49 +08:00
case "OAuth" :
if ( provider . type === "Apple" ) {
return Setting . getLabel ( i18next . t ( "provider:Key text" ) , i18next . t ( "provider:Key text - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client secret 2" ) , i18next . t ( "provider:Client secret 2 - Tooltip" ) ) ;
}
2023-05-04 23:41:37 +08:00
case "Email" :
return Setting . getLabel ( i18next . t ( "provider:From name" ) , i18next . t ( "provider:From name - Tooltip" ) ) ;
default :
if ( provider . type === "Aliyun Captcha" ) {
return Setting . getLabel ( i18next . t ( "provider:App key" ) , i18next . t ( "provider:App key - Tooltip" ) ) ;
} else {
return Setting . getLabel ( i18next . t ( "provider:Client secret 2" ) , i18next . t ( "provider:Client secret 2 - Tooltip" ) ) ;
}
}
}
2023-03-26 18:44:47 +08:00
getProviderSubTypeOptions ( type ) {
if ( type === "WeCom" || type === "Infoflow" ) {
return (
[
{ id : "Internal" , name : i18next . t ( "provider:Internal" ) } ,
{ id : "Third-party" , name : i18next . t ( "provider:Third-party" ) } ,
]
) ;
} else if ( type === "Aliyun Captcha" ) {
return [
{ id : "nc" , name : i18next . t ( "provider:Sliding Validation" ) } ,
{ id : "ic" , name : i18next . t ( "provider:Intelligent Validation" ) } ,
] ;
} else {
return [ ] ;
}
}
2023-02-22 12:10:55 +08:00
getAppIdRow ( provider ) {
let text = "" ;
let tooltip = "" ;
if ( provider . category === "OAuth" ) {
if ( provider . type === "WeCom" && provider . subType === "Internal" ) {
text = i18next . t ( "provider:Agent ID" ) ;
tooltip = i18next . t ( "provider:Agent ID - Tooltip" ) ;
} else if ( provider . type === "Infoflow" ) {
text = i18next . t ( "provider:Agent ID" ) ;
tooltip = i18next . t ( "provider:Agent ID - Tooltip" ) ;
2023-12-17 02:37:28 +08:00
} else if ( provider . type === "AzureADB2C" ) {
text = i18next . t ( "provider:User flow" ) ;
tooltip = i18next . t ( "provider:User flow - Tooltip" ) ;
2023-02-22 12:10:55 +08:00
}
} else if ( provider . category === "SMS" ) {
2023-08-07 00:59:17 +08:00
if ( provider . type === "Twilio SMS" || provider . type === "Azure ACS" ) {
2023-07-18 22:46:56 +08:00
text = i18next . t ( "provider:Sender number" ) ;
tooltip = i18next . t ( "provider:Sender number - Tooltip" ) ;
} else if ( provider . type === "Tencent Cloud SMS" ) {
2023-02-22 12:10:55 +08:00
text = i18next . t ( "provider:App ID" ) ;
tooltip = i18next . t ( "provider:App ID - Tooltip" ) ;
} else if ( provider . type === "Volc Engine SMS" ) {
text = i18next . t ( "provider:SMS account" ) ;
tooltip = i18next . t ( "provider:SMS account - Tooltip" ) ;
} else if ( provider . type === "Huawei Cloud SMS" ) {
text = i18next . t ( "provider:Channel No." ) ;
tooltip = i18next . t ( "provider:Channel No. - Tooltip" ) ;
2023-08-07 00:59:17 +08:00
} else if ( provider . type === "Amazon SNS" ) {
text = i18next . t ( "provider:Region" ) ;
tooltip = i18next . t ( "provider:Region - Tooltip" ) ;
} else if ( provider . type === "Baidu Cloud SMS" ) {
text = i18next . t ( "provider:Endpoint" ) ;
tooltip = i18next . t ( "provider:Endpoint - Tooltip" ) ;
} else if ( provider . type === "Infobip SMS" ) {
text = i18next . t ( "provider:Base URL" ) ;
tooltip = i18next . t ( "provider:Base URL - Tooltip" ) ;
} else if ( provider . type === "UCloud SMS" ) {
text = i18next . t ( "provider:Project Id" ) ;
tooltip = i18next . t ( "provider:Project Id - Tooltip" ) ;
2023-02-22 12:10:55 +08:00
}
} else if ( provider . category === "Email" ) {
2023-09-24 18:35:58 +08:00
if ( provider . type === "SUBMAIL" ) {
2023-02-22 12:10:55 +08:00
text = i18next . t ( "provider:App ID" ) ;
tooltip = i18next . t ( "provider:App ID - Tooltip" ) ;
}
2023-08-19 12:33:00 +08:00
} else if ( provider . category === "Notification" ) {
2023-09-05 17:05:34 +08:00
if ( provider . type === "Viber" ) {
text = i18next . t ( "provider:Domain" ) ;
tooltip = i18next . t ( "provider:Domain - Tooltip" ) ;
2023-09-24 18:35:58 +08:00
} else if ( provider . type === "Line" || provider . type === "Matrix" || provider . type === "Rocket Chat" ) {
2023-08-20 21:04:30 +08:00
text = i18next . t ( "provider:App Key" ) ;
tooltip = i18next . t ( "provider:App Key - Tooltip" ) ;
2025-01-17 08:35:31 +08:00
} else if ( provider . type === "CUCloud" ) {
text = i18next . t ( "provider:Topic name" ) ;
tooltip = i18next . t ( "provider:Topic name - Tooltip" ) ;
2023-08-19 12:33:00 +08:00
}
2021-08-13 14:36:46 +08:00
}
2023-02-22 12:10:55 +08:00
if ( text === "" && tooltip === "" ) {
return null ;
} else {
return (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( text , tooltip ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { provider . appId } onChange = { e => {
this . updateProviderField ( "appId" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) ;
}
2021-08-13 14:36:46 +08:00
}
2023-08-20 21:04:30 +08:00
getReceiverRow ( provider ) {
let text = "" ;
let tooltip = "" ;
2023-09-05 17:05:34 +08:00
if ( provider . type === "Telegram" || provider . type === "Pushover" || provider . type === "Pushbullet" || provider . type === "Slack" || provider . type === "Discord" || provider . type === "Line" || provider . type === "Twitter" || provider . type === "Reddit" || provider . type === "Rocket Chat" || provider . type === "Viber" ) {
2023-08-20 21:04:30 +08:00
text = i18next . t ( "provider:Chat ID" ) ;
tooltip = i18next . t ( "provider:Chat ID - Tooltip" ) ;
2023-09-24 18:35:58 +08:00
} else if ( provider . type === "Custom HTTP" || provider . type === "Webpush" || provider . type === "Matrix" ) {
2023-08-20 21:04:30 +08:00
text = i18next . t ( "provider:Endpoint" ) ;
tooltip = i18next . t ( "provider:Endpoint - Tooltip" ) ;
}
if ( text === "" && tooltip === "" ) {
2023-09-05 17:05:34 +08:00
return (
< React . Fragment >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( "Test Notification" , "Test Notification" ) } :
< / C o l >
< / R e a c t . F r a g m e n t >
) ;
2023-08-20 21:04:30 +08:00
} else {
return (
< React . Fragment >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( text , tooltip ) } :
< / C o l >
< Col span = { 6 } >
< Input value = { provider . receiver } onChange = { e => {
this . updateProviderField ( "receiver" , e . target . value ) ;
} } / >
< / C o l >
< / R e a c t . F r a g m e n t >
) ;
}
}
2021-12-06 21:46:50 +08:00
loadSamlConfiguration ( ) {
2022-08-08 23:35:24 +08:00
const parser = new DOMParser ( ) ;
2023-10-20 21:11:36 +08:00
const rawXml = this . state . provider . metadata . replace ( "\n" , "" ) ;
const xmlDoc = parser . parseFromString ( rawXml , "text/xml" ) ;
const cert = xmlDoc . querySelector ( "X509Certificate" ) . childNodes [ 0 ] . nodeValue . replace ( " " , "" ) ;
const endpoint = xmlDoc . querySelector ( "SingleSignOnService" ) . getAttribute ( "Location" ) ;
const issuerUrl = xmlDoc . querySelector ( "EntityDescriptor" ) . getAttribute ( "entityID" ) ;
2021-12-06 21:46:50 +08:00
this . updateProviderField ( "idP" , cert ) ;
this . updateProviderField ( "endpoint" , endpoint ) ;
this . updateProviderField ( "issuerUrl" , issuerUrl ) ;
}
2021-02-13 12:15:19 +08:00
renderProvider ( ) {
return (
< Card size = "small" title = {
< div >
2022-02-25 18:16:02 +08:00
{ this . state . mode === "add" ? i18next . t ( "provider:New Provider" ) : i18next . t ( "provider:Edit Provider" ) } & nbsp ; & nbsp ; & nbsp ; & nbsp ;
2021-12-12 18:51:12 +08:00
< Button onClick = { ( ) => this . submitProviderEdit ( false ) } > { i18next . t ( "general:Save" ) } < / B u t t o n >
2022-07-10 15:45:55 +08:00
< Button style = { { marginLeft : "20px" } } type = "primary" onClick = { ( ) => this . submitProviderEdit ( true ) } > { i18next . t ( "general:Save & Exit" ) } < / B u t t o n >
{ this . state . mode === "add" ? < Button style = { { marginLeft : "20px" } } onClick = { ( ) => this . deleteProvider ( ) } > { i18next . t ( "general:Cancel" ) } < / B u t t o n > : n u l l }
2021-02-13 12:15:19 +08:00
< / d i v >
2022-08-06 23:43:09 +08:00
} style = { ( Setting . isMobile ( ) ) ? { margin : "5px" } : { } } type = "inner" >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "10px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Name" ) , i18next . t ( "general:Name - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . name } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "name" , e . target . value ) ;
2021-02-13 12:15:19 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Display name" ) , i18next . t ( "general:Display name - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . displayName } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "displayName" , e . target . value ) ;
2021-02-13 12:15:19 +08:00
} } / >
< / C o l >
< / R o w >
2022-11-21 01:17:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "general:Organization" ) , i18next . t ( "general:Organization - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Select virtual = { false } style = { { width : "100%" } } disabled = { ! Setting . isAdminUser ( this . props . account ) } value = { this . state . provider . owner } onChange = { ( value => { this . updateProviderField ( "owner" , value ) ; } ) } >
2023-03-18 10:16:35 +08:00
{ Setting . isAdminUser ( this . props . account ) ? < Option key = { "admin" } value = { "admin" } > { i18next . t ( "provider:admin (Shared)" ) } < / O p t i o n > : n u l l }
2022-11-21 01:17:55 +08:00
{
this . state . organizations . map ( ( organization , index ) => < Option key = { index } value = { organization . name } > { organization . name } < / O p t i o n > )
}
< / S e l e c t >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Category" ) , i18next . t ( "provider:Category - Tooltip" ) ) } :
2021-05-14 23:45:20 +08:00
< / C o l >
< Col span = { 22 } >
2022-07-10 15:45:55 +08:00
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . category } onChange = { ( value => {
this . updateProviderField ( "category" , value ) ;
2021-05-24 01:27:03 +08:00
if ( value === "OAuth" ) {
2023-08-12 12:52:53 +08:00
this . updateProviderField ( "type" , "Google" ) ;
2021-05-24 01:27:03 +08:00
} else if ( value === "Email" ) {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "type" , "Default" ) ;
2022-09-04 11:21:20 +08:00
this . updateProviderField ( "host" , "smtp.example.com" ) ;
this . updateProviderField ( "port" , 465 ) ;
2022-08-09 23:38:35 +08:00
this . updateProviderField ( "disableSsl" , false ) ;
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "title" , "Casdoor Verification Code" ) ;
2023-12-30 00:47:10 +08:00
this . updateProviderField ( "content" , Setting . getDefaultHtmlEmailContent ( ) ) ;
2022-09-04 11:37:36 +08:00
this . updateProviderField ( "receiver" , this . props . account . email ) ;
2021-05-24 01:27:03 +08:00
} else if ( value === "SMS" ) {
2023-08-12 12:52:53 +08:00
this . updateProviderField ( "type" , "Twilio SMS" ) ;
2021-08-06 21:33:05 +08:00
} else if ( value === "Storage" ) {
2023-08-12 12:52:53 +08:00
this . updateProviderField ( "type" , "AWS S3" ) ;
2021-12-06 21:46:50 +08:00
} else if ( value === "SAML" ) {
2023-08-12 12:52:53 +08:00
this . updateProviderField ( "type" , "Keycloak" ) ;
2022-08-04 19:39:25 +08:00
} else if ( value === "Payment" ) {
2023-05-30 23:25:58 +08:00
this . updateProviderField ( "type" , "PayPal" ) ;
2022-06-18 16:00:31 +08:00
} else if ( value === "Captcha" ) {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "type" , "Default" ) ;
2023-07-20 17:51:36 +08:00
} else if ( value === "Web3" ) {
this . updateProviderField ( "type" , "MetaMask" ) ;
2023-08-19 12:33:00 +08:00
} else if ( value === "Notification" ) {
this . updateProviderField ( "type" , "Telegram" ) ;
2021-05-24 01:27:03 +08:00
}
} ) } >
2021-05-14 23:45:20 +08:00
{
[
2023-04-22 23:18:18 +08:00
{ id : "Captcha" , name : "Captcha" } ,
2022-07-10 15:45:55 +08:00
{ id : "Email" , name : "Email" } ,
2023-08-26 23:39:02 +08:00
{ id : "Notification" , name : "Notification" } ,
2023-04-22 23:18:18 +08:00
{ id : "OAuth" , name : "OAuth" } ,
{ id : "Payment" , name : "Payment" } ,
{ id : "SAML" , name : "SAML" } ,
2022-07-10 15:45:55 +08:00
{ id : "SMS" , name : "SMS" } ,
{ id : "Storage" , name : "Storage" } ,
2023-07-20 17:51:36 +08:00
{ id : "Web3" , name : "Web3" } ,
2022-12-01 15:51:10 +01:00
]
. sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
. map ( ( providerCategory , index ) => < Option key = { index } value = { providerCategory . id } > { providerCategory . name } < / O p t i o n > )
2021-05-14 23:45:20 +08:00
}
< / S e l e c t >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-06-30 00:58:25 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Type" ) , i18next . t ( "provider:Type - Tooltip" ) ) } :
2021-02-13 12:15:19 +08:00
< / C o l >
< Col span = { 22 } >
2023-07-30 17:31:36 +08:00
< Select virtual = { false } style = { { width : "100%" } } showSearch value = { this . state . provider . type } onChange = { ( value => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "type" , value ) ;
2021-08-08 14:18:44 +08:00
if ( value === "Local File System" ) {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "domain" , Setting . getFullServerUrl ( ) ) ;
2023-10-20 21:11:36 +08:00
} else if ( value === "Custom" && this . state . provider . category === "OAuth" ) {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "customAuthUrl" , "https://door.casdoor.com/login/oauth/authorize" ) ;
2023-07-05 20:35:02 +08:00
this . updateProviderField ( "scopes" , "openid profile email" ) ;
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "customTokenUrl" , "https://door.casdoor.com/api/login/oauth/access_token" ) ;
this . updateProviderField ( "customUserInfoUrl" , "https://door.casdoor.com/api/userinfo" ) ;
2023-12-07 16:59:41 +08:00
} else if ( value === "Custom HTTP SMS" ) {
2023-12-14 22:35:25 +08:00
this . updateProviderField ( "endpoint" , "https://example.com/send-custom-http-sms" ) ;
2023-12-07 16:59:41 +08:00
this . updateProviderField ( "method" , "GET" ) ;
this . updateProviderField ( "title" , "code" ) ;
2023-12-14 22:35:25 +08:00
} else if ( value === "Custom HTTP Email" ) {
this . updateProviderField ( "endpoint" , "https://example.com/send-custom-http-email" ) ;
this . updateProviderField ( "method" , "POST" ) ;
2023-08-20 21:04:30 +08:00
} else if ( value === "Custom HTTP" ) {
2023-08-12 12:52:53 +08:00
this . updateProviderField ( "method" , "GET" ) ;
this . updateProviderField ( "title" , "" ) ;
2022-04-16 17:17:45 +08:00
}
2021-08-08 14:18:44 +08:00
} ) } >
2021-02-14 10:20:42 +08:00
{
2022-12-01 15:51:10 +01:00
Setting . getProviderTypeOptions ( this . state . provider . category )
. sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
2023-07-30 17:31:36 +08:00
. map ( ( providerType , index ) => < Option key = { index } value = { providerType . id } >
< img width = { 20 } height = { 20 } style = { { marginBottom : "3px" , marginRight : "10px" } } src = { Setting . getProviderLogoURL ( { category : this . state . provider . category , type : providerType . id } ) } alt = { providerType . id } / >
{ providerType . name }
< / O p t i o n > )
2021-02-14 10:20:42 +08:00
}
< / S e l e c t >
2021-02-13 12:15:19 +08:00
< / C o l >
< / R o w >
2021-12-20 23:36:28 +08:00
{
2022-06-29 11:31:32 +08:00
this . state . provider . type !== "WeCom" && this . state . provider . type !== "Infoflow" && this . state . provider . type !== "Aliyun Captcha" ? null : (
2022-01-28 23:57:54 +08:00
< React . Fragment >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
2022-01-28 23:57:54 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Sub type" ) , i18next . t ( "provider:Sub type - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2022-07-10 15:45:55 +08:00
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . subType } onChange = { value => {
this . updateProviderField ( "subType" , value ) ;
2022-01-28 23:57:54 +08:00
} } >
{
2023-03-26 18:44:47 +08:00
this . getProviderSubTypeOptions ( this . state . provider . type ) . map ( ( providerSubType , index ) => < Option key = { index } value = { providerSubType . id } > { providerSubType . name } < / O p t i o n > )
2022-01-28 23:57:54 +08:00
}
< / S e l e c t >
< / C o l >
< / R o w >
2022-02-05 21:54:38 +08:00
{
2022-08-07 00:06:20 +08:00
this . state . provider . type !== "WeCom" ? null : (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
2023-03-19 01:01:39 +08:00
{ Setting . getLabel ( i18next . t ( "general:Method" ) , i18next . t ( "provider:Method - Tooltip" ) ) } :
2022-02-05 21:54:38 +08:00
< / C o l >
< Col span = { 22 } >
2022-07-10 15:45:55 +08:00
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . method } onChange = { value => {
this . updateProviderField ( "method" , value ) ;
2022-02-05 21:54:38 +08:00
} } >
{
2023-03-26 18:44:47 +08:00
[
{ id : "Normal" , name : i18next . t ( "provider:Normal" ) } ,
{ id : "Silent" , name : i18next . t ( "provider:Silent" ) } ,
2023-04-07 01:10:46 +08:00
] . map ( ( method , index ) => < Option key = { index } value = { method . id } > { method . name } < / O p t i o n > )
2022-02-05 21:54:38 +08:00
}
< / S e l e c t >
< / C o l >
< / R o w > )
}
2022-01-28 23:57:54 +08:00
< / R e a c t . F r a g m e n t >
2021-12-20 23:36:28 +08:00
)
}
2025-01-02 00:00:57 +08:00
{
this . state . provider . category === "OAuth" ? (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Email regex" ) , i18next . t ( "provider:Email regex - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< TextArea rows = { 4 } value = { this . state . provider . emailRegex } onChange = { e => {
this . updateProviderField ( "emailRegex" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) : null
}
2022-04-16 17:17:45 +08:00
{
2023-10-20 21:11:36 +08:00
this . state . provider . type === "Custom" ? (
2022-04-16 17:17:45 +08:00
< React . Fragment >
2023-10-20 21:11:36 +08:00
{
this . state . provider . category === "OAuth" ? (
< Col >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Auth URL" ) , i18next . t ( "provider:Auth URL - Tooltip" ) ) }
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . customAuthUrl } onChange = { e => {
this . updateProviderField ( "customAuthUrl" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Token URL" ) , i18next . t ( "provider:Token URL - Tooltip" ) ) }
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . customTokenUrl } onChange = { e => {
this . updateProviderField ( "customTokenUrl" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Scope" ) , i18next . t ( "provider:Scope - Tooltip" ) ) }
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . scopes } onChange = { e => {
this . updateProviderField ( "scopes" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:UserInfo URL" ) , i18next . t ( "provider:UserInfo URL - Tooltip" ) ) }
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . customUserInfoUrl } onChange = { e => {
this . updateProviderField ( "customUserInfoUrl" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< / C o l >
) : null
}
2023-07-05 20:35:02 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:User mapping" ) , i18next . t ( "provider:User mapping - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
{ this . renderUserMappingInput ( ) }
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "general:Favicon" ) , i18next . t ( "general:Favicon - Tooltip" ) ) } :
2022-04-16 17:17:45 +08:00
< / C o l >
< Col span = { 22 } >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 1 } >
2022-04-16 17:17:45 +08:00
{ Setting . getLabel ( i18next . t ( "general:URL" ) , i18next . t ( "general:URL - Tooltip" ) ) } :
< / C o l >
< Col span = { 23 } >
2022-07-10 15:45:55 +08:00
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . customLogo } onChange = { e => {
this . updateProviderField ( "customLogo" , e . target . value ) ;
2022-04-16 17:17:45 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 1 } >
2022-04-16 17:17:45 +08:00
{ i18next . t ( "general:Preview" ) } :
< / C o l >
< Col span = { 23 } >
< a target = "_blank" rel = "noreferrer" href = { this . state . provider . customLogo } >
2022-07-10 15:45:55 +08:00
< img src = { this . state . provider . customLogo } alt = { this . state . provider . customLogo } height = { 90 } style = { { marginBottom : "20px" } } / >
2022-04-16 17:17:45 +08:00
< / a >
< / C o l >
< / R o w >
< / C o l >
< / R o w >
< / R e a c t . F r a g m e n t >
2023-10-20 21:11:36 +08:00
) : null
2022-04-16 17:17:45 +08:00
}
2022-06-18 16:00:31 +08:00
{
2023-08-12 12:52:53 +08:00
( this . state . provider . category === "Captcha" && this . state . provider . type === "Default" ) ||
( this . state . provider . category === "Web3" ) ||
2023-09-24 18:35:58 +08:00
( this . state . provider . category === "Storage" && this . state . provider . type === "Local File System" ) ||
2023-12-07 16:59:41 +08:00
( this . state . provider . category === "SMS" && this . state . provider . type === "Custom HTTP SMS" ) ||
2024-07-12 15:48:37 +08:00
( this . state . provider . category === "Notification" && ( this . state . provider . type === "Google Chat" || this . state . provider . type === "Custom HTTP" ) || this . state . provider . type === "Balance" ) ? null : (
2023-08-12 12:52:53 +08:00
< React . Fragment >
2023-09-05 17:05:34 +08:00
{
2023-12-14 00:06:38 +08:00
( this . state . provider . category === "Storage" && this . state . provider . type === "Google Cloud Storage" ) ||
2024-04-09 22:16:01 +08:00
( this . state . provider . category === "Email" && ( this . state . provider . type === "Azure ACS" || this . state . provider . type === "SendGrid" ) ) ||
2023-09-24 18:35:58 +08:00
( this . state . provider . category === "Notification" && ( this . state . provider . type === "Line" || this . state . provider . type === "Telegram" || this . state . provider . type === "Bark" || this . state . provider . type === "Discord" || this . state . provider . type === "Slack" || this . state . provider . type === "Pushbullet" || this . state . provider . type === "Pushover" || this . state . provider . type === "Lark" || this . state . provider . type === "Microsoft Teams" ) ) ? null : (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ this . getClientIdLabel ( this . state . provider ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . clientId } onChange = { e => {
this . updateProviderField ( "clientId" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
)
2023-09-05 17:05:34 +08:00
}
2023-08-12 12:52:53 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ this . getClientSecretLabel ( this . state . provider ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . clientSecret } onChange = { e => {
this . updateProviderField ( "clientSecret" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< / R e a c t . F r a g m e n t >
)
2022-06-18 16:00:31 +08:00
}
2021-12-20 23:36:28 +08:00
{
2025-01-17 08:35:31 +08:00
this . state . provider . category !== "Email" && this . state . provider . type !== "WeChat" && this . state . provider . type !== "Apple" && this . state . provider . type !== "Aliyun Captcha" && this . state . provider . type !== "WeChat Pay" && this . state . provider . type !== "Twitter" && this . state . provider . type !== "Reddit" && this . state . provider . type !== "CUCloud" ? null : (
2021-12-20 23:36:28 +08:00
< React . Fragment >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-05-04 23:41:37 +08:00
{ this . getClientId2Label ( this . state . provider ) } :
2021-12-20 23:36:28 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . clientId2 } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "clientId2" , e . target . value ) ;
2021-12-20 23:36:28 +08:00
} } / >
< / C o l >
< / R o w >
2023-04-10 18:04:10 +08:00
{
2025-01-17 08:35:31 +08:00
( this . state . provider . type === "WeChat Pay" || this . state . provider . type === "CUCloud" ) || ( this . state . provider . category === "Email" && ( this . state . provider . type === "Azure ACS" || this . state . provider . type === "SendGrid" ) ) ? null : (
2023-04-10 18:04:10 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-05-04 23:41:37 +08:00
{ this . getClientSecret2Label ( this . state . provider ) } :
2023-04-10 18:04:10 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . clientSecret2 } onChange = { e => {
this . updateProviderField ( "clientSecret2" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
)
}
2021-12-20 23:36:28 +08:00
< / R e a c t . F r a g m e n t >
)
}
2022-11-13 15:05:15 +08:00
{
this . state . provider . type !== "WeChat" ? null : (
2024-02-05 21:38:12 +08:00
< React . Fragment >
2024-02-07 00:00:10 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Use WeChat Media Platform in PC" ) , i18next . t ( "provider:Use WeChat Media Platform in PC - Tooltip" ) ) } :
< / C o l >
< Col span = { 1 } >
< Switch disabled = { ! this . state . provider . clientId } checked = { this . state . provider . disableSsl } onChange = { checked => {
this . updateProviderField ( "disableSsl" , checked ) ;
} } / >
< / C o l >
< / R o w >
2024-02-05 21:38:12 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "token:Access token" ) , i18next . t ( "token:Access token - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2024-02-07 00:00:10 +08:00
< Input value = { this . state . provider . content } disabled = { ! this . state . provider . disableSsl || ! this . state . provider . clientId2 } onChange = { e => {
2024-02-05 21:38:12 +08:00
this . updateProviderField ( "content" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2024-02-07 00:00:10 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Follow-up action" ) , i18next . t ( "provider:Follow-up action - Tooltip" ) ) } :
2024-02-05 21:38:12 +08:00
< / C o l >
2024-02-07 00:00:10 +08:00
< Col >
< Radio . Group value = { this . state . provider . signName }
disabled = { ! this . state . provider . disableSsl || ! this . state . provider . clientId || ! this . state . provider . clientId2 }
buttonStyle = "solid"
onChange = { e => {
this . updateProviderField ( "signName" , e . target . value ) ;
} } >
< Radio . Button value = "open" > { i18next . t ( "provider:Use WeChat Open Platform to login" ) } < / R a d i o . B u t t o n >
< Radio . Button value = "media" > { i18next . t ( "provider:Use WeChat Media Platform to login" ) } < / R a d i o . B u t t o n >
< / R a d i o . G r o u p >
2024-02-05 21:38:12 +08:00
< / C o l >
< / R o w >
< / R e a c t . F r a g m e n t >
2022-11-13 15:05:15 +08:00
)
}
2024-05-23 00:42:36 +08:00
{
this . state . provider . type !== "Google" ? null : (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Get phone number" ) , i18next . t ( "provider:Get phone number - Tooltip" ) ) } :
< / C o l >
< Col span = { 1 } >
< Switch disabled = { ! this . state . provider . clientId } checked = { this . state . provider . disableSsl } onChange = { checked => {
this . updateProviderField ( "disableSsl" , checked ) ;
} } / >
< / C o l >
< / R o w >
)
}
2022-02-20 15:01:48 +08:00
{
2024-08-27 23:54:03 +08:00
this . state . provider . type !== "ADFS" && this . state . provider . type !== "AzureAD" && this . state . provider . type !== "AzureADB2C" && ( this . state . provider . type !== "Casdoor" && this . state . category !== "Storage" ) && this . state . provider . type !== "Okta" ? null : (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Domain" ) , i18next . t ( "provider:Domain - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2023-08-12 12:52:53 +08:00
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . domain } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "domain" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
2022-02-20 15:01:48 +08:00
)
}
2025-01-17 08:35:31 +08:00
{ this . state . provider . category === "Storage" || [ "Custom HTTP SMS" , "Custom HTTP Email" , "CUCloud" ] . includes ( this . state . provider . type ) ? (
2021-07-26 11:39:49 +08:00
< div >
2025-01-17 08:35:31 +08:00
{ [ "Local File System" , "CUCloud" ] . includes ( this . state . provider . type ) ? null : (
2023-07-23 11:48:15 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Endpoint" ) , i18next . t ( "provider:Region endpoint for Internet" ) ) } :
< / C o l >
< Col span = { 22 } >
2023-08-12 12:52:53 +08:00
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . endpoint } onChange = { e => {
2023-07-23 11:48:15 +08:00
this . updateProviderField ( "endpoint" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) }
2025-01-17 08:35:31 +08:00
{ [ "Custom HTTP SMS" , "Local File System" , "MinIO" , "Tencent Cloud COS" , "Google Cloud Storage" , "Qiniu Cloud Kodo" , "Synology" , "Casdoor" , "CUCloud" ] . includes ( this . state . provider . type ) ? null : (
2023-07-23 11:48:15 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Endpoint (Intranet)" ) , i18next . t ( "provider:Region endpoint for Intranet" ) ) } :
< / C o l >
< Col span = { 22 } >
2023-08-12 12:52:53 +08:00
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . intranetEndpoint } onChange = { e => {
2023-07-23 11:48:15 +08:00
this . updateProviderField ( "intranetEndpoint" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) }
2025-01-17 08:35:31 +08:00
{ [ "Custom HTTP SMS" , "Local File System" , "CUCloud" ] . includes ( this . state . provider . type ) ? null : (
2023-07-23 11:48:15 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
2024-08-27 23:54:03 +08:00
{ [ "Casdoor" ] . includes ( this . state . provider . type ) ?
Setting . getLabel ( i18next . t ( "general:Provider" ) , i18next . t ( "provider:Provider - Tooltip" ) )
: Setting . getLabel ( i18next . t ( "provider:Bucket" ) , i18next . t ( "provider:Bucket - Tooltip" ) ) } :
2023-07-23 11:48:15 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . bucket } onChange = { e => {
this . updateProviderField ( "bucket" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) }
2025-01-17 08:35:31 +08:00
{ [ "Custom HTTP SMS" , "CUCloud" ] . includes ( this . state . provider . type ) ? null : (
2023-12-07 16:59:41 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Path prefix" ) , i18next . t ( "provider:Path prefix - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . pathPrefix } onChange = { e => {
this . updateProviderField ( "pathPrefix" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) }
2025-01-17 08:35:31 +08:00
{ [ "Custom HTTP SMS" , "Synology" , "Casdoor" , "CUCloud" ] . includes ( this . state . provider . type ) ? null : (
2023-07-23 14:40:30 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Domain" ) , i18next . t ( "provider:Domain - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2023-08-12 12:52:53 +08:00
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . domain } disabled = { this . state . provider . type === "Local File System" } onChange = { e => {
2023-07-23 14:40:30 +08:00
this . updateProviderField ( "domain" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) }
2024-08-27 23:54:03 +08:00
{ [ "Casdoor" ] . includes ( this . state . provider . type ) ? (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
2024-08-27 23:54:03 +08:00
{ Setting . getLabel ( i18next . t ( "general:Organization" ) , i18next . t ( "general:Organization - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . content } onChange = { e => {
this . updateProviderField ( "content" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) : null }
2025-01-17 08:35:31 +08:00
{ [ "AWS S3" , "Tencent Cloud COS" , "Qiniu Cloud Kodo" , "Casdoor" , "CUCloud OSS" , "MinIO" , "CUCloud" ] . includes ( this . state . provider . type ) ? (
2024-08-27 23:54:03 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ [ "Casdoor" ] . includes ( this . state . provider . type ) ?
Setting . getLabel ( i18next . t ( "general:Application" ) , i18next . t ( "general:Application - Tooltip" ) ) :
Setting . getLabel ( i18next . t ( "provider:Region ID" ) , i18next . t ( "provider:Region ID - Tooltip" ) ) } :
2021-07-26 11:39:49 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . regionId } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "regionId" , e . target . value ) ;
2021-07-26 11:39:49 +08:00
} } / >
< / C o l >
< / R o w >
) : null }
< / d i v >
) : null }
2023-07-18 22:46:56 +08:00
{ this . getAppIdRow ( this . state . provider ) }
2021-05-15 13:43:21 +08:00
{
2023-08-19 12:33:00 +08:00
this . state . provider . category === "Notification" ? (
< React . Fragment >
2023-08-20 21:04:30 +08:00
{ [ "Custom HTTP" ] . includes ( this . state . provider . type ) ? (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "general:Method" ) , i18next . t ( "provider:Method - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . method } onChange = { value => {
this . updateProviderField ( "method" , value ) ;
} } >
{
[
{ id : "GET" , name : "GET" } ,
{ id : "POST" , name : "POST" } ,
] . map ( ( method , index ) => < Option key = { index } value = { method . id } > { method . name } < / O p t i o n > )
}
< / S e l e c t >
< / C o l >
< / R o w >
) : null }
2025-01-17 08:35:31 +08:00
{ [ "Custom HTTP" , "CUCloud" ] . includes ( this . state . provider . type ) ? (
2023-08-20 21:04:30 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Parameter" ) , i18next . t ( "provider:Parameter - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . title } onChange = { e => {
this . updateProviderField ( "title" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) : null }
2025-01-17 08:35:31 +08:00
{ [ "Google Chat" , "CUCloud" ] . includes ( this . state . provider . type ) ? (
2023-09-05 17:05:34 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Metadata" ) , i18next . t ( "provider:Metadata - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< TextArea rows = { 4 } value = { this . state . provider . metadata } onChange = { e => {
this . updateProviderField ( "metadata" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) : null }
2023-08-19 12:33:00 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-08-20 21:04:30 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Content" ) , i18next . t ( "provider:Content - Tooltip" ) ) } :
2023-08-19 12:33:00 +08:00
< / C o l >
< Col span = { 22 } >
< TextArea autoSize = { { minRows : 3 , maxRows : 100 } } value = { this . state . provider . content } onChange = { e => {
this . updateProviderField ( "content" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< Row style = { { marginTop : "20px" } } >
2023-08-20 21:04:30 +08:00
{ this . getReceiverRow ( this . state . provider ) }
2023-08-19 12:33:00 +08:00
< Button style = { { marginLeft : "10px" , marginBottom : "5px" } } type = "primary"
onClick = { ( ) => ProviderNotification . sendTestNotification ( this . state . provider , this . state . provider . receiver ) } >
{ i18next . t ( "provider:Send Testing Notification" ) }
< / B u t t o n >
< / R o w >
< / R e a c t . F r a g m e n t >
) : this . state . provider . category === "Email" ? (
2021-05-15 13:43:21 +08:00
< React . Fragment >
2024-04-09 22:16:01 +08:00
{ [ "SendGrid" ] . includes ( this . state . provider . type ) ? null : (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Host" ) , i18next . t ( "provider:Host - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . host } onChange = { e => {
this . updateProviderField ( "host" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
) }
{ [ "Azure ACS" , "SendGrid" ] . includes ( this . state . provider . type ) ? null : (
2023-09-12 02:13:37 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Port" ) , i18next . t ( "provider:Port - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< InputNumber value = { this . state . provider . port } onChange = { value => {
this . updateProviderField ( "port" , value ) ;
} } / >
< / C o l >
< / R o w >
) }
2024-04-09 22:16:01 +08:00
{ [ "Azure ACS" , "SendGrid" ] . includes ( this . state . provider . type ) ? null : (
2023-09-12 02:13:37 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Disable SSL" ) , i18next . t ( "provider:Disable SSL - Tooltip" ) ) } :
< / C o l >
< Col span = { 1 } >
< Switch checked = { this . state . provider . disableSsl } onChange = { checked => {
this . updateProviderField ( "disableSsl" , checked ) ;
} } / >
< / C o l >
< / R o w >
) }
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-03-03 23:49:56 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Email title" ) , i18next . t ( "provider:Email title - Tooltip" ) ) } :
2021-05-24 20:21:41 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . title } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "title" , e . target . value ) ;
2021-05-24 20:21:41 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-03-03 23:49:56 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Email content" ) , i18next . t ( "provider:Email content - Tooltip" ) ) } :
2021-05-24 20:21:41 +08:00
< / C o l >
< Col span = { 22 } >
2023-12-29 23:31:50 +08:00
< Row style = { { marginTop : "20px" } } >
2023-12-30 00:47:10 +08:00
< Button style = { { marginLeft : "10px" , marginBottom : "5px" } } onClick = { ( ) => this . updateProviderField ( "content" , "You have requested a verification code at Casdoor. Here is your code: %s, please enter in 5 minutes." ) } >
{ i18next . t ( "provider:Reset to Default Text" ) }
< / B u t t o n >
< Button style = { { marginLeft : "10px" , marginBottom : "5px" } } type = "primary" onClick = { ( ) => this . updateProviderField ( "content" , Setting . getDefaultHtmlEmailContent ( ) ) } >
{ i18next . t ( "provider:Reset to Default HTML" ) }
2023-12-29 23:31:50 +08:00
< / B u t t o n >
< / R o w >
< Row >
< Col span = { Setting . isMobile ( ) ? 22 : 11 } >
< div style = { { height : "300px" , margin : "10px" } } >
< CodeMirror
value = { this . state . provider . content }
options = { { mode : "htmlmixed" , theme : "material-darker" } }
onBeforeChange = { ( editor , data , value ) => {
this . updateProviderField ( "content" , value ) ;
} }
/ >
< / d i v >
< / C o l >
< Col span = { 1 } / >
< Col span = { Setting . isMobile ( ) ? 22 : 11 } >
< div style = { { margin : "10px" } } >
2023-12-30 00:47:10 +08:00
< div dangerouslySetInnerHTML = { { _ _html : this . state . provider . content . replace ( "%s" , "123456" ) . replace ( "%{user.friendlyName}" , Setting . getFriendlyUserName ( this . props . account ) ) } } / >
2023-12-29 23:31:50 +08:00
< / d i v >
< / C o l >
< / R o w >
2021-05-24 20:21:41 +08:00
< / C o l >
< / R o w >
2023-12-29 23:31:50 +08:00
< Row style = { { marginTop : "20px" } } >
2022-07-10 15:45:55 +08:00
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-24 01:47:10 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Test Email" ) , i18next . t ( "provider:Test Email - Tooltip" ) ) } :
< / C o l >
2023-12-29 23:31:50 +08:00
< Col span = { 4 } >
< Input value = { this . state . provider . receiver } placeholder = { i18next . t ( "user:Input your email" ) }
onChange = { e => {
this . updateProviderField ( "receiver" , e . target . value ) ;
} } / >
2022-06-24 01:47:10 +08:00
< / C o l >
2024-04-09 22:16:01 +08:00
{ [ "Azure ACS" , "SendGrid" ] . includes ( this . state . provider . type ) ? null : (
2023-12-30 00:47:10 +08:00
< Button style = { { marginLeft : "10px" , marginBottom : "5px" } } onClick = { ( ) => ProviderEditTestEmail . connectSmtpServer ( this . state . provider ) } >
2023-09-12 02:13:37 +08:00
{ i18next . t ( "provider:Test SMTP Connection" ) }
< / B u t t o n >
) }
2022-07-10 15:45:55 +08:00
< Button style = { { marginLeft : "10px" , marginBottom : "5px" } } type = "primary"
2022-09-04 11:37:36 +08:00
disabled = { ! Setting . isValidEmail ( this . state . provider . receiver ) }
onClick = { ( ) => ProviderEditTestEmail . sendTestEmail ( this . state . provider , this . state . provider . receiver ) } >
2023-03-03 23:49:56 +08:00
{ i18next . t ( "provider:Send Testing Email" ) }
2022-06-24 01:47:10 +08:00
< / B u t t o n >
< / R o w >
2021-05-15 13:43:21 +08:00
< / R e a c t . F r a g m e n t >
2021-05-23 23:38:38 +08:00
) : this . state . provider . category === "SMS" ? (
2021-05-15 13:43:21 +08:00
< React . Fragment >
2024-05-28 20:33:55 +08:00
{ [ "Custom HTTP SMS" , "Twilio SMS" , "Amazon SNS" , "Azure ACS" , "Msg91 SMS" , "Infobip SMS" ] . includes ( this . state . provider . type ) ?
2022-09-25 17:58:12 +08:00
null :
( < Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Sign Name" ) , i18next . t ( "provider:Sign Name - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . signName } onChange = { e => {
this . updateProviderField ( "signName" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
)
}
2024-02-01 12:50:22 +03:00
{ [ "Infobip SMS" ] . includes ( this . state . provider . type ) ?
2023-08-07 00:59:17 +08:00
null :
( < Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Template code" ) , i18next . t ( "provider:Template code - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . templateCode } onChange = { e => {
this . updateProviderField ( "templateCode" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
)
}
2023-12-07 16:59:41 +08:00
{
2023-12-14 22:35:25 +08:00
! [ "Custom HTTP SMS" , "Custom HTTP Email" ] . includes ( this . state . provider . type ) ? null : (
2023-12-07 16:59:41 +08:00
< React . Fragment >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { 2 } >
{ Setting . getLabel ( i18next . t ( "general:Method" ) , i18next . t ( "provider:Method - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . method } onChange = { value => {
this . updateProviderField ( "method" , value ) ;
} } >
{
[
{ id : "GET" , name : "GET" } ,
{ id : "POST" , name : "POST" } ,
] . map ( ( method , index ) => < Option key = { index } value = { method . id } > { method . name } < / O p t i o n > )
}
< / S e l e c t >
< / C o l >
< / R o w >
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Parameter" ) , i18next . t ( "provider:Parameter - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . title } onChange = { e => {
this . updateProviderField ( "title" , e . target . value ) ;
} } / >
< / C o l >
< / R o w >
< / R e a c t . F r a g m e n t >
)
}
2023-03-03 22:15:02 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:SMS Test" ) , i18next . t ( "provider:SMS Test - Tooltip" ) ) } :
< / C o l >
2023-08-20 21:04:30 +08:00
< Col span = { 4 } >
< Input . Group compact >
< CountryCodeSelect
2023-09-09 02:38:15 +08:00
style = { { width : "90px" } }
initValue = { this . state . provider . content }
2023-08-20 21:04:30 +08:00
onChange = { ( value ) => {
this . updateProviderField ( "content" , value ) ;
} }
countryCodes = { this . props . account . organization . countryCodes }
/ >
< Input value = { this . state . provider . receiver }
2023-09-09 02:38:15 +08:00
style = { { width : "150px" } }
2023-08-20 21:04:30 +08:00
placeholder = { i18next . t ( "user:Input your phone number" ) }
onChange = { e => {
this . updateProviderField ( "receiver" , e . target . value ) ;
} } / >
< / I n p u t . G r o u p >
< / C o l >
2023-03-03 22:15:02 +08:00
< Col span = { 2 } >
< Button style = { { marginLeft : "10px" , marginBottom : "5px" } } type = "primary"
2023-12-07 16:59:41 +08:00
disabled = { ! Setting . isValidPhone ( this . state . provider . receiver ) && ( this . state . provider . type !== "Custom HTTP SMS" || this . state . provider . endpoint === "" ) }
2023-03-03 22:15:02 +08:00
onClick = { ( ) => ProviderEditTestSms . sendTestSms ( this . state . provider , "+" + Setting . getCountryCode ( this . state . provider . content ) + this . state . provider . receiver ) } >
2023-03-03 23:49:56 +08:00
{ i18next . t ( "provider:Send Testing SMS" ) }
2023-03-03 22:15:02 +08:00
< / B u t t o n >
< / C o l >
< / R o w >
2021-05-15 13:43:21 +08:00
< / R e a c t . F r a g m e n t >
2021-12-06 21:46:50 +08:00
) : this . state . provider . category === "SAML" ? (
< React . Fragment >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-12-15 21:38:00 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Sign request" ) , i18next . t ( "provider:Sign request - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Switch checked = { this . state . provider . enableSignAuthnRequest } onChange = { checked => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "enableSignAuthnRequest" , checked ) ;
2021-12-15 21:38:00 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-12-06 21:46:50 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Metadata" ) , i18next . t ( "provider:Metadata - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< TextArea rows = { 4 } value = { this . state . provider . metadata } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "metadata" , e . target . value ) ;
2021-12-06 21:46:50 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
2022-09-25 17:58:12 +08:00
< Col style = { { marginTop : "5px" } } span = { 2 } / >
2021-12-06 21:46:50 +08:00
< Col span = { 2 } >
< Button type = "primary" onClick = { ( ) => {
2022-07-10 15:45:55 +08:00
try {
this . loadSamlConfiguration ( ) ;
2023-03-18 10:16:35 +08:00
Setting . showMessage ( "success" , i18next . t ( "provider:Parse metadata successfully" ) ) ;
2022-07-10 15:45:55 +08:00
} catch ( err ) {
2023-03-18 10:16:35 +08:00
Setting . showMessage ( "error" , i18next . t ( "provider:Can not parse metadata" ) ) ;
2022-07-10 15:45:55 +08:00
}
} } >
2021-12-06 21:46:50 +08:00
{ i18next . t ( "provider:Parse" ) }
< / B u t t o n >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-12-06 21:46:50 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Endpoint" ) , i18next . t ( "provider:SAML 2.0 Endpoint (HTTP)" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . endpoint } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "endpoint" , e . target . value ) ;
2021-12-06 21:46:50 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-07-23 09:40:51 +08:00
{ Setting . getLabel ( i18next . t ( "provider:IdP" ) , i18next . t ( "provider:IdP certificate" ) ) } :
2021-12-06 21:46:50 +08:00
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . idP } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "idP" , e . target . value ) ;
2021-12-06 21:46:50 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-12-06 21:46:50 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Issuer URL" ) , i18next . t ( "provider:Issuer URL - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Input value = { this . state . provider . issuerUrl } onChange = { e => {
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "issuerUrl" , e . target . value ) ;
2021-12-06 21:46:50 +08:00
} } / >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-12-06 21:46:50 +08:00
{ Setting . getLabel ( i18next . t ( "provider:SP ACS URL" ) , i18next . t ( "provider:SP ACS URL - Tooltip" ) ) } :
< / C o l >
< Col span = { 21 } >
< Input value = { ` ${ authConfig . serverUrl } /api/acs ` } readOnly = "readonly" / >
< / C o l >
< Col span = { 1 } >
< Button type = "primary" onClick = { ( ) => {
copy ( ` ${ authConfig . serverUrl } /api/acs ` ) ;
2023-12-22 00:25:46 +08:00
Setting . showMessage ( "success" , i18next . t ( "general:Copied to clipboard successfully" ) ) ;
2021-12-06 21:46:50 +08:00
} } >
{ i18next . t ( "provider:Copy" ) }
< / B u t t o n >
< / C o l >
< / R o w >
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2021-12-06 21:46:50 +08:00
{ Setting . getLabel ( i18next . t ( "provider:SP Entity ID" ) , i18next . t ( "provider:SP ACS URL - Tooltip" ) ) } :
< / C o l >
< Col span = { 21 } >
< Input value = { ` ${ authConfig . serverUrl } /api/acs ` } readOnly = "readonly" / >
< / C o l >
< Col span = { 1 } >
< Button type = "primary" onClick = { ( ) => {
copy ( ` ${ authConfig . serverUrl } /api/acs ` ) ;
2023-12-22 00:25:46 +08:00
Setting . showMessage ( "success" , i18next . t ( "general:Copied to clipboard successfully" ) ) ;
2021-12-06 21:46:50 +08:00
} } >
{ i18next . t ( "provider:Copy" ) }
< / B u t t o n >
< / C o l >
< / R o w >
< / R e a c t . F r a g m e n t >
2021-05-15 13:43:21 +08:00
) : null
}
2023-04-19 22:13:13 +08:00
{
2024-08-27 23:54:03 +08:00
( this . state . provider . type === "Alipay" || this . state . provider . type === "WeChat Pay" || this . state . provider . type === "Casdoor" ) ? (
2023-04-19 22:13:13 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-05-26 21:26:41 +08:00
{ Setting . getLabel ( i18next . t ( "general:Cert" ) , i18next . t ( "general:Cert - Tooltip" ) ) } :
2023-04-19 22:13:13 +08:00
< / C o l >
< Col span = { 22 } >
2023-09-07 15:45:54 +08:00
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . cert } onChange = { ( value => { this . updateProviderField ( "cert" , value ) ; } ) } >
{
this . state . certs . map ( ( cert , index ) => < Option key = { index } value = { cert . name } > { cert . name } < / O p t i o n > )
}
< / S e l e c t >
2023-04-19 22:13:13 +08:00
< / C o l >
< / R o w >
) : null
}
2023-09-13 17:30:51 +08:00
{
( this . state . provider . type === "Alipay" ) ? (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2023-12-20 10:09:00 +08:00
{ Setting . getLabel ( i18next . t ( "general:Root cert" ) , i18next . t ( "general:Root cert - Tooltip" ) ) } :
2023-09-13 17:30:51 +08:00
< / C o l >
< Col span = { 22 } >
< Select virtual = { false } style = { { width : "100%" } } value = { this . state . provider . metadata } onChange = { ( value => { this . updateProviderField ( "metadata" , value ) ; } ) } >
{
this . state . certs . map ( ( cert , index ) => < Option key = { index } value = { cert . name } > { cert . name } < / O p t i o n > )
}
< / S e l e c t >
< / C o l >
< / R o w >
) : null
}
2023-08-13 23:58:57 +08:00
{
this . state . provider . type === "Web3Onboard" ? (
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
{ Setting . getLabel ( i18next . t ( "provider:Wallets" ) , i18next . t ( "provider:Wallets - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< Checkbox . Group
options = { Web3Auth . getWeb3OnboardWalletsOptions ( ) }
value = { ( ) => {
try {
return JSON . parse ( this . state . provider . metadata ) ;
} catch {
return [ "injected" ] ;
}
} }
onChange = { options => {
this . updateProviderField ( "metadata" , JSON . stringify ( options ) ) ;
} }
/ >
< / C o l >
< / R o w >
) : null
}
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-22 21:54:25 +08:00
{ Setting . getLabel ( i18next . t ( "provider:Provider URL" ) , i18next . t ( "provider:Provider URL - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
2022-07-10 15:45:55 +08:00
< Input prefix = { < LinkOutlined / > } value = { this . state . provider . providerUrl } onChange = { e => {
this . updateProviderField ( "providerUrl" , e . target . value ) ;
2022-06-22 21:54:25 +08:00
} } / >
< / C o l >
< / R o w >
2022-06-18 16:00:31 +08:00
{
2022-06-22 21:54:25 +08:00
this . state . provider . category !== "Captcha" ? null : (
2022-07-10 15:45:55 +08:00
< Row style = { { marginTop : "20px" } } >
< Col style = { { marginTop : "5px" } } span = { ( Setting . isMobile ( ) ) ? 22 : 2 } >
2022-06-22 21:54:25 +08:00
{ Setting . getLabel ( i18next . t ( "general:Preview" ) , i18next . t ( "general:Preview - Tooltip" ) ) } :
< / C o l >
< Col span = { 22 } >
< CaptchaPreview
2023-03-05 20:31:46 +08:00
owner = { this . state . provider . owner }
name = { this . state . provider . name }
2022-06-22 21:54:25 +08:00
provider = { this . state . provider }
providerName = { this . state . providerName }
captchaType = { this . state . provider . type }
2022-06-29 11:31:32 +08:00
subType = { this . state . provider . subType }
2022-06-22 21:54:25 +08:00
clientId = { this . state . provider . clientId }
2023-03-05 20:31:46 +08:00
clientSecret = { this . state . provider . clientSecret }
2022-06-29 11:31:32 +08:00
clientId2 = { this . state . provider . clientId2 }
clientSecret2 = { this . state . provider . clientSecret2 }
2023-03-05 20:31:46 +08:00
providerUrl = { this . state . provider . providerUrl }
2022-06-22 21:54:25 +08:00
/ >
< / C o l >
< / R o w >
)
2022-06-18 16:00:31 +08:00
}
2021-02-13 12:15:19 +08:00
< / C a r d >
2022-07-10 15:45:55 +08:00
) ;
2021-02-13 12:15:19 +08:00
}
2023-10-10 21:47:38 +08:00
submitProviderEdit ( exitAfterSave ) {
2022-08-08 23:35:24 +08:00
const provider = Setting . deepCopy ( this . state . provider ) ;
2022-11-21 01:17:55 +08:00
ProviderBackend . updateProvider ( this . state . owner , this . state . providerName , provider )
2021-02-13 12:15:19 +08:00
. then ( ( res ) => {
2022-11-29 20:32:47 +08:00
if ( res . status === "ok" ) {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "success" , i18next . t ( "general:Successfully saved" ) ) ;
2021-02-13 12:15:19 +08:00
this . setState ( {
2022-11-21 01:17:55 +08:00
owner : this . state . provider . owner ,
2021-02-13 12:15:19 +08:00
providerName : this . state . provider . name ,
} ) ;
2021-12-12 18:51:12 +08:00
2023-10-10 21:47:38 +08:00
if ( exitAfterSave ) {
2022-07-10 15:45:55 +08:00
this . props . history . push ( "/providers" ) ;
2021-12-12 18:51:12 +08:00
} else {
2022-11-21 01:17:55 +08:00
this . props . history . push ( ` /providers/ ${ this . state . provider . owner } / ${ this . state . provider . name } ` ) ;
2021-12-12 18:51:12 +08:00
}
2021-02-13 12:15:19 +08:00
} else {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to save" ) } : ${ res . msg } ` ) ;
2022-07-10 15:45:55 +08:00
this . updateProviderField ( "name" , this . state . providerName ) ;
2021-02-13 12:15:19 +08:00
}
} )
. catch ( error => {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to connect to server" ) } : ${ error } ` ) ;
2021-02-13 12:15:19 +08:00
} ) ;
}
2022-02-25 18:16:02 +08:00
deleteProvider ( ) {
ProviderBackend . deleteProvider ( this . state . provider )
2022-12-02 00:06:28 +08:00
. then ( ( res ) => {
if ( res . status === "ok" ) {
this . props . history . push ( "/providers" ) ;
} else {
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to delete" ) } : ${ res . msg } ` ) ;
}
2022-02-25 18:16:02 +08:00
} )
. catch ( error => {
2022-12-02 00:06:28 +08:00
Setting . showMessage ( "error" , ` ${ i18next . t ( "general:Failed to connect to server" ) } : ${ error } ` ) ;
2022-02-25 18:16:02 +08:00
} ) ;
}
2021-02-13 12:15:19 +08:00
render ( ) {
return (
< div >
2021-07-23 09:46:01 +08:00
{
this . state . provider !== null ? this . renderProvider ( ) : null
}
2022-07-10 15:45:55 +08:00
< div style = { { marginTop : "20px" , marginLeft : "40px" } } >
2021-12-12 18:51:12 +08:00
< Button size = "large" onClick = { ( ) => this . submitProviderEdit ( false ) } > { i18next . t ( "general:Save" ) } < / B u t t o n >
2022-07-10 15:45:55 +08:00
< Button style = { { marginLeft : "20px" } } type = "primary" size = "large" onClick = { ( ) => this . submitProviderEdit ( true ) } > { i18next . t ( "general:Save & Exit" ) } < / B u t t o n >
{ this . state . mode === "add" ? < Button style = { { marginLeft : "20px" } } size = "large" onClick = { ( ) => this . deleteProvider ( ) } > { i18next . t ( "general:Cancel" ) } < / B u t t o n > : n u l l }
2021-07-23 09:46:01 +08:00
< / d i v >
2021-02-13 12:15:19 +08:00
< / d i v >
) ;
}
}
export default ProviderEditPage ;