Browse Source

const+username

master
LinskRuis.32 5 years ago
parent
commit
16cbb12fdd
  1. 14
      core/comm/const.go
  2. 8
      core/comm/db.go
  3. 8
      core/utils/code.go
  4. 3
      service/mgoService/info.go

14
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}$`)

8
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
}

8
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
}

3
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

Loading…
Cancel
Save