Esempio n. 1
0
func main() {
	// Add the custom fileserver paths.
	settings.Settings.FileServer = settings.FileServer{
		"/":      "public",
		"/dist/": "../client/dist",
	}

	// Initialize BitMonster.
	bitmonster.Fatal(bitmonster.Init())

	// Create a new module.
	m, err := bitmonster.NewModule("users")
	bitmonster.Fatal(err)

	// ?
	// m.addHooks(&auth{})

	// Add module methods.
	m.AddMethod("get", getUsers, auth.MustAdminGroup())

	// Add events.
	e := m.AddEvent("onNew", auth.MustAdminGroup())

	//######
	// OR get the event.
	e, err = m.Event("onNew")
	if err != nil {
		bitmonster.Fatal(err)
	}

	_ = e

	go func() {
		for {
			time.Sleep(2 * time.Second)
			// Trigger the event.
			err = e.Trigger()
			if err != nil {
				bitmonster.Fatal(err)
			}
		}
	}()
	//#####

	// Start the BitMonster server.
	bitmonster.Fatal(bitmonster.Run())
}
Esempio n. 2
0
func init() {
	var err error

	// On init hook for BitMonster.
	bitmonster.OnInit(func() {
		// Set the maximum session age.
		authSessionMaxAge = time.Duration(int64(time.Second) * int64(settings.Settings.AuthSessionMaxAge))
	})

	// Create the authentication module.
	module, err = bitmonster.NewModule(ModuleName)
	bitmonster.Fatal(err)

	// Add events.
	eventReauth = module.AddEvent("reauthenticate")

	// Add module methods.
	module.AddMethods(bitmonster.MethodMap{
		"login":        login,
		"logout":       logout,
		"authenticate": authenticate,
	})

	// Module methods which require admin rights.
	module.AddMethods(bitmonster.MethodMap{
		"admin.getGroups":         getGroups,
		"admin.getUser":           getUser,
		"admin.getUsers":          getUsers,
		"admin.addUser":           addUser,
		"admin.deleteUser":        deleteUser,
		"admin.editUser":          editUser,
		"admin.changeUsername":    changeUsername,
		"admin.changePassword":    changePassword,
		"admin.clearAuthSessions": clearAuthSessions,
	}, MustAdminGroup())

	// Module methods which require only an authenticated session.
	module.AddMethods(bitmonster.MethodMap{
		"user.getUser":           getCurrentUser,
		"user.editUser":          editCurrentUser,
		"user.changePassword":    changePasswordOfCurrentUser,
		"user.clearAuthSessions": clearAuthSessionsOfCurrentUser,
	}, MustIsAuth())
}
Esempio n. 3
0
func init() {
	// Register the admin group.
	bitmonster.Fatal(RegisterGroup(AdminGroup))
}