From 16cbb12fdda7b32ea312d813c8bb60d44292e321 Mon Sep 17 00:00:00 2001 From: "LinskRuis.32" Date: Thu, 11 Jun 2020 10:09:59 +0800 Subject: [PATCH] const+username --- core/comm/const.go | 14 ++++++++++++++ core/comm/db.go | 8 ++++---- core/utils/code.go | 8 ++++++++ service/mgoService/info.go | 3 ++- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 core/comm/const.go diff --git a/core/comm/const.go b/core/comm/const.go new file mode 100644 index 0000000..3b9c7ea --- /dev/null +++ b/core/comm/const.go @@ -0,0 +1,14 @@ +package comm + +import "regexp" + +const ( + TimeZero = -62135596800 + TimeFmt = "2006-01-02 15:04:05" + TimeFmts = "2006-01-02" + TimeFmtm = "2006-01" + TimeFmtt = "20060102150405" + TimeFmtpck = "2006-01-02T15:04:05.999999999Z" +) + +var REG_Phone = regexp.MustCompile(`^([0-9]{0,3})[1][3,4,5,7,8,9][0-9]{9}$`) diff --git a/core/comm/db.go b/core/comm/db.go index b2a36ab..a20995d 100644 --- a/core/comm/db.go +++ b/core/comm/db.go @@ -13,7 +13,7 @@ var ( ) func InitDb() error { - err := initDbSys() + err := initDb("sys", &DbSys) if err != nil { return err } @@ -23,8 +23,8 @@ func InitDb() error { } return nil } -func initDbSys() error { - cnf := gocloud.CloudConf.Datasorce["sys"] +func initDb(key string, pdb **xorm.Engine) error { + cnf := gocloud.CloudConf.Datasorce[key] if !cnf.Enable { return nil } @@ -41,7 +41,7 @@ func initDbSys() error { println("db RegisterSqlTemplate error : " + err.Error()) }*/ - DbSys = db + *pdb = db return nil } diff --git a/core/utils/code.go b/core/utils/code.go index 4251724..18da74f 100644 --- a/core/utils/code.go +++ b/core/utils/code.go @@ -1,6 +1,7 @@ package utils import ( + "GoClouds/core/comm" "fmt" "math/rand" "strings" @@ -18,3 +19,10 @@ func GenValidateCode(width int) string { } return sb.String() } + +func HideUserName(name string) string { + if comm.REG_Phone.MatchString(name) { + return name[:3] + "****" + name[7:] + } + return name +} diff --git a/service/mgoService/info.go b/service/mgoService/info.go index 106b44f..0764f97 100644 --- a/service/mgoService/info.go +++ b/service/mgoService/info.go @@ -1,6 +1,7 @@ package mgoService import ( + "GoClouds/core/utils" "GoClouds/models" "GoClouds/service" "GoClouds/service/userService" @@ -24,7 +25,7 @@ func GetUserInfoUid(uid string) *models.MgoUserInfo { e.Id = bson.NewObjectId() e.Uid = usr.Xid e.Name = usr.Name - e.Nick = usr.Nick + e.Nick = utils.HideUserName(usr.Name) err := ses.C().Insert(e) if err != nil { return nil