|
|
@ -0,0 +1,51 @@ |
|
|
|
package mgoService |
|
|
|
|
|
|
|
import ( |
|
|
|
"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.NewSession() |
|
|
|
defer ses.Close() |
|
|
|
|
|
|
|
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 = usr.Nick |
|
|
|
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)["id"].(string) |
|
|
|
if len(id) <= 0 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
return GetUserInfoUid(id) |
|
|
|
} |