Skip to content

Commit

Permalink
fix: some bugs about SMS API (#310)
Browse files Browse the repository at this point in the history
Signed-off-by: “seriouszyx” <674965440@qq.com>
  • Loading branch information
seriouszyx committed Oct 31, 2021
1 parent b7f2f90 commit 609e978
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion controllers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,21 @@ func (c *ApiController) SendSms() {
var smsForm struct {
Content string `json:"content"`
Receivers []string `json:"receivers"`
OrgId string `json:"organizationId"` // e.g. "admin/built-in"
}
err := json.Unmarshal(c.Ctx.Input.RequestBody, &smsForm)
if err != nil {
c.ResponseError(err.Error())
return
}

org := object.GetOrganization(smsForm.OrgId)
var invalidReceivers []string
for _, receiver := range smsForm.Receivers {
for idx, receiver := range smsForm.Receivers {
if !util.IsPhoneCnValid(receiver) {
invalidReceivers = append(invalidReceivers, receiver)
} else {
smsForm.Receivers[idx] = fmt.Sprintf("+%s%s", org.PhonePrefix, receiver)
}
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *ApiController) SendVerificationCode() {
user := c.getCurrentUser()
organization := object.GetOrganization(orgId)
application := object.GetApplicationByOrganizationName(organization.Name)

sendResp := errors.New("Invalid dest type.")
switch destType {
case "email":
Expand All @@ -90,12 +90,12 @@ func (c *ApiController) SendVerificationCode() {
sendResp = object.SendVerificationCodeToPhone(organization, user, provider, remoteAddr, dest)
}

status := "ok"
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()
}

Expand Down
2 changes: 1 addition & 1 deletion object/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func SendVerificationCodeToPhone(organization *Organization, user *User, provide
return err
}

return SendSms(provider, dest, code)
return SendSms(provider, code, dest)
}

func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordType, dest, code string) error {
Expand Down

0 comments on commit 609e978

Please sign in to comment.