From b7cbc0e015d23f89328fd46c66f90272d12011bc Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Fri, 14 May 2021 18:19:47 +0800 Subject: [PATCH] Return sms error message. --- controllers/verification.go | 14 ++++++-------- object/sms.go | 9 ++++----- object/verification.go | 3 +-- web/src/locales/zh.json | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/controllers/verification.go b/controllers/verification.go index 95c4e9e2..dfa90c77 100644 --- a/controllers/verification.go +++ b/controllers/verification.go @@ -45,14 +45,14 @@ func (c *ApiController) SendVerificationCode() { return } - ret := "Invalid dest type." + msg := "Invalid dest type." switch destType { case "email": if !util.IsEmailValid(dest) { c.ResponseError("Invalid Email address") return } - ret = object.SendVerificationCodeToEmail(remoteAddr, dest) + msg = object.SendVerificationCodeToEmail(remoteAddr, dest) case "phone": if !util.IsPhoneCnValid(dest) { c.ResponseError("Invalid phone number") @@ -64,17 +64,15 @@ func (c *ApiController) SendVerificationCode() { phonePrefix = org.PhonePrefix } dest = fmt.Sprintf("+%s%s", phonePrefix, dest) - ret = object.SendVerificationCodeToPhone(remoteAddr, dest) + msg = object.SendVerificationCodeToPhone(remoteAddr, dest) } - var status string - if len(ret) == 0 { - status = "ok" - } else { + status := "ok" + if msg != "" { status = "error" } - c.Data["json"] = Response{Status: status, Msg: ret} + c.Data["json"] = Response{Status: status, Msg: msg} c.ServeJSON() } diff --git a/object/sms.go b/object/sms.go index 98c0b0f1..4b6f0adb 100644 --- a/object/sms.go +++ b/object/sms.go @@ -15,8 +15,6 @@ package object import ( - "fmt" - "github.com/astaxie/beego" "github.com/casdoor/go-sms-sender" ) @@ -35,14 +33,14 @@ func InitSmsClient() { 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 { InitSmsClient() if client == nil { - fmt.Println("Sms Config Error") - return + return "SMS config error" } } + param := make(map[string]string) if provider == "tencent" { param["0"] = code @@ -50,4 +48,5 @@ func SendCodeToPhone(phone, code string) { param["code"] = code } client.SendMessage(param, phone) + return "" } diff --git a/object/verification.go b/object/verification.go index 47afb128..8ea40f88 100644 --- a/object/verification.go +++ b/object/verification.go @@ -51,8 +51,7 @@ func SendVerificationCodeToPhone(remoteAddr, dest string) string { return result } - SendCodeToPhone(dest, code) - return "" + return SendCodeToPhone(dest, code) } func AddToVerificationRecord(remoteAddr, dest, code string) string { diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index f7f20565..2a95df12 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -130,9 +130,9 @@ "Code Sent": "验证码已发送", "Input your email": "请输入邮箱", "Input your phone number": "输入手机号", - "New phone": "新的手机号", - "New email": "新的邮箱", - "Code You Received": "你收到的验证码", + "New phone": "新手机号", + "New email": "新邮箱", + "Code You Received": "验证码", "Enter your code": "输入你的验证码", "You can only send one code in 60s.": "每分钟你只能发送一次验证码", "Code has not been sent yet!": "你还没有发送验证码",