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.
51 lines
985 B
51 lines
985 B
package userService
|
|
|
|
import (
|
|
"GoBanpen/core/comm"
|
|
"GoBanpen/models"
|
|
"github.com/donnie4w/go-logger/logger"
|
|
gocloud "github.com/mgr9525/go-cloud"
|
|
ruisUtil "github.com/mgr9525/go-ruisutil"
|
|
"gopkg.in/macaron.v1"
|
|
)
|
|
|
|
func FindUUID(id string) *models.SysUser {
|
|
if len(id) <= 0 {
|
|
return nil
|
|
}
|
|
e := new(models.SysUser)
|
|
ok, err := comm.DbMain.Where("uuid=?", id).Get(e)
|
|
if err != nil {
|
|
logger.Info("FindUserUUID err:", err.Error())
|
|
return nil
|
|
}
|
|
if ok {
|
|
return e
|
|
}
|
|
return nil
|
|
}
|
|
func FindName(name string) *models.SysUser {
|
|
e := new(models.SysUser)
|
|
ok, err := comm.DbMain.Where("name=?", name).Get(e)
|
|
if err != nil {
|
|
logger.Info("FindName err:", err.Error())
|
|
return nil
|
|
}
|
|
if ok {
|
|
return e
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GetCurrentUser(c *macaron.Context) *models.SysUser {
|
|
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 FindUUID(id)
|
|
}
|