Exemplo n.º 1
0
func GetChildMenu(r *knot.WebContext, childMenu []colonycore.Menu) interface{} {
	sessionId := r.Session("sessionid", "")
	results := make([]toolkit.M, 0, 0)
	for _, m := range childMenu {
		result := toolkit.M{}
		acc := acl.HasAccess(toolkit.ToString(sessionId), acl.IDTypeSession, m.AccessId, acl.AccessRead)
		result, err := toolkit.ToM(m)
		if err != nil {
			fmt.Println(err)
		}
		if acc {
			if len(m.Childrens) > 0 {
				childs := GetChildMenu(r, m.Childrens)
				result.Set("childrens", childs)
			}
			result.Set("detail", 7)
			results = append(results, result)
		}
	}
	return results
}
Exemplo n.º 2
0
/* ==========================================
var payload = {
sessionid:"t7AuS0YIE9w8gOWY22HPJaj1pSxEjBNU",
accesscheck:[""],
accessid:""
};

app.ajaxPost("/acl/authenticate", payload)
============================================= */
func (a *AclController) Authenticate(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson
	var iaccenum acl.AccessTypeEnum

	payload := toolkit.M{}
	result := toolkit.M{}
	result.Set("hasaccess", false)

	err := r.GetPayload(&payload)
	switch {
	case err != nil:
		return helper.CreateResult(false, nil, err.Error())
	}

	switch toolkit.TypeName(payload["accesscheck"]) {
	case "[]interface {}":
		for _, val := range payload["accesscheck"].([]interface{}) {
			tacc := acl.GetAccessEnum(toolkit.ToString(val))
			if !acl.Matchaccess(int(tacc), int(iaccenum)) {
				iaccenum += tacc
			}
		}
	default:
		iaccenum = acl.GetAccessEnum(toolkit.ToString(payload["accesscheck"]))
	}
	// toolkit.Println("Type name : ", toolkit.TypeName(payload["accesscheck"]))

	found := acl.HasAccess(toolkit.ToString(payload["sessionid"]),
		acl.IDTypeSession,
		toolkit.ToString(payload["accessid"]),
		iaccenum)

	if found {
		result.Set("hasaccess", found)
	}

	return helper.CreateResult(true, result, "")
}
Exemplo n.º 3
0
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")
}