Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Devrim Gunyel
core
Commits
e4acff90
Commit
e4acff90
authored
Jan 30, 2019
by
Piotr Gawron
Browse files
sessionStorage is used instead of cookies for storing session data
parent
f057635f
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
frontend-js/package-lock.json
View file @
e4acff90
This diff is collapsed.
Click to expand it.
frontend-js/package.json
View file @
e4acff90
...
...
@@ -35,6 +35,7 @@
"log4js-memory-appender"
:
"1.0.5"
,
"mkdirp"
:
"^0.5.1"
,
"mocha"
:
"^3.5.3"
,
"mock-local-storage"
:
"^1.1.8"
,
"molart"
:
"1.2.1"
,
"uglifyjs"
:
"^2.4.10"
},
...
...
frontend-js/src/main/js/ServerConnector.js
View file @
e4acff90
...
...
@@ -1814,7 +1814,6 @@ ServerConnector.login = function (login, password) {
if
(
data
[
"
login
"
]
!==
undefined
)
{
params
.
login
=
data
[
"
login
"
];
}
console
.
log
(
params
.
login
);
self
.
getSessionData
().
setLogin
(
params
.
login
);
return
Promise
.
resolve
(
self
.
getSessionData
().
getToken
());
},
function
(
error
)
{
...
...
@@ -1829,8 +1828,7 @@ ServerConnector.login = function (login, password) {
ServerConnector
.
logout
=
function
()
{
var
self
=
this
;
return
self
.
sendGetRequest
(
self
.
logoutUrl
()).
then
(
function
()
{
self
.
getSessionData
().
setToken
(
undefined
);
self
.
getSessionData
().
setLogin
(
undefined
);
self
.
getSessionData
().
clear
();
window
.
location
.
reload
(
false
);
});
};
...
...
frontend-js/src/main/js/SessionData.js
View file @
e4acff90
...
...
@@ -5,8 +5,7 @@
var
Point
=
require
(
'
./map/canvas/Point
'
);
var
SessionObjectType
=
require
(
'
./SessionObjectType
'
);
var
Cookies
=
require
(
'
js-cookie
'
);
// noinspection JSUnusedLocalSymbols
var
logger
=
require
(
'
./logger
'
);
/**
...
...
@@ -72,7 +71,7 @@ SessionData.prototype.getProjectId = function () {
*/
SessionData
.
prototype
.
getShowComments
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
SHOW_COMMENT
);
return
Cookies
.
get
(
key
)
===
"
true
"
;
return
window
.
sessionStorage
.
getItem
(
key
)
===
"
true
"
;
};
/**
...
...
@@ -81,7 +80,7 @@ SessionData.prototype.getShowComments = function () {
*/
SessionData
.
prototype
.
setSearchQuery
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
SEARCH_QUERY
);
Cookies
.
set
(
key
,
JSON
.
stringify
(
value
));
window
.
sessionStorage
.
setItem
(
key
,
JSON
.
stringify
(
value
));
};
/**
...
...
@@ -110,11 +109,12 @@ SessionData.prototype.setQuery = function (param) {
*/
SessionData
.
prototype
.
getSearchQuery
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
SEARCH_QUERY
);
var
result
=
Cookies
.
get
(
key
);
if
(
result
!==
undefined
)
{
result
=
JSON
.
parse
(
result
);
var
result
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
result
!==
undefined
&&
result
!==
null
)
{
return
JSON
.
parse
(
result
);
}
else
{
return
undefined
;
}
return
result
;
};
/**
...
...
@@ -123,7 +123,7 @@ SessionData.prototype.getSearchQuery = function () {
*/
SessionData
.
prototype
.
setDrugQuery
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
DRUG_QUERY
);
Cookies
.
set
(
key
,
JSON
.
stringify
(
value
));
window
.
sessionStorage
.
setItem
(
key
,
JSON
.
stringify
(
value
));
};
/**
...
...
@@ -132,11 +132,12 @@ SessionData.prototype.setDrugQuery = function (value) {
*/
SessionData
.
prototype
.
getDrugQuery
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
DRUG_QUERY
);
var
result
=
Cookies
.
get
(
key
);
if
(
result
!==
undefined
)
{
result
=
JSON
.
parse
(
result
);
var
result
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
result
!==
undefined
&&
result
!==
null
)
{
return
JSON
.
parse
(
result
);
}
else
{
return
undefined
;
}
return
result
;
};
/**
...
...
@@ -145,7 +146,7 @@ SessionData.prototype.getDrugQuery = function () {
*/
SessionData
.
prototype
.
setMiRnaQuery
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
MI_RNA_QUERY
);
Cookies
.
set
(
key
,
JSON
.
stringify
(
value
));
window
.
sessionStorage
.
setItem
(
key
,
JSON
.
stringify
(
value
));
};
/**
...
...
@@ -154,11 +155,12 @@ SessionData.prototype.setMiRnaQuery = function (value) {
*/
SessionData
.
prototype
.
getMiRnaQuery
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
MI_RNA_QUERY
);
var
result
=
Cookies
.
get
(
key
);
if
(
result
!==
undefined
)
{
result
=
JSON
.
parse
(
result
);
var
result
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
result
!==
undefined
&&
result
!==
null
)
{
return
JSON
.
parse
(
result
);
}
else
{
return
undefined
;
}
return
result
;
};
/**
...
...
@@ -167,7 +169,7 @@ SessionData.prototype.getMiRnaQuery = function () {
*/
SessionData
.
prototype
.
setChemicalQuery
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
CHEMICAL_QUERY
);
Cookies
.
set
(
key
,
JSON
.
stringify
(
value
));
window
.
sessionStorage
.
setItem
(
key
,
JSON
.
stringify
(
value
));
};
/**
...
...
@@ -176,11 +178,12 @@ SessionData.prototype.setChemicalQuery = function (value) {
*/
SessionData
.
prototype
.
getChemicalQuery
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
CHEMICAL_QUERY
);
var
result
=
Cookies
.
get
(
key
);
if
(
result
!==
undefined
)
{
result
=
JSON
.
parse
(
result
);
var
result
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
result
!==
undefined
&&
result
!==
null
)
{
return
JSON
.
parse
(
result
);
}
else
{
return
undefined
;
}
return
result
;
};
/**
...
...
@@ -189,7 +192,7 @@ SessionData.prototype.getChemicalQuery = function () {
*/
SessionData
.
prototype
.
setShowComments
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
SHOW_COMMENT
);
Cookies
.
set
(
key
,
value
+
""
);
window
.
sessionStorage
.
setItem
(
key
,
value
+
""
);
};
/**
...
...
@@ -198,7 +201,12 @@ SessionData.prototype.setShowComments = function (value) {
*/
SessionData
.
prototype
.
getSelectedBackgroundOverlay
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
SELECTED_BACKGROUND_OVERLAY
);
return
Cookies
.
get
(
key
);
var
result
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
result
!==
undefined
&&
result
!==
null
)
{
return
parseInt
(
result
);
}
else
{
return
undefined
;
}
};
/**
...
...
@@ -207,7 +215,7 @@ SessionData.prototype.getSelectedBackgroundOverlay = function () {
*/
SessionData
.
prototype
.
setSelectedBackgroundOverlay
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
SELECTED_BACKGROUND_OVERLAY
);
Cookies
.
set
(
key
,
value
+
""
);
window
.
sessionStorage
.
setItem
(
key
,
value
+
""
);
};
/**
...
...
@@ -216,13 +224,16 @@ SessionData.prototype.setSelectedBackgroundOverlay = function (value) {
*/
SessionData
.
prototype
.
getVisibleOverlays
=
function
()
{
var
key
=
this
.
getKey
(
SessionObjectType
.
VISIBLE_OVERLAYS
);
var
value
=
Cookies
.
get
(
key
);
if
(
value
===
undefined
||
value
===
""
)
{
value
=
[];
var
value
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
value
===
undefined
||
value
===
null
||
value
===
""
)
{
return
[];
}
else
{
value
=
value
.
split
(
"
,
"
);
var
result
=
[];
value
.
split
(
"
,
"
).
forEach
(
function
(
element
)
{
result
.
push
(
parseInt
(
element
));
});
return
result
;
}
return
value
;
};
/**
...
...
@@ -231,7 +242,7 @@ SessionData.prototype.getVisibleOverlays = function () {
*/
SessionData
.
prototype
.
setVisibleOverlays
=
function
(
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
VISIBLE_OVERLAYS
);
Cookies
.
set
(
key
,
value
+
""
);
window
.
sessionStorage
.
setItem
(
key
,
value
+
""
);
};
/**
...
...
@@ -241,7 +252,7 @@ SessionData.prototype.setVisibleOverlays = function (value) {
*/
SessionData
.
prototype
.
setZoomLevel
=
function
(
model
,
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
ZOOM_LEVEL
,
[
model
.
getId
()]);
Cookies
.
set
(
key
,
value
+
""
);
window
.
sessionStorage
.
setItem
(
key
,
value
+
""
);
};
/**
...
...
@@ -251,11 +262,12 @@ SessionData.prototype.setZoomLevel = function (model, value) {
*/
SessionData
.
prototype
.
getZoomLevel
=
function
(
model
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
ZOOM_LEVEL
,
[
model
.
getId
()]);
var
value
=
Cookies
.
get
(
key
);
if
(
value
!==
undefined
)
{
value
=
parseInt
(
value
);
var
value
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
value
!==
undefined
&&
value
!==
null
)
{
return
parseInt
(
value
);
}
else
{
return
undefined
;
}
return
value
;
};
/**
...
...
@@ -264,10 +276,10 @@ SessionData.prototype.getZoomLevel = function (model) {
*/
SessionData
.
prototype
.
setToken
=
function
(
token
)
{
var
key
=
SessionObjectType
.
TOKEN
;
if
(
token
===
undefined
)
{
Cookies
.
remove
(
key
);
if
(
token
===
undefined
||
token
===
null
)
{
window
.
sessionStorage
.
remove
Item
(
key
);
}
else
{
Cookies
.
set
(
key
,
token
);
window
.
sessionStorage
.
setItem
(
key
,
token
);
}
};
...
...
@@ -277,7 +289,7 @@ SessionData.prototype.setToken = function (token) {
*/
SessionData
.
prototype
.
getToken
=
function
()
{
var
key
=
SessionObjectType
.
TOKEN
;
return
Cookies
.
get
(
key
);
return
window
.
sessionStorage
.
getItem
(
key
);
};
/**
...
...
@@ -286,10 +298,10 @@ SessionData.prototype.getToken = function () {
*/
SessionData
.
prototype
.
setLogin
=
function
(
login
)
{
var
key
=
SessionObjectType
.
LOGIN
;
if
(
login
===
undefined
)
{
Cookies
.
remove
(
key
);
if
(
login
===
undefined
||
login
===
null
)
{
window
.
sessionStorage
.
remove
Item
(
key
);
}
else
{
Cookies
.
set
(
key
,
login
);
window
.
sessionStorage
.
setItem
(
key
,
login
);
}
};
...
...
@@ -299,7 +311,7 @@ SessionData.prototype.setLogin = function (login) {
*/
SessionData
.
prototype
.
getLogin
=
function
()
{
var
key
=
SessionObjectType
.
LOGIN
;
return
Cookies
.
get
(
key
);
return
window
.
sessionStorage
.
getItem
(
key
);
};
/**
...
...
@@ -309,7 +321,7 @@ SessionData.prototype.getLogin = function () {
*/
SessionData
.
prototype
.
setCenter
=
function
(
model
,
value
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
CENTER
,
[
model
.
getId
()]);
Cookies
.
set
(
key
,
value
.
x
+
"
,
"
+
value
.
y
);
window
.
sessionStorage
.
setItem
(
key
,
value
.
x
+
"
,
"
+
value
.
y
);
};
/**
...
...
@@ -319,12 +331,13 @@ SessionData.prototype.setCenter = function (model, value) {
*/
SessionData
.
prototype
.
getCenter
=
function
(
model
)
{
var
key
=
this
.
getKey
(
SessionObjectType
.
CENTER
,
[
model
.
getId
()]);
var
value
=
Cookies
.
get
(
key
);
if
(
value
!==
undefined
)
{
var
value
=
window
.
sessionStorage
.
getItem
(
key
);
if
(
value
!==
undefined
&&
value
!==
null
)
{
var
tmp
=
value
.
split
(
"
,
"
);
value
=
new
Point
(
tmp
[
0
],
tmp
[
1
]);
return
new
Point
(
tmp
[
0
],
tmp
[
1
]);
}
else
{
return
undefined
;
}
return
value
;
};
/**
...
...
@@ -343,4 +356,8 @@ SessionData.prototype.getKey = function (type, args) {
return
type
+
"
_
"
+
this
.
getProjectId
()
+
"
_
"
+
args
.
join
(
"
_
"
);
};
SessionData
.
prototype
.
clear
=
function
()
{
window
.
sessionStorage
.
clear
();
};
module
.
exports
=
SessionData
;
frontend-js/src/main/js/map/overlay/SearchDbOverlay.js
View file @
e4acff90
...
...
@@ -237,7 +237,6 @@ SearchDbOverlay.prototype.searchByCoordinates = function (params) {
ServerConnector
.
getSessionData
().
setSearchQuery
(
query
);
console
.
log
(
zoom
);
if
(
self
.
_elementsByQuery
[
query
]
!==
undefined
)
{
self
.
setQueries
([
query
]);
return
self
.
callListeners
(
'
onSearch
'
,
{
...
...
frontend-js/src/test/js/helper.js
View file @
e4acff90
...
...
@@ -33,7 +33,6 @@ var SearchDbOverlay = require("../../main/js/map/overlay/SearchDbOverlay");
var
ServerConnector
=
require
(
"
../../main/js/ServerConnector
"
);
var
User
=
require
(
"
../../main/js/map/data/User
"
);
var
Cookies
=
require
(
'
js-cookie
'
);
var
fs
=
require
(
'
fs
'
);
var
Promise
=
require
(
'
bluebird
'
);
...
...
@@ -487,15 +486,14 @@ Helper.prototype.createMarker = function (params) {
* Changes url but saves the cookies.
*/
Helper
.
prototype
.
setUrl
=
function
(
url
)
{
var
cookies
=
Cookies
.
get
();
global
.
dom
.
reconfigure
({
url
:
url
});
for
(
var
cookie
in
cookies
)
{
if
(
cookies
.
hasOwnProperty
(
cookie
))
{
Cookies
.
set
(
cookie
,
cookies
[
cookie
]);
}
}
//
for (var cookie in cookies) {
//
if (cookies.hasOwnProperty(cookie)) {
//
Cookies.set(cookie, cookies[cookie]);
//
}
//
}
GuiConnector
.
init
();
};
...
...
frontend-js/src/test/js/mocha-config.js
View file @
e4acff90
"
use strict
"
;
var
Promise
=
require
(
"
bluebird
"
);
var
Cookies
=
require
(
'
js-cookie
'
);
var
Helper
=
require
(
'
./helper
'
);
...
...
@@ -14,13 +13,6 @@ var path = require('path');
var
logger
=
require
(
'
./logger
'
);
function
removeCookies
()
{
var
cookies
=
Cookies
.
get
();
for
(
var
cookie
in
cookies
)
{
Cookies
.
remove
(
cookie
);
}
}
function
mockBootstrap
()
{
$
.
fn
.
typeahead
=
function
()
{
logger
.
debug
(
"
Mock typeahead function call
"
);
...
...
@@ -56,6 +48,7 @@ before(function () {
global
.
dom
=
new
jsdom
.
JSDOM
();
global
.
window
=
global
.
dom
.
window
;
global
.
document
=
window
.
document
;
require
(
'
mock-local-storage
'
);
global
.
document
.
elementFromPoint
=
function
()
{
};
...
...
@@ -205,10 +198,9 @@ beforeEach(function () {
logger
.
flushBuffer
();
removeCookies
();
ServerConnector
.
init
();
ServerConnector
.
getSessionData
(
null
).
clear
();
ServerConnector
.
getSessionData
(
null
).
setToken
(
"
MOCK_TOKEN_ID
"
);
ServerConnector
.
getSessionData
(
null
).
setLogin
(
"
anonymous
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment