コード例 #1
0
ファイル: group.go プロジェクト: nadnawidy/colony-manager
func (a *GroupController) SaveGroup(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())
	}
	g := payload["group"].(map[string]interface{})

	initGroup := new(acl.Group)
	initGroup.ID = g["_id"].(string)
	initGroup.Title = g["Title"].(string)
	initGroup.Owner = g["Owner"].(string)
	initGroup.Enable = g["Enable"].(bool)
	err = acl.Save(initGroup)
	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}
	var grant map[string]interface{}
	for _, p := range payload["grants"].([]interface{}) {
		dat := []byte(p.(string))
		if err = json.Unmarshal(dat, &grant); err != nil {
			return helper.CreateResult(true, nil, err.Error())
		}
		AccessID := grant["AccessID"].(string)
		Accessvalue := grant["AccessValue"]
		for _, v := range Accessvalue.([]interface{}) {
			switch v {
			case "AccessCreate":
				initGroup.Grant(AccessID, acl.AccessCreate)
			case "AccessRead":
				initGroup.Grant(AccessID, acl.AccessRead)
			case "AccessUpdate":
				initGroup.Grant(AccessID, acl.AccessUpdate)
			case "AccessDelete":
				initGroup.Grant(AccessID, acl.AccessDelete)
			case "AccessSpecial1":
				initGroup.Grant(AccessID, acl.AccessSpecial1)
			case "AccessSpecial2":
				initGroup.Grant(AccessID, acl.AccessSpecial2)
			case "AccessSpecial3":
				initGroup.Grant(AccessID, acl.AccessSpecial3)
			case "AccessSpecial4":
				initGroup.Grant(AccessID, acl.AccessSpecial4)
			}
		}
	}
	err = acl.Save(initGroup)
	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}
	return helper.CreateResult(true, nil, "sukses")
}
コード例 #2
0
func (a *AdministrationController) SaveAccess(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())
	}

	initAccess := new(acl.Access)
	initAccess.ID = payload["_id"].(string)
	initAccess.Title = payload["Title"].(string)
	initAccess.Group1 = payload["Group1"].(string)
	initAccess.Group2 = payload["Group2"].(string)
	initAccess.Group3 = payload["Group3"].(string)
	initAccess.Enable = payload["Enable"].(bool)
	initAccess.SpecialAccess1 = payload["SpecialAccess1"].(string)
	initAccess.SpecialAccess2 = payload["SpecialAccess2"].(string)
	initAccess.SpecialAccess3 = payload["SpecialAccess3"].(string)
	initAccess.SpecialAccess4 = payload["SpecialAccess4"].(string)
	err = acl.Save(initAccess)
	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}
	return helper.CreateResult(true, initAccess, "sukses")
}
コード例 #3
0
ファイル: login.go プロジェクト: Budianto55/colony-manager
func (l *LoginController) PrepareDefaultUser() (err error) {
	username := colonycore.GetConfig("default_username", "").(string)
	password := colonycore.GetConfig("default_password", "").(string)

	user := new(acl.User)
	filter := dbox.Contains("loginid", username)
	c, err := acl.Find(user, filter, nil)

	if err != nil {
		return
	}

	if c.Count() == 0 {
		user.ID = toolkit.RandomString(32)
		user.LoginID = username
		user.FullName = username
		user.Password = password
		user.Enable = true

		err = acl.Save(user)
		if err != nil {
			return
		}
		err = acl.ChangePassword(user.ID, password)
		if err != nil {
			return
		}

		fmt.Printf(`Default user "%s" with standard password has been created%s`, username, "\n")
	}

	return
}
コード例 #4
0
ファイル: session.go プロジェクト: eaciit/colony-manager
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")
}
コード例 #5
0
func (a *ApplicationController) SaveAccess(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson
	conn, err := a.ConnectToDataSource()

	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}

	err = acl.SetDb(conn)

	initUser := new(acl.User)

	initUser.LoginID = "alip"
	initUser.FullName = "alip sidik"
	initUser.Email = "*****@*****.**"
	initUser.Password = "******"

	err = acl.Save(initUser)
	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}
	return helper.CreateResult(true, conn, "aa")
}
コード例 #6
0
ファイル: user.go プロジェクト: kranjcarz/colony-manager
func (a *UserController) SaveUser(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())
	}
	user := payload["user"].(map[string]interface{})
	groups := user["Groups"]
	var group []string
	for _, v := range groups.([]interface{}) {
		group = append(group, v.(string))
	}
	fmt.Println(user["_id"].(string))
	initUser := new(acl.User)
	id := toolkit.RandomString(32)
	if user["_id"].(string) == "" {
		initUser.ID = id
	} else {
		initUser.ID = user["_id"].(string)
	}
	initUser.LoginID = user["LoginID"].(string)
	initUser.FullName = user["FullName"].(string)
	initUser.Email = user["Email"].(string)
	initUser.Password = user["Password"].(string)
	initUser.Enable = user["Enable"].(bool)
	initUser.Groups = group

	err = acl.Save(initUser)

	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}
	if user["_id"].(string) == "" {
		err = acl.ChangePassword(initUser.ID, user["Password"].(string))
		if err != nil {
			return helper.CreateResult(true, nil, err.Error())
		}
	}

	var grant map[string]interface{}
	for _, p := range payload["grants"].([]interface{}) {
		dat := []byte(p.(string))
		if err = json.Unmarshal(dat, &grant); err != nil {
			return helper.CreateResult(true, nil, err.Error())
		}
		AccessID := grant["AccessID"].(string)
		Accessvalue := grant["AccessValue"]
		for _, v := range Accessvalue.([]interface{}) {
			switch v {
			case "AccessCreate":
				initUser.Grant(AccessID, acl.AccessCreate)
			case "AccessRead":
				initUser.Grant(AccessID, acl.AccessRead)
			case "AccessUpdate":
				initUser.Grant(AccessID, acl.AccessUpdate)
			case "AccessDelete":
				initUser.Grant(AccessID, acl.AccessDelete)
			case "AccessSpecial1":
				initUser.Grant(AccessID, acl.AccessSpecial1)
			case "AccessSpecial2":
				initUser.Grant(AccessID, acl.AccessSpecial2)
			case "AccessSpecial3":
				initUser.Grant(AccessID, acl.AccessSpecial3)
			case "AccessSpecial4":
				initUser.Grant(AccessID, acl.AccessSpecial4)
			}
		}
	}
	err = acl.Save(initUser)

	return helper.CreateResult(true, nil, "sukses")
}
コード例 #7
0
ファイル: group.go プロジェクト: eaciit/colony-manager
func (a *GroupController) SaveGroup(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())
	}
	g := payload["group"].(map[string]interface{})
	config := payload["groupConfig"].(map[string]interface{})
	memberConf, _ := toolkit.ToM(config)

	if g["GroupType"].(string) == "1" {
		memberConf.Set("filter", "("+g["Filter"].(string)+")").
			Set("attributes", []string{g["LoginID"].(string), g["Fullname"].(string), g["Email"].(string)}).
			Set("mapattributes", toolkit.M{}.Set("LoginID", g["LoginID"].(string)).
				Set("FullName", g["Fullname"].(string)).
				Set("Email", g["Email"].(string)))

		err = acl.AddUserLdapByGroup(g["_id"].(string), memberConf)
		if err != nil {
			return helper.CreateResult(false, nil, err.Error())
		}
		delete(config, "password")
		delete(memberConf, "password")
	}

	initGroup := new(acl.Group)
	initGroup.ID = g["_id"].(string)
	initGroup.Title = g["Title"].(string)
	initGroup.Owner = g["Owner"].(string)
	initGroup.Enable = g["Enable"].(bool)
	initGroup.GroupConf = config
	initGroup.MemberConf = memberConf

	if g["GroupType"].(string) == "1" {
		initGroup.GroupType = acl.GroupTypeLdap
	} else if g["GroupType"].(string) == "0" {
		initGroup.GroupType = acl.GroupTypeBasic
	}

	err = acl.Save(initGroup)
	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}

	var grant map[string]interface{}
	for _, p := range payload["grants"].([]interface{}) {
		dat := []byte(p.(string))
		if err = json.Unmarshal(dat, &grant); err != nil {
			return helper.CreateResult(true, nil, err.Error())
		}
		AccessID := grant["AccessID"].(string)
		Accessvalue := grant["AccessValue"]
		for _, v := range Accessvalue.([]interface{}) {
			switch v {
			case "AccessCreate":
				initGroup.Grant(AccessID, acl.AccessCreate)
			case "AccessRead":
				initGroup.Grant(AccessID, acl.AccessRead)
			case "AccessUpdate":
				initGroup.Grant(AccessID, acl.AccessUpdate)
			case "AccessDelete":
				initGroup.Grant(AccessID, acl.AccessDelete)
			case "AccessSpecial1":
				initGroup.Grant(AccessID, acl.AccessSpecial1)
			case "AccessSpecial2":
				initGroup.Grant(AccessID, acl.AccessSpecial2)
			case "AccessSpecial3":
				initGroup.Grant(AccessID, acl.AccessSpecial3)
			case "AccessSpecial4":
				initGroup.Grant(AccessID, acl.AccessSpecial4)
			}
		}
	}
	err = acl.Save(initGroup)
	if err != nil {
		return helper.CreateResult(true, nil, err.Error())
	}

	return helper.CreateResult(true, nil, "sukses")
}