Return sms error message.

This commit is contained in:
Yang Luo
2021-05-14 18:19:47 +08:00
parent d361a39ffc
commit b7cbc0e015
4 changed files with 14 additions and 18 deletions

View File

@ -45,14 +45,14 @@ func (c *ApiController) SendVerificationCode() {
return return
} }
ret := "Invalid dest type." msg := "Invalid dest type."
switch destType { switch destType {
case "email": case "email":
if !util.IsEmailValid(dest) { if !util.IsEmailValid(dest) {
c.ResponseError("Invalid Email address") c.ResponseError("Invalid Email address")
return return
} }
ret = object.SendVerificationCodeToEmail(remoteAddr, dest) msg = object.SendVerificationCodeToEmail(remoteAddr, dest)
case "phone": case "phone":
if !util.IsPhoneCnValid(dest) { if !util.IsPhoneCnValid(dest) {
c.ResponseError("Invalid phone number") c.ResponseError("Invalid phone number")
@ -64,17 +64,15 @@ func (c *ApiController) SendVerificationCode() {
phonePrefix = org.PhonePrefix phonePrefix = org.PhonePrefix
} }
dest = fmt.Sprintf("+%s%s", phonePrefix, dest) dest = fmt.Sprintf("+%s%s", phonePrefix, dest)
ret = object.SendVerificationCodeToPhone(remoteAddr, dest) msg = object.SendVerificationCodeToPhone(remoteAddr, dest)
} }
var status string status := "ok"
if len(ret) == 0 { if msg != "" {
status = "ok"
} else {
status = "error" status = "error"
} }
c.Data["json"] = Response{Status: status, Msg: ret} c.Data["json"] = Response{Status: status, Msg: msg}
c.ServeJSON() c.ServeJSON()
} }

View File

@ -15,8 +15,6 @@
package object package object
import ( import (
"fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/casdoor/go-sms-sender" "github.com/casdoor/go-sms-sender"
) )
@ -35,14 +33,14 @@ func InitSmsClient() {
client = go_sms_sender.NewSmsClient(provider, accessId, accessKey, sign, region, templateId, appId) client = go_sms_sender.NewSmsClient(provider, accessId, accessKey, sign, region, templateId, appId)
} }
func SendCodeToPhone(phone, code string) { func SendCodeToPhone(phone, code string) string {
if client == nil { if client == nil {
InitSmsClient() InitSmsClient()
if client == nil { if client == nil {
fmt.Println("Sms Config Error") return "SMS config error"
return
} }
} }
param := make(map[string]string) param := make(map[string]string)
if provider == "tencent" { if provider == "tencent" {
param["0"] = code param["0"] = code
@ -50,4 +48,5 @@ func SendCodeToPhone(phone, code string) {
param["code"] = code param["code"] = code
} }
client.SendMessage(param, phone) client.SendMessage(param, phone)
return ""
} }

View File

@ -51,8 +51,7 @@ func SendVerificationCodeToPhone(remoteAddr, dest string) string {
return result return result
} }
SendCodeToPhone(dest, code) return SendCodeToPhone(dest, code)
return ""
} }
func AddToVerificationRecord(remoteAddr, dest, code string) string { func AddToVerificationRecord(remoteAddr, dest, code string) string {

View File

@ -130,9 +130,9 @@
"Code Sent": "验证码已发送", "Code Sent": "验证码已发送",
"Input your email": "请输入邮箱", "Input your email": "请输入邮箱",
"Input your phone number": "输入手机号", "Input your phone number": "输入手机号",
"New phone": "新手机号", "New phone": "新手机号",
"New email": "新邮箱", "New email": "新邮箱",
"Code You Received": "你收到的验证码", "Code You Received": "验证码",
"Enter your code": "输入你的验证码", "Enter your code": "输入你的验证码",
"You can only send one code in 60s.": "每分钟你只能发送一次验证码", "You can only send one code in 60s.": "每分钟你只能发送一次验证码",
"Code has not been sent yet!": "你还没有发送验证码", "Code has not been sent yet!": "你还没有发送验证码",