package mgoService import ( "GoClouds/core/utils" "GoClouds/models" "GoClouds/service" "GoClouds/service/userService" gocloud "github.com/mgr9525/go-cloud" ruisUtil "github.com/mgr9525/go-ruisutil" "gopkg.in/macaron.v1" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) func GetUserInfoUid(uid string) *models.MgoUserInfo { ses := service.MgoUserInfoDao.GetSession() e := new(models.MgoUserInfo) err := ses.C().Find(bson.M{"uid": uid}).One(e) if err != nil { if err == mgo.ErrNotFound { usr := userService.FindXid(uid) if usr == nil { return nil } e.Id = bson.NewObjectId() e.Uid = usr.Xid e.Name = usr.Name e.Nick = utils.HideUserName(usr.Name) err := ses.C().Insert(e) if err != nil { return nil } } else { return nil } } return e } func GetCurrentUserInfo(c *macaron.Context) *models.MgoUserInfo { defer ruisUtil.Recovers("GetCurrentUser", nil) tkm := gocloud.GetToken(c) if tkm == nil { return nil } id := (*tkm)["xid"].(string) if len(id) <= 0 { return nil } return GetUserInfoUid(id) }