Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web-ui
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WEBGDE-Components
web-ui
Commits
5ec06f93
Commit
5ec06f93
authored
Jan 20, 2023
by
Jorem Magcawas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return element upon logout
parent
e7d704ba
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
120 additions
and
223 deletions
+120
-223
config.js
WebGde/WebContent/config.js
+5
-2
keycloak-login.js
WebGde/WebContent/keycloak-login.js
+1
-177
bpoService.js
WebGde/WebContent/src/BPO/bpoService.js
+1
-0
getElement.js
WebGde/WebContent/src/BPO/getElement.js
+2
-0
returnElement.js
WebGde/WebContent/src/BPO/returnElement.js
+16
-1
accessFile.js
WebGde/WebContent/src/accessFile/accessFile.js
+1
-1
endSession.js
WebGde/WebContent/src/endSession/endSession.js
+73
-39
style.css
WebGde/WebContent/style.css
+21
-3
No files found.
WebGde/WebContent/config.js
View file @
5ec06f93
...
...
@@ -52,4 +52,8 @@ var BPO_URL = "http://35.169.23.0:8080/bpo/"
var
CURRENT_NODE
=
"Web GDE"
var
ENCODING_PASS
=
"PASS1"
var
NEXT_NODE
=
"Complete"
var
EXCEPTION_NODE
=
"Exception"
\ No newline at end of file
var
EXCEPTION_NODE
=
"Exception"
//KEYCLOAK CONFIG
const
REDIRECT_URL
=
'http://auth-server/auth/realms/GFS/protocol/openid-connect/logout?redirect_uri=encodedRedirectUri'
;
WebGde/WebContent/keycloak-login.js
View file @
5ec06f93
...
...
@@ -33,15 +33,11 @@ var appID;
var
app
;
// #NODES
const
REDIRECT_URL
=
'http://auth-server/auth/realms/GFS/protocol/openid-connect/logout?redirect_uri=encodedRedirectUri'
;
const
kc
=
Keycloak
();
var
updateProfile
=
function
()
{
console
.
log
(
kc
.
token
);
login_userData
.
access_token
=
kc
.
tokenParsed
;
login_userData
.
id_token
=
kc
.
idTokenParsed
;
setUser
();
setRoles
();
setApps
();
}
kc
.
onAuthRefreshSuccess
=
function
()
{
...
...
@@ -94,9 +90,7 @@ kc.init(initOptions).then(function (authenticated) {
if
(
!
authenticated
)
{
console
.
warn
(
'Not authenticated'
);
}
else
{
// updateProfile();
// refreshImage();
//set email
}
}).
catch
(
function
()
{
console
.
info
(
'Init Error'
);
...
...
@@ -160,175 +154,5 @@ function getkcToken() {
}
function
setUser
()
{
console
.
log
(
'setting up user'
);
login_userData
.
username
=
kc
.
tokenParsed
[
'preferred_username'
];
login_userData
.
fname
=
kc
.
tokenParsed
[
'given_name'
];
login_userData
.
name
=
kc
.
tokenParsed
[
'name'
];
login_userData
.
wid
=
kc
.
tokenParsed
[
'wid'
];
login_userData
.
jti
=
kc
.
tokenParsed
[
'jti'
]
}
function
setRoles
()
{
console
.
log
(
'setting up roles'
);
var
myobj
=
kc
.
tokenParsed
[
'resource_access'
];
console
.
log
(
myobj
);
$
.
each
(
myobj
,
function
(
index
,
object
)
{
console
.
log
(
'i: '
+
index
);
if
(
appID
.
length
>
0
&&
appID
==
index
)
{
console
.
log
(
appID
);
for
(
var
property
in
object
)
{
if
(
property
==
"roles"
)
{
var
approles
=
object
[
property
];
for
(
var
item
in
approles
)
{
var
roleId
=
approles
[
item
];
var
role
=
{
'roleId'
:
roleId
,
'roleName'
:
roleId
}
login_userData
.
roles
.
push
(
role
);
}
}
}
}
});
}
function
setApps
()
{
var
clientAttributes
=
[];
var
myobj
=
kc
.
tokenParsed
[
'resource_access'
];
var
realmObj
=
kc
.
tokenParsed
[
'realm_access'
];
var
realmRoles
=
realmObj
[
'roles'
];
//get the apps
$
.
each
(
myobj
,
function
(
index
,
object
)
{
console
.
log
(
'app: '
+
index
);
var
appIcon
=
''
;
var
appUrl
=
''
;
//filter out application 'account' as this is a keycloak application
if
(
index
!==
"account"
)
{
//we use keycloak realm roles to store the url and icons of the apps in the apprdrawer
//as keycloak doesnt have attributes for clients/applications to hold these two
$
.
each
(
realmRoles
,
function
(
i
,
o
)
{
if
(
o
.
includes
(
index
)
&&
o
.
includes
(
"url"
))
{
appUrl
=
o
.
split
(
"url-"
)[
1
];
}
if
(
o
.
includes
(
index
)
&&
o
.
includes
(
"icon"
))
{
appIcon
=
o
.
split
(
"icon-"
)[
1
];
}
})
app
=
{
'id'
:
index
,
'name'
:
index
,
'icon'
:
appIcon
,
'url'
:
appUrl
}
if
(
appUrl
.
length
>
0
)
{
login_userData
.
apps
.
push
(
app
);
}
}
});
}
function
setUserRoleAndApps
(
appid
)
{
appID
=
appid
;
setRoles
();
setApps
();
}
function
createjwt
(
role
)
{
const
header
=
{
"alg"
:
ALG
}
var
stringifiedHeader
=
CryptoJS
.
enc
.
Utf8
.
parse
(
JSON
.
stringify
(
header
));
var
encodedHeader
=
base64url
(
stringifiedHeader
);
const
data
=
{
"jti"
:
login_userData
.
jti
,
"iss"
:
"sso"
,
"sub"
:
"authorized"
,
"usr"
:
login_userData
.
username
.
toUpperCase
(),
"wid"
:
login_userData
.
wid
,
"rol"
:
[
role
],
"app"
:
[
app
.
id
],
"iat"
:
timestampIssued
(
getDate
()),
"exp"
:
timestampExpired
(
getDate
(),
TIMEOUT
)
}
var
stringifiedData
=
CryptoJS
.
enc
.
Utf8
.
parse
(
JSON
.
stringify
(
data
));
var
encodedData
=
base64url
(
stringifiedData
);
var
token
=
encodedHeader
+
"."
+
encodedData
;
var
secret
=
CryptoJS
.
enc
.
Base64
.
parse
(
SECRET
)
var
signature
=
CryptoJS
.
HmacSHA256
(
token
,
secret
);
var
base64sign
=
base64url
(
signature
);
var
signedToken
=
token
+
"."
+
base64sign
;
return
signedToken
;
}
function
base64url
(
source
)
{
// Encode in classical base64
encodedSource
=
CryptoJS
.
enc
.
Base64
.
stringify
(
source
);
// Remove padding equal characters
encodedSource
=
encodedSource
.
replace
(
/=+$/
,
''
);
// Replace characters according to base64url specifications
encodedSource
=
encodedSource
.
replace
(
/
\+
/g
,
'-'
);
encodedSource
=
encodedSource
.
replace
(
/
\/
/g
,
'_'
);
return
encodedSource
;
}
function
setCookie
(
token
)
{
var
cookie
=
'access_token='
+
token
+
';'
+
'Path=/;Secure;HttpOnly'
;
document
.
cookie
=
cookie
;
}
function
encryptedjson
(
role
)
{
var
jwt
=
createjwt
(
role
);
return
jwt
;
}
function
getDate
()
{
const
date
=
new
Date
();
return
date
;
}
function
timestampIssued
(
dt
)
{
const
unix
=
Math
.
round
(
+
dt
/
1000
);
return
unix
;
}
function
timestampExpired
(
dt
,
seconds
)
{
dt
.
setSeconds
(
dt
.
getSeconds
()
+
seconds
);
const
unix
=
Math
.
round
(
+
dt
/
1000
);
return
unix
;
}
WebGde/WebContent/src/BPO/bpoService.js
View file @
5ec06f93
...
...
@@ -6,6 +6,7 @@ let urlCompleteToNextNode = BPO_URL + `req/workers/{{USER_ID}}/nodes/${CURRENT_N
let
urlGetWorkersCurrentNode
=
BPO_URL
+
`req/nodes/
${
CURRENT_NODE
}
/workers`
let
urlRejectElement
=
BPO_URL
+
`req/nodes/
${
CURRENT_NODE
}
/elements/{{elementId}}?newNodeId={{newNodeId}}`
;
function
getUrlReturnElement
(
element_id
)
{
let
url
=
urlReturnElement
.
replace
(
"{{USER_ID}}"
,
sessionStorage
.
getItem
(
"user_id"
));
url
=
url
.
replace
(
"{{ELEMENT_ID}}"
,
element_id
);
...
...
WebGde/WebContent/src/BPO/getElement.js
View file @
5ec06f93
...
...
@@ -12,6 +12,8 @@ async function initGetElement() {
if
(
xml
.
isExisting
)
{
const
xmlString
=
await
[...
xml
.
data
].
join
(
''
).
replace
(
'
\
t'
,
''
);
const
lastImage
=
getXmlLastImage
(
xmlString
);
console
.
log
(
'xmlString:'
+
xmlString
);
sessionStorage
.
setItem
(
'section'
,
getXmlSection
(
xmlString
));
sessionStorage
.
setItem
(
'doctype'
,
getXmlDocType
(
xmlString
));
...
...
WebGde/WebContent/src/BPO/returnElement.js
View file @
5ec06f93
...
...
@@ -4,10 +4,25 @@ async function returnElementBPO(elementId) {
if
(
response
.
status
==
200
)
{
await
loadWaitingElement
();
init
();
alert
(
"Element Returned"
);
console
.
log
(
'Element Returned'
);
}
else
{
alert
(
`Error
${
response
.
status
}
: Returning element`
);
}
return
response
.
status
;
}
async
function
returnElementLogout
(
elementId
)
{
let
response
=
await
fetch
(
getUrlReturnElement
(
elementId
),
{
method
:
"POST"
});
if
(
response
.
status
==
200
)
{
console
.
log
(
'Element Returned'
);
}
else
{
alert
(
`Error
${
response
.
status
}
: Returning element`
);
logoutKeycloak
();
}
return
response
.
status
;
}
var
returnButton
=
document
.
getElementById
(
'return'
);
...
...
WebGde/WebContent/src/accessFile/accessFile.js
View file @
5ec06f93
...
...
@@ -248,7 +248,7 @@ async function accessFile() {
if
(
IS_RETRIEVE_FROM_GFS
==
"Y"
){
const
modal
=
document
.
getElementById
(
"TiffViewerModal"
);
modal
.
style
.
display
=
'none'
;
//hide local modal\
getFolder
(
FOLDER_URL
+
sessionStorage
.
getItem
(
'user_id'
)
+
'/element
5
'
);
getFolder
(
FOLDER_URL
+
sessionStorage
.
getItem
(
'user_id'
)
+
'/element
1
'
);
}
else
{
if
((
localStorage
.
length
)
==
0
){
if
(
updated_input_files
.
length
==
0
){
...
...
WebGde/WebContent/src/endSession/endSession.js
View file @
5ec06f93
// var submitted = false;
const
form
=
document
.
getElementById
(
"fields"
);
const
sidebar
=
document
.
getElementById
(
"sidebar"
);
let
closerWindow
;
// form.addEventListener('submit', (e)=>{
// submitted = true;
// })
endButton
=
document
.
createElement
(
"button"
);
endButton
.
id
=
"endBtn"
;
endButton
.
innerHTML
=
"End Session"
;
...
...
@@ -17,7 +12,6 @@ endDiv.append(endButton);
sidebar
.
append
(
endDiv
);
//checks if form is empty
function
checkForm
(
form
){
var
inputs
=
form
.
getElementsByTagName
(
"input"
);
var
selects
=
form
.
getElementsByTagName
(
"select"
);
...
...
@@ -34,37 +28,78 @@ function checkForm(form){
if
(
inputsBlankCount
==
0
&&
selectsBlankCount
==
0
)
return
true
;
}
//deletes the indexedDB if form is submitted or form is empty
endButton
.
addEventListener
(
"click"
,
function
(){
//clear localStorage
localStorage
.
clear
();
sessionStorage
.
clear
();
endButton
.
addEventListener
(
"click"
,
function
(){
let
endWindow
=
document
.
getElementById
(
'end_window'
);
endWindow
.
style
.
display
=
'block'
;
});
//if form is submitted or fields are blank, delete database
if
(
checkForm
(
form
)){
var
DBdeleteRequest
=
window
.
indexedDB
.
deleteDatabase
(
"ImageDatabase"
);
DBdeleteRequest
.
addEventListener
(
'blocked'
,
function
(
e
){
console
.
log
(
"Database cleared."
);
//closerWindow = window.open("closer.html", '_self');
});
DBdeleteRequest
.
addEventListener
(
'upgradeneeded'
,
function
(
e
){
console
.
log
(
"Upgrade needed in deleting database"
);
});
DBdeleteRequest
.
addEventListener
(
'error'
,
function
(
e
){
console
.
log
(
"Error in deleting database"
);
});
DBdeleteRequest
.
addEventListener
(
'success'
,
function
(
e
){
console
.
log
(
"Database cleared."
);
//closerWindow = window.open("closer.html", '_self');
});
createEndSessionWindow
();
logoutKeycloak
();
//resets the the boolean checker if data is submitted
submitted
=
false
;
}
//if form is not empty but "End Session" button is pressed without submitting the form
else
{
alert
(
"Fields are not empty. Submit or clear fields first."
);
}
});
\ No newline at end of file
function
createEndSessionWindow
(){
let
endWindow
=
document
.
createElement
(
'div'
);
endWindow
.
id
=
'end_window'
;
endWindow
.
style
.
display
=
'none'
;
document
.
body
.
appendChild
(
endWindow
);
let
endBodyDiv
=
document
.
createElement
(
'div'
);
endBodyDiv
.
id
=
'endBodyDiv'
;
let
endLabel
=
document
.
createElement
(
'p'
);
endLabel
.
innerText
=
"Session will end. Current Element will be Returned."
;
let
endContinue
=
document
.
createElement
(
'p'
);
endContinue
.
innerText
=
"Continue Y/N?"
;
let
endOkCnclDiv
=
document
.
createElement
(
'div'
);
endOkCnclDiv
.
id
=
'endOkCnclCont'
;
let
okEnd
=
document
.
createElement
(
'button'
);
okEnd
.
innerHTML
=
'ok'
;
okEnd
.
id
=
'okEndButtn'
;
okEnd
.
onclick
=
async
function
()
{
if
(
checkForm
(
form
)){
var
DBdeleteRequest
=
window
.
indexedDB
.
deleteDatabase
(
"ImageDatabase"
);
DBdeleteRequest
.
addEventListener
(
'blocked'
,
function
(
e
){
console
.
log
(
"Database cleared."
);
});
DBdeleteRequest
.
addEventListener
(
'upgradeneeded'
,
function
(
e
){
console
.
log
(
"Upgrade needed in deleting database"
);
});
DBdeleteRequest
.
addEventListener
(
'error'
,
function
(
e
){
console
.
log
(
"Error in deleting database"
);
});
DBdeleteRequest
.
addEventListener
(
'success'
,
function
(
e
){
console
.
log
(
"Database cleared."
);
});
let
returnElem
=
await
returnElementLogout
(
sessionStorage
.
getItem
(
"element_id"
));
if
(
returnElem
==
200
){
endWindow
.
style
.
display
=
'none'
;
localStorage
.
clear
();
sessionStorage
.
clear
();
logoutKeycloak
();
submitted
=
false
;
}
}
else
{
alert
(
"Fields are not empty. Submit or clear fields first."
);
}
endWindow
.
style
.
display
=
'none'
;
}
let
cancelEnd
=
document
.
createElement
(
'button'
);
cancelEnd
.
innerHTML
=
'cancel'
;
cancelEnd
.
id
=
'cnclEndButton'
;
cancelEnd
.
onclick
=
function
()
{
endWindow
.
style
.
display
=
'none'
;
}
endOkCnclDiv
.
appendChild
(
okEnd
);
endOkCnclDiv
.
appendChild
(
cancelEnd
);
endBodyDiv
.
appendChild
(
endLabel
);
endBodyDiv
.
appendChild
(
endContinue
);
endBodyDiv
.
appendChild
(
endOkCnclDiv
);
endWindow
.
appendChild
(
endBodyDiv
);
}
WebGde/WebContent/style.css
View file @
5ec06f93
...
...
@@ -527,7 +527,7 @@ select {
width
:
200px
;
border
:
1px
solid
;
position
:
absolute
;
top
:
calc
(
50%
-
83
px
);
top
:
calc
(
50%
-
122
px
);
transform
:
translate
(
0
,
-50%
);
left
:
calc
(
50%
-
100px
);
transform
:
translate
(
-50%
,
0
);
...
...
@@ -562,4 +562,23 @@ select {
#text-area
{
margin-left
:
3px
;
margin-bottom
:
3px
;
}
\ No newline at end of file
}
#end_window
{
text-align
:
center
;
height
:
120px
;
width
:
400px
;
border
:
1px
solid
;
position
:
absolute
;
top
:
calc
(
50%
-
60px
);
transform
:
translate
(
0
,
-50%
);
left
:
calc
(
50%
-
200px
);
transform
:
translate
(
-50%
,
0
);
padding
:
10px
;
background-color
:
white
;
}
#endOkCnclCont
>
button
{
margin
:
5px
;
}
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