mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Add phone provider.
This commit is contained in:
@ -29,9 +29,15 @@ type Provider struct {
|
||||
Type string `xorm:"varchar(100)" json:"type"`
|
||||
ClientId string `xorm:"varchar(100)" json:"clientId"`
|
||||
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
|
||||
Host string `xorm:"varchar(100)" json:"host"`
|
||||
Port int `json:"port"`
|
||||
ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"`
|
||||
|
||||
Host string `xorm:"varchar(100)" json:"host"`
|
||||
Port int `json:"port"`
|
||||
|
||||
RegionId string `xorm:"varchar(100)" json:"regionId"`
|
||||
SignName string `xorm:"varchar(100)" json:"signName"`
|
||||
TemplateCode string `xorm:"varchar(100)" json:"templateCode"`
|
||||
|
||||
ProviderUrl string `xorm:"varchar(200)" json:"providerUrl"`
|
||||
}
|
||||
|
||||
func GetProviders(owner string) []*Provider {
|
||||
@ -76,6 +82,19 @@ func getDefaultEmailProvider() *Provider {
|
||||
return &provider
|
||||
}
|
||||
|
||||
func getDefaultPhoneProvider() *Provider {
|
||||
provider := Provider{Owner: "admin", Category: "Phone"}
|
||||
existed, err := adapter.Engine.Get(&provider)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !existed {
|
||||
return nil
|
||||
}
|
||||
return &provider
|
||||
}
|
||||
|
||||
func UpdateProvider(id string, provider *Provider) bool {
|
||||
owner, name := util.GetOwnerAndNameFromId(id)
|
||||
if getProvider(owner, name) == nil {
|
||||
|
@ -15,34 +15,23 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"fmt"
|
||||
|
||||
"github.com/casdoor/go-sms-sender"
|
||||
)
|
||||
|
||||
var client go_sms_sender.SmsClient
|
||||
var provider string
|
||||
|
||||
func InitSmsClient() {
|
||||
provider = beego.AppConfig.String("smsProvider")
|
||||
accessId := beego.AppConfig.String("smsAccessId")
|
||||
accessKey := beego.AppConfig.String("smsAccessKey")
|
||||
appId := beego.AppConfig.String("smsAppId")
|
||||
sign := beego.AppConfig.String("smsSign")
|
||||
region := beego.AppConfig.String("smsRegion")
|
||||
templateId := beego.AppConfig.String("smsTemplateId")
|
||||
client = go_sms_sender.NewSmsClient(provider, accessId, accessKey, sign, region, templateId, appId)
|
||||
}
|
||||
|
||||
func SendCodeToPhone(phone, code string) string {
|
||||
provider := getDefaultPhoneProvider()
|
||||
if provider == nil {
|
||||
return "Please set an phone provider first"
|
||||
}
|
||||
client := go_sms_sender.NewSmsClient(provider.Type, provider.ClientId, provider.ClientSecret, provider.SignName, provider.RegionId, provider.TemplateCode)
|
||||
if client == nil {
|
||||
InitSmsClient()
|
||||
if client == nil {
|
||||
return "SMS config error"
|
||||
}
|
||||
return fmt.Sprintf("Unsupported provide type: %s", provider.Type)
|
||||
}
|
||||
|
||||
param := make(map[string]string)
|
||||
if provider == "tencent" {
|
||||
if provider.Type == "tencent" {
|
||||
param["0"] = code
|
||||
} else {
|
||||
param["code"] = code
|
||||
|
Reference in New Issue
Block a user