fix: improvde code logic (#285)

Signed-off-by: sh1luo <690898835@qq.com>
This commit is contained in:
sh1luo
2021-09-04 22:20:47 +08:00
committed by GitHub
parent e68b0198f1
commit a4edf47dc4
10 changed files with 44 additions and 45 deletions

View File

@ -80,12 +80,12 @@ func (c *ApiController) SendEmail() {
ok := 0
for _, receiver := range emailForm.Receivers {
if msg := object.SendEmail(
if err = object.SendEmail(
provider,
emailForm.Title,
emailForm.Content,
receiver,
emailForm.Sender); len(msg) == 0 {
emailForm.Sender); err == nil {
ok++
}
}

View File

@ -15,6 +15,7 @@
package controllers
import (
"errors"
"fmt"
"strings"
@ -62,8 +63,8 @@ func (c *ApiController) SendVerificationCode() {
user := c.getCurrentUser()
organization := object.GetOrganization(orgId)
application := object.GetApplicationByOrganizationName(organization.Name)
msg := "Invalid dest type."
sendResp := errors.New("Invalid dest type.")
switch destType {
case "email":
if !util.IsEmailValid(dest) {
@ -72,7 +73,7 @@ func (c *ApiController) SendVerificationCode() {
}
provider := application.GetEmailProvider()
msg = object.SendVerificationCodeToEmail(organization, user, provider, remoteAddr, dest)
sendResp = object.SendVerificationCodeToEmail(organization, user, provider, remoteAddr, dest)
case "phone":
if !util.IsPhoneCnValid(dest) {
c.ResponseError("Invalid phone number")
@ -86,15 +87,15 @@ func (c *ApiController) SendVerificationCode() {
dest = fmt.Sprintf("+%s%s", org.PhonePrefix, dest)
provider := application.GetSmsProvider()
msg = object.SendVerificationCodeToPhone(organization, user, provider, remoteAddr, dest)
sendResp = object.SendVerificationCodeToPhone(organization, user, provider, remoteAddr, dest)
}
status := "ok"
if msg != "" {
if sendResp != nil {
status = "error"
}
c.Data["json"] = Response{Status: status, Msg: msg}
c.Data["json"] = Response{Status: status, Msg: sendResp.Error()}
c.ServeJSON()
}