mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
fix: improvde code logic (#285)
Signed-off-by: sh1luo <690898835@qq.com>
This commit is contained in:
@ -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++
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user