本文整理匯總了Golang中github.com/eaciit/acl.FindByID函數的典型用法代碼示例。如果您正苦於以下問題:Golang FindByID函數的具體用法?Golang FindByID怎麽用?Golang FindByID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FindByID函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetSession
func (a *SessionController) GetSession(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
_ = a.InitialSetDatabase()
// payload := map[string]interface{}{}
// err := r.GetPayload(&payload)
// if err != nil {
// return helper.CreateResult(false, nil, err.Error())
// }
tSession := new(acl.Session)
data := toolkit.M{}
arrm := make([]toolkit.M, 0, 0)
// c, err := acl.Find(tSession, nil, toolkit.M{}.Set("take", payload["take"].(int)).Set("skip", payload["skip"].(int)))
c, err := acl.Find(tSession, nil, toolkit.M{}.Set("take", 10).Set("skip", 0))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
err = c.Fetch(&arrm, 0, false)
for i, val := range arrm {
tUser := new(acl.User)
e := acl.FindByID(tUser, toolkit.ToString(val.Get("userid", "")))
if e != nil {
continue
}
arrm[i].Set("username", tUser.LoginID)
arrm[i].Set("duration", time.Since(val["created"].(time.Time)).Hours())
arrm[i].Set("status", "ACTIVE")
if val["expired"].(time.Time).Before(time.Now().UTC()) {
arrm[i].Set("duration", val["expired"].(time.Time).Sub(val["created"].(time.Time)).Hours())
arrm[i].Set("status", "EXPIRED")
}
arrm[i].Set("username", tUser.LoginID)
// toolkit.Printf("Debug date : %v : %v\n", toolkit.TypeName(val["created"]), val["created"].(time.Time))
}
c.Close()
c, err = acl.Find(tSession, nil, nil)
data.Set("Datas", arrm)
data.Set("total", c.Count())
// data.Set("total", 100)
if err != nil {
return helper.CreateResult(true, nil, err.Error())
} else {
return helper.CreateResult(true, data, "")
}
}
示例2: FindAccess
func (a *AdministrationController) FindAccess(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
tAccess := new(acl.Access)
err = acl.FindByID(tAccess, payload["_id"].(string))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
} else {
return helper.CreateResult(true, tAccess, "")
}
}
示例3: FindGroup
func (a *GroupController) FindGroup(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
tGroup := new(acl.Group)
err = acl.FindByID(tGroup, payload["_id"].(string))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
} else {
return helper.CreateResult(true, tGroup, "")
}
}
示例4: DeleteUser
func (a *UserController) DeleteUser(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
a.InitialSetDatabase()
tUser := new(acl.User)
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
err = acl.FindByID(tUser, payload["_id"].(string))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
err = acl.Delete(tUser)
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
return helper.CreateResult(true, nil, "success")
}
示例5: GetUser
func GetUser(r *knot.WebContext) (tUser acl.User, err error) {
sessionId := r.Session("sessionid", "")
if toolkit.ToString(sessionId) == "" {
err = error(errors.New("Sessionid is not found"))
return
}
userid, err := acl.FindUserBySessionID(toolkit.ToString(sessionId))
if err != nil {
return
}
err = acl.FindByID(&tUser, userid)
if err != nil {
return
}
return
}
示例6: GetAccess
func (a *UserController) GetAccess(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
tUser := new(acl.User)
err = acl.FindByID(tUser, payload["id"].(string)) //
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
var AccessGrants = []interface{}{}
for _, v := range tUser.Grants {
var access = toolkit.M{}
access.Set("AccessID", v.AccessID)
access.Set("AccessValue", acl.Splitinttogrant(int(v.AccessValue)))
AccessGrants = append(AccessGrants, access)
}
fmt.Println(AccessGrants)
return helper.CreateResult(true, AccessGrants, "")
}
示例7: GetUserName
func (l *LoginController) GetUserName(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
sessionId := r.Session("sessionid", "")
if toolkit.ToString(sessionId) == "" {
return helper.CreateResult(true, "", "Sessionid is not found")
}
userid, err := acl.FindUserBySessionID(toolkit.ToString(sessionId))
if err != nil {
return helper.CreateResult(false, "", "Get username failed")
}
tUser := new(acl.User)
err = acl.FindByID(tUser, userid)
if err != nil {
return helper.CreateResult(false, "", "Get username failed")
}
return helper.CreateResult(true, toolkit.M{}.Set("username", tUser.LoginID), "")
}
示例8: SetExpired
func (a *SessionController) SetExpired(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
a.InitialSetDatabase()
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
tSession := new(acl.Session)
err = acl.FindByID(tSession, payload["_id"].(string))
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
tSession.Expired = time.Now().UTC()
err = acl.Save(tSession)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, nil, "Set expired success")
}
示例9: RefreshGroupLdap
func (a *GroupController) RefreshGroupLdap(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
group := new(acl.Group)
err = acl.FindByID(group, payload["groupid"].(string))
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
config, err := toolkit.ToM(group.MemberConf)
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
err = acl.RefreshUserLdapByGroup(payload["groupid"].(string), config)
if err != nil {
return helper.CreateResult(true, nil, err.Error())
}
return helper.CreateResult(true, nil, "success")
}
示例10: GetAccessMenu
func (l *LoginController) GetAccessMenu(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
sessionId := r.Session("sessionid", "")
cursor, err := colonycore.Find(new(colonycore.Menu), nil)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
menus := []colonycore.Menu{}
results := make([]toolkit.M, 0, 0)
cursor.Fetch(&menus, 0, false)
if IsDevMode {
for _, m := range menus {
result, _ := toolkit.ToM(m)
results = append(results, result)
}
return helper.CreateResult(true, results, "Success")
}
if toolkit.ToString(sessionId) == "" {
return helper.CreateResult(true, nil, "Session Not Found")
}
stat := acl.IsSessionIDActive(toolkit.ToString(sessionId))
if !stat {
return helper.CreateResult(false, nil, "Session Expired")
}
if cursor.Count() > 0 {
for _, m := range menus {
result := toolkit.M{}
acc := acl.HasAccess(toolkit.ToString(sessionId), acl.IDTypeSession, m.AccessId, acl.AccessRead)
result, err = toolkit.ToM(m)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
// if toolkit.ToString(sessionId) != "" {
userid, err := acl.FindUserBySessionID(toolkit.ToString(sessionId))
if err != nil {
return helper.CreateResult(false, "", "Get username failed")
}
tUser := new(acl.User)
err = acl.FindByID(tUser, userid)
if err != nil {
return helper.CreateResult(false, "", "Get username failed")
}
result.Set("detail", 7)
if tUser.LoginID == "eaciit" {
results = append(results, result)
} else {
if acc {
result.Set("childrens", "")
if len(m.Childrens) > 0 {
childs := GetChildMenu(r, m.Childrens)
result.Set("childrens", childs)
}
results = append(results, result)
}
}
// }
}
}
return helper.CreateResult(true, results, "Success")
}