Skip to content

Commit ca5417c

Browse files
committed
refactor
1 parent b675523 commit ca5417c

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

services/static-webserver/client/source/class/osparc/TooSmallDialog.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ qx.Class.define("osparc.TooSmallDialog", {
6969
button.addListener("execute", () => qx.core.Init.getApplication().logout());
7070
layout.add(button);
7171

72-
const authManager = osparc.auth.Manager.getInstance();
73-
authManager.bind("loggedIn", layout, "visibility", {
72+
authData.bind("loggedIn", layout, "visibility", {
7473
converter: isLoggedIn => isLoggedIn ? "visible" : "excluded"
7574
});
7675

services/static-webserver/client/source/class/osparc/auth/Data.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ qx.Class.define("osparc.auth.Data", {
5858
auth: {
5959
init: null,
6060
nullable: true,
61-
check: "osparc.io.request.authentication.Token"
61+
check: "osparc.io.request.authentication.Token",
62+
apply: "__applyAuth"
6263
},
6364

6465
/**
@@ -104,10 +105,21 @@ qx.Class.define("osparc.auth.Data", {
104105
nullable: true,
105106
check: "Date",
106107
event: "changeExpirationDate"
108+
},
109+
110+
loggedIn: {
111+
check: "Boolean",
112+
nullable: false,
113+
init: false,
114+
event: "changeLoggedIn",
107115
}
108116
},
109117

110118
members: {
119+
__applyAuth: function(auth) {
120+
this.setLoggedIn(auth !== null && auth instanceof osparc.io.request.authentication.Token);
121+
},
122+
111123
__applyRole: function(role) {
112124
if (role && ["user", "tester", "product_owner", "admin"].includes(role)) {
113125
this.setGuest(false);

services/static-webserver/client/source/class/osparc/auth/Manager.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,10 @@ qx.Class.define("osparc.auth.Manager", {
2626
extend: qx.core.Object,
2727
type: "singleton",
2828

29-
construct: function() {
30-
// TODO: how to store this locally?? See http://www.qooxdoo.org/devel/pages/data_binding/stores.html#offline-store
31-
// TODO: check if expired??
32-
// TODO: request server if token is still valid (e.g. expired, etc)
33-
const authData = osparc.auth.Data.getInstance();
34-
authData.bind("auth", this, "loggedIn", {
35-
converter: auth => auth !== null && auth instanceof osparc.io.request.authentication.Token
36-
});
37-
},
38-
3929
events: {
4030
"loggedOut": "qx.event.type.Event"
4131
},
4232

43-
properties: {
44-
loggedIn: {
45-
check: "Boolean",
46-
nullable: false,
47-
init: false,
48-
event: "changeLoggedIn",
49-
}
50-
},
51-
5233
members: {
5334
register: function(userData) {
5435
const params = {
@@ -135,6 +116,14 @@ qx.Class.define("osparc.auth.Manager", {
135116
return osparc.data.Resources.fetch("auth", "resendCode", params);
136117
},
137118

119+
isLoggedIn: function() {
120+
// TODO: how to store this locally?? See http://www.qooxdoo.org/devel/pages/data_binding/stores.html#offline-store
121+
// TODO: check if expired??
122+
// TODO: request server if token is still valid (e.g. expired, etc)
123+
const auth = osparc.auth.Data.getInstance().getAuth();
124+
return auth !== null && auth instanceof osparc.io.request.authentication.Token;
125+
},
126+
138127
/*
139128
* Function that checks if there is a token and validates it against the server.
140129
*/

0 commit comments

Comments
 (0)