Enonic XP Library for storing attributes on a users session.
Warning This library will not work in clustered environments with multiple instances of XP running, since the state of the user is not replicated.
You can instead use cookies to store attributes related to the user.
To install this library you need to add a new dependency to your app's build.gradle file.
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
include 'no.item:lib-xp-session:1.0.0'
}
After updating the gradle file, you can import the /lib/session
library.
The library includes the following functions:
setAttribute(key, value)
getAttribute(key)
removeAttribute(key)
getAttributeNames()
getId()
getCreationTime()
var sessionLib = require('/lib/session');
exports.get = function() {
sessionLib.setAttribute("myKey", "myValue");
var myValue = sessionLib.getAttribute("myKey"); // "myValue" is returned
...
}
To build he project run the following code
./gradlew build
Deploy locally for testing purposes:
./gradlew publishToMavenLocal
Go to the Jitpack page for lib-xp-session to deploy from Github.