mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
fix: some bugs about SMS API (#310)
Signed-off-by: “seriouszyx” <674965440@qq.com>
This commit is contained in:
@ -96,6 +96,7 @@ func (c *ApiController) SendSms() {
|
|||||||
var smsForm struct {
|
var smsForm struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Receivers []string `json:"receivers"`
|
Receivers []string `json:"receivers"`
|
||||||
|
OrgId string `json:"organizationId"` // e.g. "admin/built-in"
|
||||||
}
|
}
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &smsForm)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &smsForm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -103,10 +104,13 @@ func (c *ApiController) SendSms() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
org := object.GetOrganization(smsForm.OrgId)
|
||||||
var invalidReceivers []string
|
var invalidReceivers []string
|
||||||
for _, receiver := range smsForm.Receivers {
|
for idx, receiver := range smsForm.Receivers {
|
||||||
if !util.IsPhoneCnValid(receiver) {
|
if !util.IsPhoneCnValid(receiver) {
|
||||||
invalidReceivers = append(invalidReceivers, receiver)
|
invalidReceivers = append(invalidReceivers, receiver)
|
||||||
|
} else {
|
||||||
|
smsForm.Receivers[idx] = fmt.Sprintf("+%s%s", org.PhonePrefix, receiver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +90,12 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
sendResp = object.SendVerificationCodeToPhone(organization, user, provider, remoteAddr, dest)
|
sendResp = object.SendVerificationCodeToPhone(organization, user, provider, remoteAddr, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
status := "ok"
|
|
||||||
if sendResp != nil {
|
if sendResp != nil {
|
||||||
status = "error"
|
c.Data["json"] = Response{Status: "error", Msg: sendResp.Error()}
|
||||||
|
} else {
|
||||||
|
c.Data["json"] = Response{Status: "ok"}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = Response{Status: status, Msg: sendResp.Error()}
|
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func SendVerificationCodeToPhone(organization *Organization, user *User, provide
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return SendSms(provider, dest, code)
|
return SendSms(provider, code, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordType, dest, code string) error {
|
func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordType, dest, code string) error {
|
||||||
|
Reference in New Issue
Block a user