fix: check cn phone regex bug and add check to verification code

Signed-off-by: Kininaru <shiftregister233@outlook.com>
This commit is contained in:
Kininaru
2021-05-13 09:55:37 +08:00
parent 892cb39e3e
commit 1589da0a62
5 changed files with 16 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import (
"strings"
"github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/util"
)
func (c *ApiController) SendVerificationCode() {
@ -47,8 +48,16 @@ func (c *ApiController) SendVerificationCode() {
ret := "Invalid dest type."
switch destType {
case "email":
if !util.IsEmailValid(dest) {
c.ResponseError("Invalid Email address")
return
}
ret = object.SendVerificationCodeToEmail(remoteAddr, dest)
case "phone":
if !util.IsPhoneCnValid(dest) {
c.ResponseError("Invalid phone number")
return
}
org := object.GetOrganizationByName(user.Owner)
phonePrefix := "86"
if org != nil && org.PhonePrefix != "" {