zhou.xiaoning há 2 anos atrás
pai
commit
3289ae5360
1 ficheiros alterados com 9 adições e 2 exclusões
  1. 9 2
      models/account.go

+ 9 - 2
models/account.go

@@ -7,6 +7,7 @@ import (
 	"mtp2_if/db"
 	"mtp2_if/global/e"
 	"mtp2_if/utils"
+	"regexp"
 	"strconv"
 	"time"
 )
@@ -704,8 +705,8 @@ func GetUserInfo(userID int) (*Userinfo, error) {
 	if len(userInfo.Mobile) > 0 {
 		if s1, err := hex.DecodeString(userInfo.Mobile); err == nil { // hex -> []byte
 			if s2, err := utils.AESDecrypt(s1, key); err == nil {
-				// 临时操作 - 解决导入数据手机号码被加密两次的问题
-				if len(userInfo.Mobile) >= 40 {
+				// FIXME: - 临时操作 - 解决导入数据手机号码被加密两次的问题
+				if !phoneValid(string(s2)) {
 					if s3, err := utils.AESDecrypt(s2, key); err == nil {
 						userInfo.Mobile2 = string(s3)
 					}
@@ -719,6 +720,12 @@ func GetUserInfo(userID int) (*Userinfo, error) {
 	return &userInfo, nil
 }
 
+func phoneValid(phone string) bool {
+	reg := `^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$`
+	rgx := regexp.MustCompile(reg)
+	return rgx.MatchString(phone)
+}
+
 // GetUserInfoByLoginID 通过登录账号获取用户信息的方法
 func GetUserInfoByLoginID(loginID int) (*Userinfo, error) {
 	engine := db.GetEngine()