Exemple #1
0
func EnsureAdminUser() {
	statsQuery := m.GetSystemStatsQuery{}

	if err := bus.Dispatch(&statsQuery); err != nil {
		log.Fatal(3, "Could not determine if admin user exists: %v", err)
		return
	}

	if statsQuery.Result.UserCount > 0 {
		return
	}

	cmd := m.CreateUserCommand{}
	cmd.Login = setting.AdminUser
	cmd.Email = setting.AdminUser + "@localhost"
	cmd.Password = setting.AdminPassword
	cmd.IsAdmin = true

	if err := bus.Dispatch(&cmd); err != nil {
		log.Error(3, "Failed to create default admin user", err)
		return
	}

	system := m.AddSystemsCommand{}
	system.OrgId = cmd.Result.OrgId
	system.SystemsName = []string{"Cloudwiz"}
	if err := bus.Dispatch(&system); err != nil {
		log.Error(3, "Failed to create defalut system for admin", err)
		return
	}
	log.Info("Created default Cloudwiz system")
	log.Info("Created default admin user: %v", setting.AdminUser)
}
Exemple #2
0
func AddNewSystems(c *middleware.Context, system m.AddSystemsCommand) Response {
	system.OrgId = c.OrgId
	if err := bus.Dispatch(&system); err != nil {
		return ApiError(500, "Failed to update Systems", err)
	}
	return ApiSuccess("Systems added")
}