示例#1
0
文件: admin.go 项目: go-galaxy/galaxy
func Permission(r render.Render) {
	l, err := dao.GetAllPermission()
	if err != nil {
		service.Logs.Error("dao.GetAllPermission() err(%v)", err)
	}
	data := make(map[string]interface{})
	data["l"] = l
	r.HTML(200, "permission", data)
	return
}
示例#2
0
//从数据库读入缓存
func Reload() (err error) {
	//reload user
	userList, err := dao.GetAllUser()
	if err != nil {
		Logs.Error("dao.GetAllUser err (%v)", err)
		return
	}
	for _, v := range userList {
		cache.Users[v.Id] = v
	}
	//reload permission
	pList, err := dao.GetAllPermission()
	if err != nil {
		Logs.Error("dao.GetAllPermission err (%v)", err)
		return
	}
	for _, v := range pList {
		cache.Permissions[v.Id] = v
	}
	//reload role
	rList, err := dao.GetAllRole()
	if err != nil {
		Logs.Error("dao.GetAllRole err (%v)", err)
		return
	}
	for _, v := range rList {
		cache.Roles[v.Id] = v
	}
	//reload userRole
	urList, err := dao.GetAllUserRole()
	if err != nil {
		Logs.Error("dao.GetAllUserRole err (%v)", err)
		return
	}
	for _, v := range urList {
		cache.UserRoleCache.Add(v.UserId, v.RoleId)
	}
	//reload rolePermission
	rpList, err := dao.GetAllRolePermission()
	if err != nil {
		Logs.Error("dao.GetAllRolePermission err (%v)", err)
		return
	}
	for _, v := range rpList {
		cache.RolePermissionCache.Add(v.RoleId, v.PermissionId)
	}
	return

}
示例#3
0
文件: admin.go 项目: go-galaxy/galaxy
func RoleAdd(r render.Render, req *http.Request) {
	req.ParseForm()
	values := req.Form
	id := values.Get("id")
	var idInt64 int64
	var err error
	m := &model.Role{}
	data := make(map[string]interface{})

	l, err := dao.GetAllPermission()
	if err != nil {
		service.Logs.Error("dao.GetAllPermission() err(%v)", err)
	}
	data["l"] = l

	list := dao.GetFormatPermission()
	data["list"] = list

	if id != "" {
		idInt64, err = strconv.ParseInt(id, 10, 64)
		if err != nil {
			service.Logs.Error("strconv.ParseInt err(%v)", err)
			return
		}
	}
	if req.Method == "GET" {
		if id != "" && idInt64 != 0 {
			m, err = dao.GetRoleById(idInt64)
			if err != nil {
				service.Logs.Error("dao.GetRoleById err(%v)", err)
				return
			}
		}
		p := cache.GetRolePermissions(idInt64)
		data["p"] = p
		data["m"] = m
		r.HTML(200, "role_add", data)
		return
	}
	m.Info = values.Get("info")
	m.Name = values.Get("name")
	if id == "" || idInt64 == 0 {
		m.Status = 0
		mId, err := dao.AddRole(m)
		if err != nil {
			service.Logs.Error("dao.AddRole err(%v)", err)
			return
		}
		m, _ = dao.GetRoleById(mId)
	} else {
		m.Id = idInt64
		status, _ := strconv.Atoi(values.Get("status"))
		m.Status = status
		err = dao.UpdateRoleById(m)
		if err != nil {
			service.Logs.Error("dao.UpdateRoleById err(%v)", err)
			return
		}
	}
	p := cache.GetRolePermissions(idInt64)

	data["p"] = p
	data["m"] = m

	r.HTML(200, "role_add", data)
	return
}