96 lines
1.7 KiB
JavaScript
96 lines
1.7 KiB
JavaScript
/**
|
|
* User session
|
|
*/
|
|
export default function UserSession() {
|
|
/** @private @type {string | undefined} */
|
|
this._sessionId = undefined;
|
|
|
|
/** @private @type {string | undefined} */
|
|
this._websiteKey = undefined;
|
|
|
|
/** @private @type {string | undefined} */
|
|
this._imageTag = undefined;
|
|
|
|
|
|
/**
|
|
* Get session identifier
|
|
* @return {string}
|
|
*/
|
|
this.getSessionId = function() {
|
|
return this._sessionId;
|
|
};
|
|
|
|
/**
|
|
* Set session identifier
|
|
* @param {string} sessionId
|
|
*/
|
|
this.setSessionId = function(sessionId) {
|
|
this._sessionId = sessionId;
|
|
};
|
|
|
|
|
|
/**
|
|
* Get website key
|
|
* @return {string}
|
|
*/
|
|
this.getWebsiteKey = function() {
|
|
return this._websiteKey;
|
|
};
|
|
|
|
/**
|
|
* Set website key
|
|
* @param {string} websiteKey
|
|
*/
|
|
this.setWebsiteKey = function(websiteKey) {
|
|
this._websiteKey = websiteKey;
|
|
};
|
|
|
|
|
|
/**
|
|
* Get image tag as text
|
|
* @return {string}
|
|
*/
|
|
this.getImageTag = function() {
|
|
return this._imageTag;
|
|
};
|
|
|
|
/**
|
|
* Set image tag as text
|
|
* @param {string} imageObject
|
|
*/
|
|
this.setImageTag = function(imageObject) {
|
|
this._imageTag = imageObject;
|
|
};
|
|
|
|
|
|
/**
|
|
* Serialize the session into a JSON object
|
|
* @return {Array<any>}
|
|
*/
|
|
this.serialize = function() {
|
|
const sessionId = this.getSessionId();
|
|
const websiteKey = this.getWebsiteKey();
|
|
const imageTag = this.getImageTag();
|
|
|
|
return [
|
|
sessionId,
|
|
websiteKey,
|
|
imageTag,
|
|
];
|
|
};
|
|
|
|
/**
|
|
* Deserialize session data from JSON object
|
|
* @param {Array<any>} payload
|
|
*/
|
|
this.deserialize = function([
|
|
sessionId,
|
|
websiteKey,
|
|
imageTag,
|
|
]) {
|
|
this.setSessionId(sessionId);
|
|
this.setWebsiteKey(websiteKey);
|
|
this.setImageTag(imageTag);
|
|
};
|
|
}
|