mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
fix: Adjust custom http to notification provider (#2237)
* feat: Adjust custom http to notification provider * fix go linter * update ProviderEditPage * update ProviderEditPage
This commit is contained in:
parent
f0e097e138
commit
c54b54ca19
@ -12,37 +12,35 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package object
|
package notification
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/proxy"
|
"github.com/casdoor/casdoor/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HttpSmsClient struct {
|
type HttpNotificationClient struct {
|
||||||
endpoint string
|
endpoint string
|
||||||
method string
|
method string
|
||||||
paramName string
|
paramName string
|
||||||
text string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHttpSmsClient(endpoint string, method string, paramName string, text string) (*HttpSmsClient, error) {
|
func NewCustomHttpProvider(endpoint string, method string, paramName string) (*HttpNotificationClient, error) {
|
||||||
client := &HttpSmsClient{
|
client := &HttpNotificationClient{
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
method: method,
|
method: method,
|
||||||
paramName: paramName,
|
paramName: paramName,
|
||||||
text: text,
|
|
||||||
}
|
}
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpSmsClient) SendMessage(param map[string]string, targetPhoneNumber ...string) error {
|
func (c *HttpNotificationClient) Send(ctx context.Context, subject string, content string) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
content := param["code"]
|
|
||||||
httpClient := proxy.DefaultHttpClient
|
httpClient := proxy.DefaultHttpClient
|
||||||
|
|
||||||
req, err := http.NewRequest(c.method, c.endpoint, bytes.NewBufferString(content))
|
req, err := http.NewRequest(c.method, c.endpoint, bytes.NewBufferString(content))
|
||||||
@ -68,7 +66,7 @@ func (c *HttpSmsClient) SendMessage(param map[string]string, targetPhoneNumber .
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return fmt.Errorf("SendMessage() error, custom HTTP SMS request failed with status: %s", resp.Status)
|
return fmt.Errorf("SendMessage() error, custom HTTP Notification request failed with status: %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
@ -16,9 +16,11 @@ package notification
|
|||||||
|
|
||||||
import "github.com/nikoksr/notify"
|
import "github.com/nikoksr/notify"
|
||||||
|
|
||||||
func GetNotificationProvider(typ string, appId string, receiver string) (notify.Notifier, error) {
|
func GetNotificationProvider(typ string, appId string, receiver string, method string, title string) (notify.Notifier, error) {
|
||||||
if typ == "Telegram" {
|
if typ == "Telegram" {
|
||||||
return NewTelegramProvider(appId, receiver)
|
return NewTelegramProvider(appId, receiver)
|
||||||
|
} else if typ == "Custom HTTP" {
|
||||||
|
return NewCustomHttpProvider(receiver, method, title)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
|
|
||||||
func getNotificationClient(provider *Provider) (notify.Notifier, error) {
|
func getNotificationClient(provider *Provider) (notify.Notifier, error) {
|
||||||
var client notify.Notifier
|
var client notify.Notifier
|
||||||
client, err := notification.GetNotificationProvider(provider.Type, provider.AppId, provider.Receiver)
|
client, err := notification.GetNotificationProvider(provider.Type, provider.AppId, provider.Receiver, provider.Method, provider.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,6 @@ func getSmsClient(provider *Provider) (sender.SmsClient, error) {
|
|||||||
|
|
||||||
if provider.Type == sender.HuaweiCloud || provider.Type == sender.AzureACS {
|
if provider.Type == sender.HuaweiCloud || provider.Type == sender.AzureACS {
|
||||||
client, err = sender.NewSmsClient(provider.Type, provider.ClientId, provider.ClientSecret, provider.SignName, provider.TemplateCode, provider.ProviderUrl, provider.AppId)
|
client, err = sender.NewSmsClient(provider.Type, provider.ClientId, provider.ClientSecret, provider.SignName, provider.TemplateCode, provider.ProviderUrl, provider.AppId)
|
||||||
} else if provider.Type == "Custom HTTP SMS" {
|
|
||||||
client, err = newHttpSmsClient(provider.Endpoint, provider.Method, provider.ClientId, provider.Title)
|
|
||||||
} else {
|
} else {
|
||||||
client, err = sender.NewSmsClient(provider.Type, provider.ClientId, provider.ClientSecret, provider.SignName, provider.TemplateCode, provider.AppId)
|
client, err = sender.NewSmsClient(provider.Type, provider.ClientId, provider.ClientSecret, provider.SignName, provider.TemplateCode, provider.AppId)
|
||||||
}
|
}
|
||||||
|
@ -278,8 +278,8 @@ class ProviderEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
} else if (provider.category === "Notification") {
|
} else if (provider.category === "Notification") {
|
||||||
if (provider.type === "Telegram") {
|
if (provider.type === "Telegram") {
|
||||||
text = i18next.t("provider:Api Token");
|
text = i18next.t("provider:App Key");
|
||||||
tooltip = i18next.t("provider:Api Token - Tooltip");
|
tooltip = i18next.t("provider:App Key - Tooltip");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +301,36 @@ class ProviderEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getReceiverRow(provider) {
|
||||||
|
let text = "";
|
||||||
|
let tooltip = "";
|
||||||
|
|
||||||
|
if (provider.type === "Telegram") {
|
||||||
|
text = i18next.t("provider:Chat ID");
|
||||||
|
tooltip = i18next.t("provider:Chat ID - Tooltip");
|
||||||
|
} else if (provider.type === "Custom HTTP") {
|
||||||
|
text = i18next.t("provider:Endpoint");
|
||||||
|
tooltip = i18next.t("provider:Endpoint - Tooltip");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text === "" && tooltip === "") {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
|
{Setting.getLabel(text, tooltip)} :
|
||||||
|
</Col>
|
||||||
|
<Col span={6} >
|
||||||
|
<Input value={provider.receiver} onChange={e => {
|
||||||
|
this.updateProviderField("receiver", e.target.value);
|
||||||
|
}} />
|
||||||
|
</Col>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadSamlConfiguration() {
|
loadSamlConfiguration() {
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const xmlDoc = parser.parseFromString(this.state.provider.metadata, "text/xml");
|
const xmlDoc = parser.parseFromString(this.state.provider.metadata, "text/xml");
|
||||||
@ -421,10 +451,8 @@ class ProviderEditPage extends React.Component {
|
|||||||
this.updateProviderField("scopes", "openid profile email");
|
this.updateProviderField("scopes", "openid profile email");
|
||||||
this.updateProviderField("customTokenUrl", "https://door.casdoor.com/api/login/oauth/access_token");
|
this.updateProviderField("customTokenUrl", "https://door.casdoor.com/api/login/oauth/access_token");
|
||||||
this.updateProviderField("customUserInfoUrl", "https://door.casdoor.com/api/userinfo");
|
this.updateProviderField("customUserInfoUrl", "https://door.casdoor.com/api/userinfo");
|
||||||
} else if (value === "Custom HTTP SMS") {
|
} else if (value === "Custom HTTP") {
|
||||||
this.updateProviderField("endpoint", "https://door.casdoor.com/api/get-account");
|
|
||||||
this.updateProviderField("method", "GET");
|
this.updateProviderField("method", "GET");
|
||||||
this.updateProviderField("clientId", "param1");
|
|
||||||
this.updateProviderField("title", "");
|
this.updateProviderField("title", "");
|
||||||
}
|
}
|
||||||
})}>
|
})}>
|
||||||
@ -562,7 +590,6 @@ class ProviderEditPage extends React.Component {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
(this.state.provider.category === "Captcha" && this.state.provider.type === "Default") ||
|
(this.state.provider.category === "Captcha" && this.state.provider.type === "Default") ||
|
||||||
(this.state.provider.category === "SMS" && this.state.provider.type === "Custom HTTP SMS") ||
|
|
||||||
(this.state.provider.category === "Web3") ||
|
(this.state.provider.category === "Web3") ||
|
||||||
(this.state.provider.category === "Storage" && this.state.provider.type === "Local File System" || (this.state.provider.category === "Notification")) ? null : (
|
(this.state.provider.category === "Storage" && this.state.provider.type === "Local File System" || (this.state.provider.category === "Notification")) ? null : (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
@ -647,7 +674,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
</Row>
|
</Row>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
{this.state.provider.category === "Storage" || this.state.provider.type === "Custom HTTP SMS" ? (
|
{this.state.provider.category === "Storage" ? (
|
||||||
<div>
|
<div>
|
||||||
{["Local File System"].includes(this.state.provider.type) ? null : (
|
{["Local File System"].includes(this.state.provider.type) ? null : (
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
@ -661,7 +688,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
{["Custom HTTP SMS", "Local File System", "MinIO", "Tencent Cloud COS", "Google Cloud Storage", "Qiniu Cloud Kodo"].includes(this.state.provider.type) ? null : (
|
{["Local File System", "MinIO", "Tencent Cloud COS", "Google Cloud Storage", "Qiniu Cloud Kodo"].includes(this.state.provider.type) ? null : (
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={2}>
|
<Col style={{marginTop: "5px"}} span={2}>
|
||||||
{Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} :
|
{Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} :
|
||||||
@ -673,7 +700,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
{["Custom HTTP SMS", "Local File System"].includes(this.state.provider.type) ? null : (
|
{["Local File System"].includes(this.state.provider.type) ? null : (
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={2}>
|
<Col style={{marginTop: "5px"}} span={2}>
|
||||||
{Setting.getLabel(i18next.t("provider:Bucket"), i18next.t("provider:Bucket - Tooltip"))} :
|
{Setting.getLabel(i18next.t("provider:Bucket"), i18next.t("provider:Bucket - Tooltip"))} :
|
||||||
@ -685,19 +712,17 @@ class ProviderEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
)}
|
)}
|
||||||
{["Custom HTTP SMS"].includes(this.state.provider.type) ? null : (
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Col style={{marginTop: "5px"}} span={2}>
|
||||||
<Col style={{marginTop: "5px"}} span={2}>
|
{Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:Path prefix - Tooltip"))} :
|
||||||
{Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:Path prefix - Tooltip"))} :
|
</Col>
|
||||||
</Col>
|
<Col span={22} >
|
||||||
<Col span={22} >
|
<Input value={this.state.provider.pathPrefix} onChange={e => {
|
||||||
<Input value={this.state.provider.pathPrefix} onChange={e => {
|
this.updateProviderField("pathPrefix", e.target.value);
|
||||||
this.updateProviderField("pathPrefix", e.target.value);
|
}} />
|
||||||
}} />
|
</Col>
|
||||||
</Col>
|
</Row>
|
||||||
</Row>
|
{["MinIO", "Google Cloud Storage", "Qiniu Cloud Kodo"].includes(this.state.provider.type) ? null : (
|
||||||
)}
|
|
||||||
{["Custom HTTP SMS", "MinIO", "Google Cloud Storage", "Qiniu Cloud Kodo"].includes(this.state.provider.type) ? null : (
|
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={2}>
|
<Col style={{marginTop: "5px"}} span={2}>
|
||||||
{Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} :
|
{Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} :
|
||||||
@ -723,56 +748,44 @@ class ProviderEditPage extends React.Component {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
{
|
|
||||||
this.state.provider.type !== "Custom HTTP SMS" ? null : (
|
|
||||||
<React.Fragment>
|
|
||||||
<Row style={{marginTop: "20px"}} >
|
|
||||||
<Col style={{marginTop: "5px"}} span={2}>
|
|
||||||
{Setting.getLabel(i18next.t("general:Method"), i18next.t("provider:Method - Tooltip"))} :
|
|
||||||
</Col>
|
|
||||||
<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}</Option>)
|
|
||||||
}
|
|
||||||
</Select>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row style={{marginTop: "20px"}} >
|
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
|
||||||
{Setting.getLabel(i18next.t("provider:Parameter name"), i18next.t("provider:Parameter name - Tooltip"))} :
|
|
||||||
</Col>
|
|
||||||
<Col span={22} >
|
|
||||||
<Input value={this.state.provider.clientId} onChange={e => {
|
|
||||||
this.updateProviderField("clientId", e.target.value);
|
|
||||||
}} />
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row style={{marginTop: "20px"}} >
|
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
|
||||||
{Setting.getLabel(i18next.t("provider:Content"), i18next.t("provider:Content - Tooltip"))} :
|
|
||||||
</Col>
|
|
||||||
<Col span={22} >
|
|
||||||
<TextArea autoSize={{minRows: 3, maxRows: 100}} value={this.state.provider.title} onChange={e => {
|
|
||||||
this.updateProviderField("title", e.target.value);
|
|
||||||
}} />
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</React.Fragment>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
{this.getAppIdRow(this.state.provider)}
|
{this.getAppIdRow(this.state.provider)}
|
||||||
{
|
{
|
||||||
this.state.provider.category === "Notification" ? (
|
this.state.provider.category === "Notification" ? (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
{["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"))} :
|
||||||
|
</Col>
|
||||||
|
<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}</Option>)
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
) : null}
|
||||||
|
{["Custom HTTP"].includes(this.state.provider.type) ? (
|
||||||
|
<Row style={{marginTop: "20px"}} >
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
|
{Setting.getLabel(i18next.t("provider:Parameter"), i18next.t("provider:Parameter - Tooltip"))} :
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
<Input value={this.state.provider.title} onChange={e => {
|
||||||
|
this.updateProviderField("title", e.target.value);
|
||||||
|
}} />
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
) : null}
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("provider:Notification content"), i18next.t("provider:Notification content - Tooltip"))} :
|
{Setting.getLabel(i18next.t("provider:Content"), i18next.t("provider:Content - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<TextArea autoSize={{minRows: 3, maxRows: 100}} value={this.state.provider.content} onChange={e => {
|
<TextArea autoSize={{minRows: 3, maxRows: 100}} value={this.state.provider.content} onChange={e => {
|
||||||
@ -781,14 +794,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row style={{marginTop: "20px"}} >
|
<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
{this.getReceiverRow(this.state.provider)}
|
||||||
{Setting.getLabel(i18next.t("provider:Chat Id"), i18next.t("provider:Chat Id - Tooltip"))} :
|
|
||||||
</Col>
|
|
||||||
<Col span={4} >
|
|
||||||
<Input value={this.state.provider.receiver} placeholder = {i18next.t("user:Input your chat id")} onChange={e => {
|
|
||||||
this.updateProviderField("receiver", e.target.value);
|
|
||||||
}} />
|
|
||||||
</Col>
|
|
||||||
<Button style={{marginLeft: "10px", marginBottom: "5px"}} type="primary"
|
<Button style={{marginLeft: "10px", marginBottom: "5px"}} type="primary"
|
||||||
onClick={() => ProviderNotification.sendTestNotification(this.state.provider, this.state.provider.receiver)} >
|
onClick={() => ProviderNotification.sendTestNotification(this.state.provider, this.state.provider.receiver)} >
|
||||||
{i18next.t("provider:Send Testing Notification")}
|
{i18next.t("provider:Send Testing Notification")}
|
||||||
@ -868,7 +874,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
) : this.state.provider.category === "SMS" ? (
|
) : this.state.provider.category === "SMS" ? (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{["Custom HTTP SMS", "Twilio SMS", "Amazon SNS", "Azure ACS", "Msg91 SMS", "Infobip SMS"].includes(this.state.provider.type) ?
|
{["Twilio SMS", "Amazon SNS", "Azure ACS", "Msg91 SMS", "Infobip SMS"].includes(this.state.provider.type) ?
|
||||||
null :
|
null :
|
||||||
(<Row style={{marginTop: "20px"}} >
|
(<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
@ -882,7 +888,7 @@ class ProviderEditPage extends React.Component {
|
|||||||
</Row>
|
</Row>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
{["Custom HTTP SMS", "Infobip SMS"].includes(this.state.provider.type) ?
|
{["Infobip SMS"].includes(this.state.provider.type) ?
|
||||||
null :
|
null :
|
||||||
(<Row style={{marginTop: "20px"}} >
|
(<Row style={{marginTop: "20px"}} >
|
||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
@ -900,32 +906,27 @@ class ProviderEditPage extends React.Component {
|
|||||||
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
{Setting.getLabel(i18next.t("provider:SMS Test"), i18next.t("provider:SMS Test - Tooltip"))} :
|
{Setting.getLabel(i18next.t("provider:SMS Test"), i18next.t("provider:SMS Test - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
{["Custom HTTP SMS"].includes(this.state.provider.type) ?
|
<Col span={4} >
|
||||||
null :
|
<Input.Group compact>
|
||||||
(
|
<CountryCodeSelect
|
||||||
<Col span={4} >
|
style={{width: "30%"}}
|
||||||
<Input.Group compact>
|
value={this.state.provider.content}
|
||||||
<CountryCodeSelect
|
onChange={(value) => {
|
||||||
style={{width: "30%"}}
|
this.updateProviderField("content", value);
|
||||||
value={this.state.provider.content}
|
}}
|
||||||
onChange={(value) => {
|
countryCodes={this.props.account.organization.countryCodes}
|
||||||
this.updateProviderField("content", value);
|
/>
|
||||||
}}
|
<Input value={this.state.provider.receiver}
|
||||||
countryCodes={this.props.account.organization.countryCodes}
|
style={{width: "70%"}}
|
||||||
/>
|
placeholder = {i18next.t("user:Input your phone number")}
|
||||||
<Input value={this.state.provider.receiver}
|
onChange={e => {
|
||||||
style={{width: "70%"}}
|
this.updateProviderField("receiver", e.target.value);
|
||||||
placeholder = {i18next.t("user:Input your phone number")}
|
}} />
|
||||||
onChange={e => {
|
</Input.Group>
|
||||||
this.updateProviderField("receiver", e.target.value);
|
</Col>
|
||||||
}} />
|
|
||||||
</Input.Group>
|
|
||||||
</Col>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
<Col span={2} >
|
<Col span={2} >
|
||||||
<Button style={{marginLeft: "10px", marginBottom: "5px"}} type="primary"
|
<Button style={{marginLeft: "10px", marginBottom: "5px"}} type="primary"
|
||||||
disabled={!Setting.isValidPhone(this.state.provider.receiver) && (this.state.provider.type !== "Custom HTTP SMS" || this.state.provider.endpoint === "")}
|
disabled={!Setting.isValidPhone(this.state.provider.receiver)}
|
||||||
onClick={() => ProviderEditTestSms.sendTestSms(this.state.provider, "+" + Setting.getCountryCode(this.state.provider.content) + this.state.provider.receiver)} >
|
onClick={() => ProviderEditTestSms.sendTestSms(this.state.provider, "+" + Setting.getCountryCode(this.state.provider.content) + this.state.provider.receiver)} >
|
||||||
{i18next.t("provider:Send Testing SMS")}
|
{i18next.t("provider:Send Testing SMS")}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -96,10 +96,6 @@ export const OtherProviderInfo = {
|
|||||||
logo: `${StaticBaseUrl}/img/social_azure.png`,
|
logo: `${StaticBaseUrl}/img/social_azure.png`,
|
||||||
url: "https://azure.microsoft.com/en-us/products/communication-services",
|
url: "https://azure.microsoft.com/en-us/products/communication-services",
|
||||||
},
|
},
|
||||||
"Custom HTTP SMS": {
|
|
||||||
logo: `${StaticBaseUrl}/img/email_default.png`,
|
|
||||||
url: "https://casdoor.org/docs/provider/sms/overview",
|
|
||||||
},
|
|
||||||
"Infobip SMS": {
|
"Infobip SMS": {
|
||||||
logo: `${StaticBaseUrl}/img/social_infobip.png`,
|
logo: `${StaticBaseUrl}/img/social_infobip.png`,
|
||||||
url: "https://portal.infobip.com/homepage/",
|
url: "https://portal.infobip.com/homepage/",
|
||||||
@ -276,6 +272,10 @@ export const OtherProviderInfo = {
|
|||||||
logo: `${StaticBaseUrl}/img/social_telegram.png`,
|
logo: `${StaticBaseUrl}/img/social_telegram.png`,
|
||||||
url: "https://telegram.org/",
|
url: "https://telegram.org/",
|
||||||
},
|
},
|
||||||
|
"Custom HTTP": {
|
||||||
|
logo: `${StaticBaseUrl}/img/email_default.png`,
|
||||||
|
url: "https://casdoor.org/docs/provider/sms/overview",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -909,7 +909,6 @@ export function getProviderTypeOptions(category) {
|
|||||||
{id: "Aliyun SMS", name: "Alibaba Cloud SMS"},
|
{id: "Aliyun SMS", name: "Alibaba Cloud SMS"},
|
||||||
{id: "Amazon SNS", name: "Amazon SNS"},
|
{id: "Amazon SNS", name: "Amazon SNS"},
|
||||||
{id: "Azure ACS", name: "Azure ACS"},
|
{id: "Azure ACS", name: "Azure ACS"},
|
||||||
{id: "Custom HTTP SMS", name: "Custom HTTP SMS"},
|
|
||||||
{id: "Infobip SMS", name: "Infobip SMS"},
|
{id: "Infobip SMS", name: "Infobip SMS"},
|
||||||
{id: "Tencent Cloud SMS", name: "Tencent Cloud SMS"},
|
{id: "Tencent Cloud SMS", name: "Tencent Cloud SMS"},
|
||||||
{id: "Baidu Cloud SMS", name: "Baidu Cloud SMS"},
|
{id: "Baidu Cloud SMS", name: "Baidu Cloud SMS"},
|
||||||
@ -966,6 +965,7 @@ export function getProviderTypeOptions(category) {
|
|||||||
} else if (category === "Notification") {
|
} else if (category === "Notification") {
|
||||||
return ([
|
return ([
|
||||||
{id: "Telegram", name: "Telegram"},
|
{id: "Telegram", name: "Telegram"},
|
||||||
|
{id: "Custom HTTP", name: "Custom HTTP"},
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
export function sendTestNotification(provider, notification) {
|
export function sendTestNotification(provider) {
|
||||||
testNotificationProvider(provider, notification)
|
testNotificationProvider(provider.content, provider.name)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
Setting.showMessage("success", i18next.t("general:Successfully sent"));
|
Setting.showMessage("success", i18next.t("general:Successfully sent"));
|
||||||
@ -29,12 +29,12 @@ export function sendTestNotification(provider, notification) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNotificationProvider(provider, email = "") {
|
function testNotificationProvider(content, name) {
|
||||||
const notificationForm = {
|
const notificationForm = {
|
||||||
content: provider.content,
|
content: content,
|
||||||
};
|
};
|
||||||
|
|
||||||
return fetch(`${Setting.ServerUrl}/api/send-notification?provider=` + provider.name, {
|
return fetch(`${Setting.ServerUrl}/api/send-notification?provider=${name}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
body: JSON.stringify(notificationForm),
|
body: JSON.stringify(notificationForm),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user