Example #1
0
func init() {
	// Create a new emitter, set the recover function and the max listeners.
	emitter = emission.NewEmitter().
		RecoverWith(recoverEmitter).
		SetMaxListeners(emitterMaxListeners)

	// Start the event loops on init.
	bitmonster.OnInit(func() {
		go listenForUserChangesLoop()
	})
}
Example #2
0
func init() {
	// Register the custom type to gob.
	gob.Register(new(authToken))

	bitmonster.OnInit(func() {
		// Create a new secure cookie object with the cookie keys
		secureCookie = securecookie.New([]byte(settings.Settings.AuthHashKey), []byte(settings.Settings.AuthBlockKey))

		// Set the max age in seconds
		secureCookie.MaxAge(settings.Settings.AuthSessionMaxAge)
	})
}
Example #3
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())
}