Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
Vereign Client Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
Vereign Client Library
Commits
4d0842c2
Commit
4d0842c2
authored
6 years ago
by
Alexey Lunin
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 505-not-being-loged-out
parents
646b4e55
1c1d62e1
Branches
505-not-being-loged-out
Branches containing commit
Tags
Tags containing commit
1 merge request
!46
Not being loged out from the dashboard after logging out of chrome extension
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
javascript/src/iframe/viamapi-iframe.js
+146
-124
146 additions, 124 deletions
javascript/src/iframe/viamapi-iframe.js
main.go
+32
-58
32 additions, 58 deletions
main.go
with
178 additions
and
182 deletions
javascript/src/iframe/viamapi-iframe.js
+
146
−
124
View file @
4d0842c2
...
@@ -710,25 +710,37 @@ const connection = Penpal.connectToParent({
...
@@ -710,25 +710,37 @@ const connection = Penpal.connectToParent({
});
});
},
},
logout
:
async
()
=>
{
logout
:
async
()
=>
{
const
authenticationPublicKey
=
localStorage
.
getItem
(
"
authenticatedIdentity
"
);
try
{
if
(
!
authenticationPublicKey
||
!
window
.
loadedIdentities
[
authenticationPublicKey
])
{
const
authenticationPublicKey
=
localStorage
.
getItem
(
"
authenticatedIdentity
"
);
if
(
!
authenticationPublicKey
||
!
window
.
loadedIdentities
[
authenticationPublicKey
])
{
return
{
data
:
""
,
code
:
"
400
"
,
status
:
"
Identity not loaded
"
};
}
// Clone headers to be able destroy authentication first.
// We need it because clients should be able reload page right after logout invocation and not wait until request completed
const
headers
=
{...
window
.
viamApi
.
getConfig
().
headers
};
destroyAuthentication
();
return
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
identityLogout
,
{
headers
}
);
}
catch
(
e
)
{
return
{
return
{
data
:
""
,
data
:
""
,
code
:
"
400
"
,
code
:
"
400
"
,
status
:
"
Identity not loaded
"
status
:
e
.
message
};
};
}
}
const
identityLogoutResponse
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
identityLogout
,
null
);
destroyAuthentication
();
return
identityLogoutResponse
;
},
},
identityRestoreAccess
(
restoreAccessIdentity
,
identificator
)
{
identityRestoreAccess
(
restoreAccessIdentity
,
identificator
)
{
return
new
Penpal
.
Promise
(
result
=>
{
return
new
Penpal
.
Promise
(
result
=>
{
...
@@ -1298,80 +1310,23 @@ connection.promise.then(parent => {
...
@@ -1298,80 +1310,23 @@ connection.promise.then(parent => {
}
}
},
50
);
},
50
);
setInterval
(
async
()
=>
{
const
getNewEventsWithoutSession
=
async
()
=>
{
if
(
window
.
currentlyLoadedIdentity
&&
!
anynomousDeviceKeyEventsProcessing
&&
!
window
.
currentlyAuthenticatedIdentity
)
{
anynomousDeviceKeyEventsProcessing
=
true
;
anynomousDeviceKeyEventsProcessing
=
true
;
try
{
try
{
const
executeResult
=
await
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventGetNewEventsWithoutSession
,
null
,
"
devicekey
"
);
const
executeResult
=
await
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventGetNewEventsWithoutSession
,
null
,
"
devicekey
"
);
if
(
executeResult
.
code
===
"
200
"
)
{
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
const
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxDeviceKeyAnonymousEventTime
=
false
;
let
changedMaxDeviceKeyAnonymousEventTime
=
false
;
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
const
event
=
executeResult
.
data
[
i
];
const
event
=
executeResult
.
data
[
i
];
switch
(
event
.
type
)
{
switch
(
event
.
type
)
{
case
"
DeviceConfirmed
"
:
{
case
"
DeviceConfirmed
"
:
{
await
setIdentityInLocalStorage
(
window
.
currentlyLoadedIdentity
);
await
setIdentityInLocalStorage
(
window
.
currentlyLoadedIdentity
);
parent
.
onEvent
(
event
);
parent
.
onEvent
(
event
);
break
;
break
;
}
case
"
QRCodeUpdated
"
:
{
const
actionID
=
event
[
"
actionID
"
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
);
});
break
;
}
case
"
KeyDeleted
"
:
{
const
authenticationPublicKey
=
localStorage
.
getItem
(
"
authenticatedIdentity
"
);
clearPinCodeTtl
(
authenticationPublicKey
);
localStorage
.
removeItem
(
"
uuid
"
);
localStorage
.
removeItem
(
"
token
"
);
localStorage
.
removeItem
(
"
authenticatedIdentity
"
);
delete
window
.
loadedIdentities
[
authenticationPublicKey
];
window
.
currentlyLoadedIdentity
=
null
;
window
.
currentlyAuthenticatedIdentity
=
null
;
window
.
lastTimeGetProfile
=
0
;
destroyIdentityFromLocalStorage
(
authenticationPublicKey
);
break
;
}
default
:
{
parent
.
onEvent
(
event
);
}
}
}
changedMaxDeviceKeyAnonymousEventTime
=
true
;
maxDeviceKeyAnonymousEventTime
=
Math
.
max
(
maxDeviceKeyAnonymousEventTime
,
event
.
stamp
);
}
if
(
changedMaxDeviceKeyAnonymousEventTime
)
{
await
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventUpdateLastViewedWithoutSession
,
null
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
.
toString
());
}
}
}
catch
(
e
)
{
console
.
warn
(
e
);
}
anynomousDeviceKeyEventsProcessing
=
false
;
}
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsDeviceEventsProcessing
===
false
)
{
case
"
QRCodeUpdated
"
:
{
eventsDeviceEventsProcessing
=
true
;
try
{
const
executeResult
=
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
devicekey
"
);
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
const
changedMaxDeviceKeyEventTime
=
false
;
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
const
event
=
executeResult
.
data
[
i
];
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
const
actionID
=
event
[
"
actionID
"
];
const
actionID
=
event
[
"
actionID
"
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
...
@@ -1381,59 +1336,126 @@ connection.promise.then(parent => {
...
@@ -1381,59 +1336,126 @@ connection.promise.then(parent => {
eventCopy
[
"
payloads
"
].
push
(
url
);
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
);
parent
.
onEvent
(
eventCopy
);
});
});
}
else
{
break
;
}
case
"
KeyDeleted
"
:
{
const
authenticationPublicKey
=
localStorage
.
getItem
(
"
authenticatedIdentity
"
);
clearPinCodeTtl
(
authenticationPublicKey
);
localStorage
.
removeItem
(
"
uuid
"
);
localStorage
.
removeItem
(
"
token
"
);
localStorage
.
removeItem
(
"
authenticatedIdentity
"
);
delete
window
.
loadedIdentities
[
authenticationPublicKey
];
window
.
currentlyLoadedIdentity
=
null
;
window
.
currentlyAuthenticatedIdentity
=
null
;
window
.
lastTimeGetProfile
=
0
;
destroyIdentityFromLocalStorage
(
authenticationPublicKey
);
break
;
}
default
:
{
parent
.
onEvent
(
event
);
parent
.
onEvent
(
event
);
}
}
maxDeviceKeyEventTime
=
Math
.
max
(
maxDeviceKeyEventTime
,
event
.
stamp
);
}
}
if
(
changedMaxDeviceKeyEventTime
)
{
changedMaxDeviceKeyAnonymousEventTime
=
true
;
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
=
Math
.
max
(
maxDeviceKeyAnonymousEventTime
,
event
.
stamp
);
maxDeviceKeyEventTime
.
toString
());
}
if
(
changedMaxDeviceKeyAnonymousEventTime
)
{
await
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventUpdateLastViewedWithoutSession
,
null
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
.
toString
());
}
}
}
catch
(
e
)
{
console
.
warn
(
e
);
}
anynomousDeviceKeyEventsProcessing
=
false
;
};
const
getNewDeviceEvents
=
async
()
=>
{
eventsDeviceEventsProcessing
=
true
;
try
{
const
executeResult
=
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
devicekey
"
);
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
const
changedMaxDeviceKeyEventTime
=
false
;
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
const
event
=
executeResult
.
data
[
i
];
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
const
actionID
=
event
[
"
actionID
"
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
);
});
}
else
{
parent
.
onEvent
(
event
);
}
}
maxDeviceKeyEventTime
=
Math
.
max
(
maxDeviceKeyEventTime
,
event
.
stamp
);
}
if
(
changedMaxDeviceKeyEventTime
)
{
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
devicekey
"
,
maxDeviceKeyEventTime
.
toString
());
}
}
}
catch
(
e
)
{
console
.
warn
(
e
);
}
}
eventsDeviceEventsProcessing
=
false
;
}
catch
(
e
)
{
console
.
warn
(
e
);
}
}
eventsDeviceEventsProcessing
=
false
;
};
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsEntityEventsProcessing
===
false
)
{
const
getNewEntityEvents
=
async
()
=>
{
eventsEntityEventsProcessing
=
true
;
eventsEntityEventsProcessing
=
true
;
try
{
try
{
const
executeResult
=
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
entity
"
);
const
executeResult
=
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
entity
"
);
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxEntityEventTime
=
false
;
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
const
event
=
executeResult
.
data
[
i
];
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
const
actionID
=
event
[
"
actionID
"
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxEntityEventTime
=
false
;
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
const
event
=
executeResult
.
data
[
i
];
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
const
actionID
=
event
[
"
actionID
"
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
);
});
continue
;
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
}
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
);
});
parent
.
onEvent
(
event
);
continue
;
changedMaxEntityEventTime
=
true
;
maxEntityEventTime
=
Math
.
max
(
maxEntityEventTime
,
event
.
stamp
);
}
if
(
changedMaxEntityEventTime
)
{
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
entity
"
,
maxEntityEventTime
.
toString
());
}
}
parent
.
onEvent
(
event
);
changedMaxEntityEventTime
=
true
;
maxEntityEventTime
=
Math
.
max
(
maxEntityEventTime
,
event
.
stamp
);
}
if
(
changedMaxEntityEventTime
)
{
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
entity
"
,
maxEntityEventTime
.
toString
());
}
}
}
catch
(
e
)
{
console
.
warn
(
e
);
}
}
eventsEntityEventsProcessing
=
false
;
}
catch
(
e
)
{
console
.
warn
(
e
);
}
eventsEntityEventsProcessing
=
false
;
}
setInterval
(()
=>
{
if
(
window
.
currentlyLoadedIdentity
&&
!
anynomousDeviceKeyEventsProcessing
&&
!
window
.
currentlyAuthenticatedIdentity
)
{
getNewEventsWithoutSession
();
}
if
(
window
.
currentlyAuthenticatedIdentity
)
{
// These functions has to be executed at the same time.
!
eventsDeviceEventsProcessing
&&
getNewDeviceEvents
();
!
eventsEntityEventsProcessing
&&
getNewEntityEvents
();
}
}
},
1000
);
},
1000
);
});
});
This diff is collapsed.
Click to expand it.
main.go
+
32
−
58
View file @
4d0842c2
...
@@ -38,9 +38,17 @@ func buildPenpalMethods() string {
...
@@ -38,9 +38,17 @@ func buildPenpalMethods() string {
prefixes
:=
[]
string
{}
prefixes
:=
[]
string
{}
endPoints
:=
server
.
GetEndPoints
(
prefixes
)
endPoints
:=
server
.
GetEndPoints
(
prefixes
)
result
:=
result
:=
`
"import Penpal from 'penpal';
\n\n
"
+
const encodeResponse = (code, data, status) => {
"export default {
\n
"
return {
code,
data,
status
};
};
export default {
`
methods
:=
generatePenpalRemoteMethods
(
endPoints
)
methods
:=
generatePenpalRemoteMethods
(
endPoints
)
...
@@ -590,31 +598,13 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
...
@@ -590,31 +598,13 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
privateCheckSnippet
:=
`
privateCheckSnippet
:=
`
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) {
if (
result({
!authenticationPublicKey ||
"data" : "",
!window.loadedIdentities[authenticationPublicKey] ||
"code" : "400",
!extendPinCodeTtl(authenticationPublicKey)
"status" : "Identity not authenticated"
) {
});
return encodeResponse("400", "", "Identity not authenticated");
}
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
const success = extendPinCodeTtl(authenticationPublicKey);
if(success === false) {
result({"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
})
}
`
`
for
i
:=
0
;
i
<
keysLen
;
i
++
{
for
i
:=
0
;
i
<
keysLen
;
i
++
{
...
@@ -626,24 +616,14 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
...
@@ -626,24 +616,14 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
if
url
==
"/identity/getIdentityProfileData"
{
if
url
==
"/identity/getIdentityProfileData"
{
privateCheckSnippet
=
`
privateCheckSnippet
=
`
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) {
if (
result({
!authenticationPublicKey ||
"data" : "",
!window.loadedIdentities[authenticationPublicKey]
"code" : "400",
) {
"status" : "Identity not authenticated"
return encodeResponse("400", "", "Identity not authenticated");
});
}
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
`
`
}
}
...
@@ -685,12 +665,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
...
@@ -685,12 +665,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
lastComma
=
""
lastComma
=
""
}
}
method
:=
packageStr
+
strings
.
Title
(
methodStr
)
+
": function("
+
args
+
") {
\n
"
+
method
:=
packageStr
+
strings
.
Title
(
methodStr
)
+
": async function("
+
args
+
") {
\n
"
+
" return new Penpal.Promise(function(result) {
\n
"
+
snippet
+
snippet
+
" executeRestfulFunction(
\"
"
+
endPoints
[
url
]
.
HandlerType
+
"
\"
, viamApi, viamApi."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
", null"
+
lastComma
+
args
+
").then(function(executeResult) {
\n
"
+
" return await executeRestfulFunction(
\"
"
+
endPoints
[
url
]
.
HandlerType
+
"
\"
, viamApi, viamApi."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
", null"
+
lastComma
+
args
+
");
\n
"
+
" result(executeResult);
\n
"
+
" });
\n
"
+
" });
\n
"
+
"}"
"}"
methods
+=
method
methods
+=
method
...
@@ -713,12 +690,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
...
@@ -713,12 +690,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
snippet
=
privateCheckSnippet
snippet
=
privateCheckSnippet
}
}
method
:=
packageStr
+
strings
.
Title
(
methodStr
)
+
": function() {
\n
"
+
method
:=
packageStr
+
strings
.
Title
(
methodStr
)
+
": async function() {
\n
"
+
" return new Penpal.Promise(function(result) {
\n
"
+
snippet
+
snippet
+
" executeRestfulFunction(
\"
"
+
endPoints
[
url
]
.
HandlerType
+
"
\"
, viamApi, viamApi."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
", null).then(function(executeResult) {
\n
"
+
" return await executeRestfulFunction(
\"
"
+
endPoints
[
url
]
.
HandlerType
+
"
\"
, viamApi, viamApi."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
", null);
\n
"
+
" result(executeResult);
\n
"
+
" });
\n
"
+
" });
\n
"
+
"}"
"}"
methods
+=
method
methods
+=
method
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment