Skip to content

Commit

Permalink
feat: add SendEmailByProvider and SendSmsByProvider APIs, add back Ap…
Browse files Browse the repository at this point in the history
…plication.CertObj (#129)

* feat: support send email and sms by specific provider

* feat: remove sms-test and add cert obj to application

* feat: remove email provider test
  • Loading branch information
love98ooo authored Sep 26, 2024
1 parent 0e8233a commit 51af090
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
3 changes: 2 additions & 1 deletion casdoorsdk/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ type Application struct {

FailedSigninLimit int `json:"failedSigninLimit"`
FailedSigninFrozenTime int `json:"failedSigninFrozenTime"`
}

CertObj *Cert `xorm:"-" json:"certObj"`
}

func (c *Client) GetApplications() ([]*Application, error) {
queryMap := map[string]string{
Expand Down
22 changes: 22 additions & 0 deletions casdoorsdk/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,25 @@ func (c *Client) SendEmail(title string, content string, sender string, receiver
}
return nil
}

func (c *Client) SendEmailByProvider(title string, content string, sender string, provider string, receivers ...string) error {
form := emailForm{
Title: title,
Content: content,
Sender: sender,
Receivers: receivers,
}
postBytes, err := json.Marshal(form)
if err != nil {
return err
}

providerMap := map[string]string{
"provider": provider,
}
_, err = c.DoPost("send-email", providerMap, postBytes, false, false)
if err != nil {
return err
}
return nil
}
4 changes: 4 additions & 0 deletions casdoorsdk/email_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ package casdoorsdk
func SendEmail(title string, content string, sender string, receivers ...string) error {
return globalClient.SendEmail(title, content, sender, receivers...)
}

func SendEmailByProvider(title string, content string, sender string, provider string, receivers ...string) error {
return globalClient.SendEmailByProvider(title, content, sender, provider, receivers...)
}
20 changes: 20 additions & 0 deletions casdoorsdk/sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,23 @@ func (c *Client) SendSms(content string, receivers ...string) error {
}
return nil
}

func (c *Client) SendSmsByProvider(content string, provider string, receivers ...string) error {
form := smsForm{
Content: content,
Receivers: receivers,
}
postBytes, err := json.Marshal(form)
if err != nil {
return err
}

providerMap := map[string]string{
"provider": provider,
}
_, err = c.DoPost("send-sms", providerMap, postBytes, false, false)
if err != nil {
return err
}
return nil
}
4 changes: 4 additions & 0 deletions casdoorsdk/sms_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ package casdoorsdk
func SendSms(content string, receivers ...string) error {
return globalClient.SendSms(content, receivers...)
}

func SendSmsByProvider(content string, provider string, receivers ...string) error {
return globalClient.SendSmsByProvider(content, provider, receivers...)
}
4 changes: 2 additions & 2 deletions casdoorsdk/sms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestSms(t *testing.T) {
InitConfig(TestCasdoorEndpoint, TestClientId, TestClientSecret, TestJwtPublicKey, TestCasdoorOrganization, TestCasdoorApplication)

sms := &smsForm{
Content: "casdoor",
Receivers: []string{"+8613854673829", "+441932567890"},
Content: "casdoor",
Receivers: []string{"+8613854673829", "+441932567890"},
}
err := SendSms(sms.Content, sms.Receivers...)
if err != nil {
Expand Down

0 comments on commit 51af090

Please sign in to comment.