You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.1 KiB

package mgoService
import (
"GoClouds/core/utils"
"GoClouds/models"
"GoClouds/service"
"GoClouds/service/userService"
"context"
"github.com/gin-gonic/gin"
gocloud "github.com/mgr9525/go-cloud"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func GetUserInfoUid(uid string) *models.MgoUserInfo {
ses := service.MgoUserInfoDao.GetSession()
e := new(models.MgoUserInfo)
err := ses.C().Find(context.Background(), bson.M{"uid": uid}).One(e)
if err != nil {
//if err == qmgo.ErrNotFound {
usr := userService.FindXid(uid)
if usr == nil {
return nil
}
e.Id = primitive.NewObjectID()
e.Uid = usr.Xid
e.Name = usr.Name
if e.Name == "" {
e.Nick = "[未知用户]"
} else {
e.Nick = utils.HideUserName(usr.Name)
}
_, err = ses.C().InsertOne(context.Background(), e)
if err != nil {
return nil
}
//} else {
// return nil
//}
}
return e
}
func GetCurrentUserInfo(c *gin.Context) *models.MgoUserInfo {
tkm := gocloud.GetToken(c)
if tkm == nil {
return nil
}
id := tkm["id"].(string)
if len(id) <= 0 {
return nil
}
return GetUserInfoUid(id)
}