@klauswuestefeld/jux-web 2024.2.6-4 → 2024.2.7-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.d.ts +3 -2
- package/dist/jux-web.js +91 -69
- package/dist/login/base-page.d.ts +1 -0
- package/dist/login/session.d.ts +0 -1
- package/dist/login/unauthorized-magic-link-request-page.d.ts +1 -0
- package/dist/main.esm.js +91 -69
- package/dist/main.js +91 -69
- package/package.json +1 -1
package/dist/api-client.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare const setBackendUrl: (backendUrl: string) => void;
|
|
2
|
+
export declare const getBackendUrl: () => string;
|
|
2
3
|
export declare const handleJuxEvents: (ev: Event) => void;
|
|
3
|
-
export declare const backendRequest: (requestType: string, urlString: string, params: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any) => void;
|
|
4
|
+
export declare const backendRequest: (requestType: string, urlString: string, params: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any, handleUnauthorized?: () => void) => void;
|
|
4
5
|
export declare const backendPost: (endpoint: string, postContent: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any) => void;
|
|
5
6
|
export declare const backendGet: (endpoint: string, params: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any) => void;
|
|
6
|
-
export declare const requestMagicLink: (data: any, onJsonResponse: (response: any) => any) => void;
|
|
7
|
+
export declare const requestMagicLink: (data: any, onJsonResponse: (response: any) => any, onUnauthorized: () => void) => void;
|
|
7
8
|
export declare const openMagicLink: (magicToken: string, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any) => void;
|
|
8
9
|
export declare const googleLogin: (token: string, onLogin: (response: any) => any, onLoginError: (message: string) => any) => void;
|
|
9
10
|
export declare const microsoftLogin: (token: string, onLogin: (response: any) => any, onLoginError: (message: string) => any) => void;
|
package/dist/jux-web.js
CHANGED
|
@@ -196,7 +196,13 @@ var juxWeb = (function (exports) {
|
|
|
196
196
|
const backendHelpMessage = (req) => {
|
|
197
197
|
return req.response && req.response.error || req.response || req;
|
|
198
198
|
};
|
|
199
|
-
const
|
|
199
|
+
const defaultHandleUnauthorized = () => {
|
|
200
|
+
localStorage.removeItem('token');
|
|
201
|
+
alert(getTranslation('session-expired-msg'));
|
|
202
|
+
location.reload();
|
|
203
|
+
// googleAuthSignOut(); TODO
|
|
204
|
+
};
|
|
205
|
+
const backendRequest = (requestType, urlString, params, onJsonResponse, onHelpMessage, handleUnauthorized = defaultHandleUnauthorized) => {
|
|
200
206
|
if (urlString.includes(getBackendUrl())) {
|
|
201
207
|
urlString = urlString.replace(getBackendUrl(), getBackendUrlToTry());
|
|
202
208
|
}
|
|
@@ -219,10 +225,7 @@ var juxWeb = (function (exports) {
|
|
|
219
225
|
req.responseType = 'json';
|
|
220
226
|
req.onerror = req.ontimeout = () => {
|
|
221
227
|
if (req.status === 401) {
|
|
222
|
-
|
|
223
|
-
alert(getTranslation('session-expired-msg'));
|
|
224
|
-
location.reload();
|
|
225
|
-
// googleAuthSignOut(); TODO
|
|
228
|
+
handleUnauthorized();
|
|
226
229
|
}
|
|
227
230
|
else if (req.status === 0) {
|
|
228
231
|
if (retries >= maxRetries) {
|
|
@@ -269,8 +272,10 @@ var juxWeb = (function (exports) {
|
|
|
269
272
|
const backendGet = (endpoint, params, onJsonResponse, onHelpMessage) => {
|
|
270
273
|
backendRequest('GET', getApiUrl() + endpoint, params, onJsonResponse, onHelpMessage);
|
|
271
274
|
};
|
|
272
|
-
const requestMagicLink = (data, onJsonResponse) => {
|
|
273
|
-
|
|
275
|
+
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
276
|
+
const { email, token } = data;
|
|
277
|
+
const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
|
|
278
|
+
backendRequest('GET', url, null, onJsonResponse, console.error, onUnauthorized);
|
|
274
279
|
};
|
|
275
280
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
276
281
|
backendRequest('GET', getMagicAuthUrl() + magicToken, null, onJsonResponse, onHelpMessage);
|
|
@@ -14095,16 +14100,7 @@ var juxWeb = (function (exports) {
|
|
|
14095
14100
|
return result;
|
|
14096
14101
|
};
|
|
14097
14102
|
|
|
14098
|
-
const
|
|
14099
|
-
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
14100
|
-
page.style.display = 'block';
|
|
14101
|
-
page.style.width = '100%';
|
|
14102
|
-
page.style.height = '100%';
|
|
14103
|
-
page.style.backgroundPosition = '50%';
|
|
14104
|
-
page.style.backgroundSize = 'cover';
|
|
14105
|
-
page.style.display = 'block';
|
|
14106
|
-
};
|
|
14107
|
-
const applyContainerStyles$1 = (container) => {
|
|
14103
|
+
const applyContainerStyles = (container) => {
|
|
14108
14104
|
container.style.backgroundColor = '#ffffffdd';
|
|
14109
14105
|
container.style.borderRadius = '16px';
|
|
14110
14106
|
container.style.inset = '50% 50% 50% 0';
|
|
@@ -14120,6 +14116,24 @@ var juxWeb = (function (exports) {
|
|
|
14120
14116
|
container.style.margin = '0 auto';
|
|
14121
14117
|
container.style.paddingTop = '0';
|
|
14122
14118
|
};
|
|
14119
|
+
const applyPageStyles = (page, backgroundImg) => {
|
|
14120
|
+
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
14121
|
+
page.style.backgroundPosition = '50%';
|
|
14122
|
+
page.style.backgroundSize = 'cover';
|
|
14123
|
+
page.style.display = 'block';
|
|
14124
|
+
page.style.height = '100%';
|
|
14125
|
+
};
|
|
14126
|
+
const basePage = (pageName, backgroundImg, content) => {
|
|
14127
|
+
const result = document.createElement(pageName);
|
|
14128
|
+
result.className = 'base-login-page';
|
|
14129
|
+
applyPageStyles(result, backgroundImg);
|
|
14130
|
+
const section = document.createElement('section');
|
|
14131
|
+
applyContainerStyles(section);
|
|
14132
|
+
content.forEach(element => section.appendChild(element));
|
|
14133
|
+
result.appendChild(section);
|
|
14134
|
+
return result;
|
|
14135
|
+
};
|
|
14136
|
+
|
|
14123
14137
|
const applyBtnStyles = (btn) => {
|
|
14124
14138
|
btn.style.cursor = 'pointer';
|
|
14125
14139
|
btn.style.textDecoration = 'underline';
|
|
@@ -14134,22 +14148,20 @@ var juxWeb = (function (exports) {
|
|
|
14134
14148
|
btn.style.font = 'inherit';
|
|
14135
14149
|
};
|
|
14136
14150
|
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
14137
|
-
const
|
|
14138
|
-
const
|
|
14139
|
-
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
14143
|
-
|
|
14144
|
-
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
|
|
14148
|
-
|
|
14149
|
-
|
|
14150
|
-
|
|
14151
|
-
magicLinkHowTo.style.padding = '0 30px';
|
|
14152
|
-
magicLinkHowTo.style.textAlign = 'center';
|
|
14151
|
+
const content = [];
|
|
14152
|
+
const sent = document.createElement('p');
|
|
14153
|
+
sent.id = 'magic-link-sent';
|
|
14154
|
+
sent.textContent = getTranslation(sent.id);
|
|
14155
|
+
sent.style.marginBottom = '10px';
|
|
14156
|
+
const email = document.createElement('p');
|
|
14157
|
+
email.id = 'magic-link-email';
|
|
14158
|
+
email.style.fontWeight = '700';
|
|
14159
|
+
email.style.marginBottom = '10px';
|
|
14160
|
+
const howTo = document.createElement('p');
|
|
14161
|
+
howTo.id = 'magic-link-how-to';
|
|
14162
|
+
howTo.innerHTML = getTranslation(howTo.id);
|
|
14163
|
+
howTo.style.padding = '0 30px';
|
|
14164
|
+
howTo.style.textAlign = 'center';
|
|
14153
14165
|
const btn = document.createElement('button');
|
|
14154
14166
|
btn.id = 'email-not-received-btn';
|
|
14155
14167
|
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
@@ -14165,9 +14177,38 @@ var juxWeb = (function (exports) {
|
|
|
14165
14177
|
returnLink.style.cursor = 'pointer';
|
|
14166
14178
|
returnLink.style.fontWeight = '700';
|
|
14167
14179
|
returnLink.style.textDecoration = 'underline';
|
|
14168
|
-
|
|
14169
|
-
|
|
14170
|
-
result
|
|
14180
|
+
content.push(sent, email, howTo, btn, returnLink);
|
|
14181
|
+
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
14182
|
+
return result;
|
|
14183
|
+
};
|
|
14184
|
+
|
|
14185
|
+
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
14186
|
+
const content = [];
|
|
14187
|
+
const notSent = document.createElement('p');
|
|
14188
|
+
notSent.id = 'magic-link-not-sent';
|
|
14189
|
+
notSent.textContent = getTranslation(notSent.id);
|
|
14190
|
+
notSent.style.marginBottom = '10px';
|
|
14191
|
+
const email = document.createElement('p');
|
|
14192
|
+
email.id = 'magic-link-email';
|
|
14193
|
+
email.style.fontWeight = '700';
|
|
14194
|
+
email.style.marginBottom = '10px';
|
|
14195
|
+
const info = document.createElement('p');
|
|
14196
|
+
info.id = 'magic-link-fail-info';
|
|
14197
|
+
info.innerHTML = getTranslation(info.id);
|
|
14198
|
+
info.style.padding = '0 30px';
|
|
14199
|
+
info.style.textAlign = 'center';
|
|
14200
|
+
const back = document.createElement('a');
|
|
14201
|
+
back.textContent = getTranslation('return-link');
|
|
14202
|
+
back.onclick = () => {
|
|
14203
|
+
result.remove();
|
|
14204
|
+
onReturn();
|
|
14205
|
+
};
|
|
14206
|
+
back.style.marginTop = '32px';
|
|
14207
|
+
back.style.cursor = 'pointer';
|
|
14208
|
+
back.style.fontWeight = '700';
|
|
14209
|
+
back.style.textDecoration = 'underline';
|
|
14210
|
+
content.push(notSent, email, info, back);
|
|
14211
|
+
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
14171
14212
|
return result;
|
|
14172
14213
|
};
|
|
14173
14214
|
|
|
@@ -14192,7 +14233,10 @@ var juxWeb = (function (exports) {
|
|
|
14192
14233
|
};
|
|
14193
14234
|
const clearSession = () => {
|
|
14194
14235
|
// onUserChanged(null);
|
|
14236
|
+
// TODO: find a better way to preserve backend-url
|
|
14237
|
+
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
14195
14238
|
localStorage.clear();
|
|
14239
|
+
setBackendUrl(backendUrl);
|
|
14196
14240
|
// @ts-ignore
|
|
14197
14241
|
window.store = {};
|
|
14198
14242
|
};
|
|
@@ -14319,12 +14363,15 @@ var juxWeb = (function (exports) {
|
|
|
14319
14363
|
}
|
|
14320
14364
|
const payload = { email, token };
|
|
14321
14365
|
const onRequestMagicLink = () => {
|
|
14322
|
-
|
|
14366
|
+
const onResponse = (page) => {
|
|
14323
14367
|
currentPage.remove();
|
|
14324
|
-
clientBody.appendChild(
|
|
14325
|
-
const magicLinkEmail =
|
|
14368
|
+
clientBody.appendChild(page);
|
|
14369
|
+
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
14326
14370
|
magicLinkEmail.textContent = email;
|
|
14327
|
-
}
|
|
14371
|
+
};
|
|
14372
|
+
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
14373
|
+
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
14374
|
+
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
14328
14375
|
};
|
|
14329
14376
|
// @ts-ignore
|
|
14330
14377
|
if (window.store.fetchUserBackendUrl) {
|
|
@@ -14485,28 +14532,6 @@ var juxWeb = (function (exports) {
|
|
|
14485
14532
|
return result;
|
|
14486
14533
|
};
|
|
14487
14534
|
|
|
14488
|
-
const applyContainerStyles = (container) => {
|
|
14489
|
-
container.style.backgroundColor = '#ffffffdd';
|
|
14490
|
-
container.style.borderRadius = '16px';
|
|
14491
|
-
container.style.inset = '50% 50% 50% 0';
|
|
14492
|
-
container.style.position = 'relative';
|
|
14493
|
-
container.style.transform = 'translateY(-50%)';
|
|
14494
|
-
container.style.width = '620px';
|
|
14495
|
-
container.style.alignItems = 'center';
|
|
14496
|
-
container.style.display = 'flex';
|
|
14497
|
-
container.style.flexDirection = 'column';
|
|
14498
|
-
container.style.fontSize = '16px';
|
|
14499
|
-
container.style.height = '100%';
|
|
14500
|
-
container.style.justifyContent = 'center';
|
|
14501
|
-
container.style.margin = '0 auto';
|
|
14502
|
-
container.style.paddingTop = '0';
|
|
14503
|
-
};
|
|
14504
|
-
const applyPageStyles = (page) => {
|
|
14505
|
-
page.style.backgroundPosition = '50%';
|
|
14506
|
-
page.style.backgroundSize = 'cover';
|
|
14507
|
-
page.style.display = 'block';
|
|
14508
|
-
page.style.height = '100%';
|
|
14509
|
-
};
|
|
14510
14535
|
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
14511
14536
|
const onReturn = () => clientApp.appendChild(loginPage);
|
|
14512
14537
|
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
@@ -14526,20 +14551,17 @@ var juxWeb = (function (exports) {
|
|
|
14526
14551
|
}
|
|
14527
14552
|
};
|
|
14528
14553
|
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
14529
|
-
const
|
|
14530
|
-
applyPageStyles(result);
|
|
14531
|
-
const section = document.createElement('section');
|
|
14532
|
-
applyContainerStyles(section);
|
|
14554
|
+
const content = [];
|
|
14533
14555
|
const salutation = document.createElement('sign-in-salutation');
|
|
14534
14556
|
salutation.textContent = getTranslation('sign-in-salutation');
|
|
14535
14557
|
const explanation = document.createElement('sign-in-explanation');
|
|
14536
14558
|
explanation.textContent = getTranslation('sign-in-explanation');
|
|
14537
14559
|
const msg = document.createElement('sign-in-msg');
|
|
14538
14560
|
msg.textContent = getTranslation('sign-in-msg-general');
|
|
14539
|
-
|
|
14540
|
-
|
|
14561
|
+
content.push(salutation, explanation, msg);
|
|
14562
|
+
const result = basePage('login-page', backgroundImg, content);
|
|
14563
|
+
const section = result.querySelector('section');
|
|
14541
14564
|
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
14542
|
-
result.appendChild(section);
|
|
14543
14565
|
return result;
|
|
14544
14566
|
};
|
|
14545
14567
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const basePage: (pageName: string, backgroundImg: string, content: HTMLElement[]) => HTMLElement;
|
package/dist/login/session.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export declare const setBackendToken: (token: string) => void;
|
|
2
2
|
export declare const onTokenAcquired: (token: string, onUserLogin: any) => void;
|
|
3
|
-
export declare const clearSession: () => void;
|
|
4
3
|
export declare const initSession: (clientApp: HTMLElement, supportedLoginTypes: string[], onUserLogin: any, backgroundImage: string, fetchUserBackendUrl: any, magicLinkRequestEndpoint: string | null, magicLinkAuthEndpoint: string | null) => void;
|
|
5
4
|
export declare const onMicrosoftSignIn: (onUserLogin: any) => Promise<void>;
|
|
6
5
|
export declare const onGoogleSignIn: (onUserLogin: any) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const unauthorizedMagicLinkRequestPage: (backgroundImg: string, onReturn: any) => HTMLElement;
|
package/dist/main.esm.js
CHANGED
|
@@ -195,7 +195,13 @@ const removeOverlay = () => {
|
|
|
195
195
|
const backendHelpMessage = (req) => {
|
|
196
196
|
return req.response && req.response.error || req.response || req;
|
|
197
197
|
};
|
|
198
|
-
const
|
|
198
|
+
const defaultHandleUnauthorized = () => {
|
|
199
|
+
localStorage.removeItem('token');
|
|
200
|
+
alert(getTranslation('session-expired-msg'));
|
|
201
|
+
location.reload();
|
|
202
|
+
// googleAuthSignOut(); TODO
|
|
203
|
+
};
|
|
204
|
+
const backendRequest = (requestType, urlString, params, onJsonResponse, onHelpMessage, handleUnauthorized = defaultHandleUnauthorized) => {
|
|
199
205
|
if (urlString.includes(getBackendUrl())) {
|
|
200
206
|
urlString = urlString.replace(getBackendUrl(), getBackendUrlToTry());
|
|
201
207
|
}
|
|
@@ -218,10 +224,7 @@ const backendRequest = (requestType, urlString, params, onJsonResponse, onHelpMe
|
|
|
218
224
|
req.responseType = 'json';
|
|
219
225
|
req.onerror = req.ontimeout = () => {
|
|
220
226
|
if (req.status === 401) {
|
|
221
|
-
|
|
222
|
-
alert(getTranslation('session-expired-msg'));
|
|
223
|
-
location.reload();
|
|
224
|
-
// googleAuthSignOut(); TODO
|
|
227
|
+
handleUnauthorized();
|
|
225
228
|
}
|
|
226
229
|
else if (req.status === 0) {
|
|
227
230
|
if (retries >= maxRetries) {
|
|
@@ -268,8 +271,10 @@ const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage) => {
|
|
|
268
271
|
const backendGet = (endpoint, params, onJsonResponse, onHelpMessage) => {
|
|
269
272
|
backendRequest('GET', getApiUrl() + endpoint, params, onJsonResponse, onHelpMessage);
|
|
270
273
|
};
|
|
271
|
-
const requestMagicLink = (data, onJsonResponse) => {
|
|
272
|
-
|
|
274
|
+
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
275
|
+
const { email, token } = data;
|
|
276
|
+
const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
|
|
277
|
+
backendRequest('GET', url, null, onJsonResponse, console.error, onUnauthorized);
|
|
273
278
|
};
|
|
274
279
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
275
280
|
backendRequest('GET', getMagicAuthUrl() + magicToken, null, onJsonResponse, onHelpMessage);
|
|
@@ -775,16 +780,7 @@ const contactUsModal = (subject) => {
|
|
|
775
780
|
return result;
|
|
776
781
|
};
|
|
777
782
|
|
|
778
|
-
const
|
|
779
|
-
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
780
|
-
page.style.display = 'block';
|
|
781
|
-
page.style.width = '100%';
|
|
782
|
-
page.style.height = '100%';
|
|
783
|
-
page.style.backgroundPosition = '50%';
|
|
784
|
-
page.style.backgroundSize = 'cover';
|
|
785
|
-
page.style.display = 'block';
|
|
786
|
-
};
|
|
787
|
-
const applyContainerStyles$1 = (container) => {
|
|
783
|
+
const applyContainerStyles = (container) => {
|
|
788
784
|
container.style.backgroundColor = '#ffffffdd';
|
|
789
785
|
container.style.borderRadius = '16px';
|
|
790
786
|
container.style.inset = '50% 50% 50% 0';
|
|
@@ -800,6 +796,24 @@ const applyContainerStyles$1 = (container) => {
|
|
|
800
796
|
container.style.margin = '0 auto';
|
|
801
797
|
container.style.paddingTop = '0';
|
|
802
798
|
};
|
|
799
|
+
const applyPageStyles = (page, backgroundImg) => {
|
|
800
|
+
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
801
|
+
page.style.backgroundPosition = '50%';
|
|
802
|
+
page.style.backgroundSize = 'cover';
|
|
803
|
+
page.style.display = 'block';
|
|
804
|
+
page.style.height = '100%';
|
|
805
|
+
};
|
|
806
|
+
const basePage = (pageName, backgroundImg, content) => {
|
|
807
|
+
const result = document.createElement(pageName);
|
|
808
|
+
result.className = 'base-login-page';
|
|
809
|
+
applyPageStyles(result, backgroundImg);
|
|
810
|
+
const section = document.createElement('section');
|
|
811
|
+
applyContainerStyles(section);
|
|
812
|
+
content.forEach(element => section.appendChild(element));
|
|
813
|
+
result.appendChild(section);
|
|
814
|
+
return result;
|
|
815
|
+
};
|
|
816
|
+
|
|
803
817
|
const applyBtnStyles = (btn) => {
|
|
804
818
|
btn.style.cursor = 'pointer';
|
|
805
819
|
btn.style.textDecoration = 'underline';
|
|
@@ -814,22 +828,20 @@ const applyBtnStyles = (btn) => {
|
|
|
814
828
|
btn.style.font = 'inherit';
|
|
815
829
|
};
|
|
816
830
|
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
817
|
-
const
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
magicLinkHowTo.style.padding = '0 30px';
|
|
832
|
-
magicLinkHowTo.style.textAlign = 'center';
|
|
831
|
+
const content = [];
|
|
832
|
+
const sent = document.createElement('p');
|
|
833
|
+
sent.id = 'magic-link-sent';
|
|
834
|
+
sent.textContent = getTranslation(sent.id);
|
|
835
|
+
sent.style.marginBottom = '10px';
|
|
836
|
+
const email = document.createElement('p');
|
|
837
|
+
email.id = 'magic-link-email';
|
|
838
|
+
email.style.fontWeight = '700';
|
|
839
|
+
email.style.marginBottom = '10px';
|
|
840
|
+
const howTo = document.createElement('p');
|
|
841
|
+
howTo.id = 'magic-link-how-to';
|
|
842
|
+
howTo.innerHTML = getTranslation(howTo.id);
|
|
843
|
+
howTo.style.padding = '0 30px';
|
|
844
|
+
howTo.style.textAlign = 'center';
|
|
833
845
|
const btn = document.createElement('button');
|
|
834
846
|
btn.id = 'email-not-received-btn';
|
|
835
847
|
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
@@ -845,9 +857,38 @@ const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
|
845
857
|
returnLink.style.cursor = 'pointer';
|
|
846
858
|
returnLink.style.fontWeight = '700';
|
|
847
859
|
returnLink.style.textDecoration = 'underline';
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
result
|
|
860
|
+
content.push(sent, email, howTo, btn, returnLink);
|
|
861
|
+
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
862
|
+
return result;
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
866
|
+
const content = [];
|
|
867
|
+
const notSent = document.createElement('p');
|
|
868
|
+
notSent.id = 'magic-link-not-sent';
|
|
869
|
+
notSent.textContent = getTranslation(notSent.id);
|
|
870
|
+
notSent.style.marginBottom = '10px';
|
|
871
|
+
const email = document.createElement('p');
|
|
872
|
+
email.id = 'magic-link-email';
|
|
873
|
+
email.style.fontWeight = '700';
|
|
874
|
+
email.style.marginBottom = '10px';
|
|
875
|
+
const info = document.createElement('p');
|
|
876
|
+
info.id = 'magic-link-fail-info';
|
|
877
|
+
info.innerHTML = getTranslation(info.id);
|
|
878
|
+
info.style.padding = '0 30px';
|
|
879
|
+
info.style.textAlign = 'center';
|
|
880
|
+
const back = document.createElement('a');
|
|
881
|
+
back.textContent = getTranslation('return-link');
|
|
882
|
+
back.onclick = () => {
|
|
883
|
+
result.remove();
|
|
884
|
+
onReturn();
|
|
885
|
+
};
|
|
886
|
+
back.style.marginTop = '32px';
|
|
887
|
+
back.style.cursor = 'pointer';
|
|
888
|
+
back.style.fontWeight = '700';
|
|
889
|
+
back.style.textDecoration = 'underline';
|
|
890
|
+
content.push(notSent, email, info, back);
|
|
891
|
+
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
851
892
|
return result;
|
|
852
893
|
};
|
|
853
894
|
|
|
@@ -872,7 +913,10 @@ const onTokenAcquired = (token, onUserLogin) => {
|
|
|
872
913
|
};
|
|
873
914
|
const clearSession = () => {
|
|
874
915
|
// onUserChanged(null);
|
|
916
|
+
// TODO: find a better way to preserve backend-url
|
|
917
|
+
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
875
918
|
localStorage.clear();
|
|
919
|
+
setBackendUrl(backendUrl);
|
|
876
920
|
// @ts-ignore
|
|
877
921
|
window.store = {};
|
|
878
922
|
};
|
|
@@ -999,12 +1043,15 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
|
|
|
999
1043
|
}
|
|
1000
1044
|
const payload = { email, token };
|
|
1001
1045
|
const onRequestMagicLink = () => {
|
|
1002
|
-
|
|
1046
|
+
const onResponse = (page) => {
|
|
1003
1047
|
currentPage.remove();
|
|
1004
|
-
clientBody.appendChild(
|
|
1005
|
-
const magicLinkEmail =
|
|
1048
|
+
clientBody.appendChild(page);
|
|
1049
|
+
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
1006
1050
|
magicLinkEmail.textContent = email;
|
|
1007
|
-
}
|
|
1051
|
+
};
|
|
1052
|
+
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
1053
|
+
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
1054
|
+
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1008
1055
|
};
|
|
1009
1056
|
// @ts-ignore
|
|
1010
1057
|
if (window.store.fetchUserBackendUrl) {
|
|
@@ -1165,28 +1212,6 @@ const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, cli
|
|
|
1165
1212
|
return result;
|
|
1166
1213
|
};
|
|
1167
1214
|
|
|
1168
|
-
const applyContainerStyles = (container) => {
|
|
1169
|
-
container.style.backgroundColor = '#ffffffdd';
|
|
1170
|
-
container.style.borderRadius = '16px';
|
|
1171
|
-
container.style.inset = '50% 50% 50% 0';
|
|
1172
|
-
container.style.position = 'relative';
|
|
1173
|
-
container.style.transform = 'translateY(-50%)';
|
|
1174
|
-
container.style.width = '620px';
|
|
1175
|
-
container.style.alignItems = 'center';
|
|
1176
|
-
container.style.display = 'flex';
|
|
1177
|
-
container.style.flexDirection = 'column';
|
|
1178
|
-
container.style.fontSize = '16px';
|
|
1179
|
-
container.style.height = '100%';
|
|
1180
|
-
container.style.justifyContent = 'center';
|
|
1181
|
-
container.style.margin = '0 auto';
|
|
1182
|
-
container.style.paddingTop = '0';
|
|
1183
|
-
};
|
|
1184
|
-
const applyPageStyles = (page) => {
|
|
1185
|
-
page.style.backgroundPosition = '50%';
|
|
1186
|
-
page.style.backgroundSize = 'cover';
|
|
1187
|
-
page.style.display = 'block';
|
|
1188
|
-
page.style.height = '100%';
|
|
1189
|
-
};
|
|
1190
1215
|
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
1191
1216
|
const onReturn = () => clientApp.appendChild(loginPage);
|
|
1192
1217
|
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
@@ -1206,20 +1231,17 @@ const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes
|
|
|
1206
1231
|
}
|
|
1207
1232
|
};
|
|
1208
1233
|
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
1209
|
-
const
|
|
1210
|
-
applyPageStyles(result);
|
|
1211
|
-
const section = document.createElement('section');
|
|
1212
|
-
applyContainerStyles(section);
|
|
1234
|
+
const content = [];
|
|
1213
1235
|
const salutation = document.createElement('sign-in-salutation');
|
|
1214
1236
|
salutation.textContent = getTranslation('sign-in-salutation');
|
|
1215
1237
|
const explanation = document.createElement('sign-in-explanation');
|
|
1216
1238
|
explanation.textContent = getTranslation('sign-in-explanation');
|
|
1217
1239
|
const msg = document.createElement('sign-in-msg');
|
|
1218
1240
|
msg.textContent = getTranslation('sign-in-msg-general');
|
|
1219
|
-
|
|
1220
|
-
|
|
1241
|
+
content.push(salutation, explanation, msg);
|
|
1242
|
+
const result = basePage('login-page', backgroundImg, content);
|
|
1243
|
+
const section = result.querySelector('section');
|
|
1221
1244
|
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
1222
|
-
result.appendChild(section);
|
|
1223
1245
|
return result;
|
|
1224
1246
|
};
|
|
1225
1247
|
|
package/dist/main.js
CHANGED
|
@@ -219,7 +219,13 @@ const removeOverlay = () => {
|
|
|
219
219
|
const backendHelpMessage = (req) => {
|
|
220
220
|
return req.response && req.response.error || req.response || req;
|
|
221
221
|
};
|
|
222
|
-
const
|
|
222
|
+
const defaultHandleUnauthorized = () => {
|
|
223
|
+
localStorage.removeItem('token');
|
|
224
|
+
alert(getTranslation('session-expired-msg'));
|
|
225
|
+
location.reload();
|
|
226
|
+
// googleAuthSignOut(); TODO
|
|
227
|
+
};
|
|
228
|
+
const backendRequest = (requestType, urlString, params, onJsonResponse, onHelpMessage, handleUnauthorized = defaultHandleUnauthorized) => {
|
|
223
229
|
if (urlString.includes(getBackendUrl())) {
|
|
224
230
|
urlString = urlString.replace(getBackendUrl(), getBackendUrlToTry());
|
|
225
231
|
}
|
|
@@ -242,10 +248,7 @@ const backendRequest = (requestType, urlString, params, onJsonResponse, onHelpMe
|
|
|
242
248
|
req.responseType = 'json';
|
|
243
249
|
req.onerror = req.ontimeout = () => {
|
|
244
250
|
if (req.status === 401) {
|
|
245
|
-
|
|
246
|
-
alert(getTranslation('session-expired-msg'));
|
|
247
|
-
location.reload();
|
|
248
|
-
// googleAuthSignOut(); TODO
|
|
251
|
+
handleUnauthorized();
|
|
249
252
|
}
|
|
250
253
|
else if (req.status === 0) {
|
|
251
254
|
if (retries >= maxRetries) {
|
|
@@ -292,8 +295,10 @@ const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage) => {
|
|
|
292
295
|
const backendGet = (endpoint, params, onJsonResponse, onHelpMessage) => {
|
|
293
296
|
backendRequest('GET', getApiUrl() + endpoint, params, onJsonResponse, onHelpMessage);
|
|
294
297
|
};
|
|
295
|
-
const requestMagicLink = (data, onJsonResponse) => {
|
|
296
|
-
|
|
298
|
+
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
299
|
+
const { email, token } = data;
|
|
300
|
+
const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
|
|
301
|
+
backendRequest('GET', url, null, onJsonResponse, console.error, onUnauthorized);
|
|
297
302
|
};
|
|
298
303
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
299
304
|
backendRequest('GET', getMagicAuthUrl() + magicToken, null, onJsonResponse, onHelpMessage);
|
|
@@ -799,16 +804,7 @@ const contactUsModal = (subject) => {
|
|
|
799
804
|
return result;
|
|
800
805
|
};
|
|
801
806
|
|
|
802
|
-
const
|
|
803
|
-
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
804
|
-
page.style.display = 'block';
|
|
805
|
-
page.style.width = '100%';
|
|
806
|
-
page.style.height = '100%';
|
|
807
|
-
page.style.backgroundPosition = '50%';
|
|
808
|
-
page.style.backgroundSize = 'cover';
|
|
809
|
-
page.style.display = 'block';
|
|
810
|
-
};
|
|
811
|
-
const applyContainerStyles$1 = (container) => {
|
|
807
|
+
const applyContainerStyles = (container) => {
|
|
812
808
|
container.style.backgroundColor = '#ffffffdd';
|
|
813
809
|
container.style.borderRadius = '16px';
|
|
814
810
|
container.style.inset = '50% 50% 50% 0';
|
|
@@ -824,6 +820,24 @@ const applyContainerStyles$1 = (container) => {
|
|
|
824
820
|
container.style.margin = '0 auto';
|
|
825
821
|
container.style.paddingTop = '0';
|
|
826
822
|
};
|
|
823
|
+
const applyPageStyles = (page, backgroundImg) => {
|
|
824
|
+
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
825
|
+
page.style.backgroundPosition = '50%';
|
|
826
|
+
page.style.backgroundSize = 'cover';
|
|
827
|
+
page.style.display = 'block';
|
|
828
|
+
page.style.height = '100%';
|
|
829
|
+
};
|
|
830
|
+
const basePage = (pageName, backgroundImg, content) => {
|
|
831
|
+
const result = document.createElement(pageName);
|
|
832
|
+
result.className = 'base-login-page';
|
|
833
|
+
applyPageStyles(result, backgroundImg);
|
|
834
|
+
const section = document.createElement('section');
|
|
835
|
+
applyContainerStyles(section);
|
|
836
|
+
content.forEach(element => section.appendChild(element));
|
|
837
|
+
result.appendChild(section);
|
|
838
|
+
return result;
|
|
839
|
+
};
|
|
840
|
+
|
|
827
841
|
const applyBtnStyles = (btn) => {
|
|
828
842
|
btn.style.cursor = 'pointer';
|
|
829
843
|
btn.style.textDecoration = 'underline';
|
|
@@ -838,22 +852,20 @@ const applyBtnStyles = (btn) => {
|
|
|
838
852
|
btn.style.font = 'inherit';
|
|
839
853
|
};
|
|
840
854
|
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
magicLinkHowTo.style.padding = '0 30px';
|
|
856
|
-
magicLinkHowTo.style.textAlign = 'center';
|
|
855
|
+
const content = [];
|
|
856
|
+
const sent = document.createElement('p');
|
|
857
|
+
sent.id = 'magic-link-sent';
|
|
858
|
+
sent.textContent = getTranslation(sent.id);
|
|
859
|
+
sent.style.marginBottom = '10px';
|
|
860
|
+
const email = document.createElement('p');
|
|
861
|
+
email.id = 'magic-link-email';
|
|
862
|
+
email.style.fontWeight = '700';
|
|
863
|
+
email.style.marginBottom = '10px';
|
|
864
|
+
const howTo = document.createElement('p');
|
|
865
|
+
howTo.id = 'magic-link-how-to';
|
|
866
|
+
howTo.innerHTML = getTranslation(howTo.id);
|
|
867
|
+
howTo.style.padding = '0 30px';
|
|
868
|
+
howTo.style.textAlign = 'center';
|
|
857
869
|
const btn = document.createElement('button');
|
|
858
870
|
btn.id = 'email-not-received-btn';
|
|
859
871
|
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
@@ -869,9 +881,38 @@ const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
|
869
881
|
returnLink.style.cursor = 'pointer';
|
|
870
882
|
returnLink.style.fontWeight = '700';
|
|
871
883
|
returnLink.style.textDecoration = 'underline';
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
result
|
|
884
|
+
content.push(sent, email, howTo, btn, returnLink);
|
|
885
|
+
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
886
|
+
return result;
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
890
|
+
const content = [];
|
|
891
|
+
const notSent = document.createElement('p');
|
|
892
|
+
notSent.id = 'magic-link-not-sent';
|
|
893
|
+
notSent.textContent = getTranslation(notSent.id);
|
|
894
|
+
notSent.style.marginBottom = '10px';
|
|
895
|
+
const email = document.createElement('p');
|
|
896
|
+
email.id = 'magic-link-email';
|
|
897
|
+
email.style.fontWeight = '700';
|
|
898
|
+
email.style.marginBottom = '10px';
|
|
899
|
+
const info = document.createElement('p');
|
|
900
|
+
info.id = 'magic-link-fail-info';
|
|
901
|
+
info.innerHTML = getTranslation(info.id);
|
|
902
|
+
info.style.padding = '0 30px';
|
|
903
|
+
info.style.textAlign = 'center';
|
|
904
|
+
const back = document.createElement('a');
|
|
905
|
+
back.textContent = getTranslation('return-link');
|
|
906
|
+
back.onclick = () => {
|
|
907
|
+
result.remove();
|
|
908
|
+
onReturn();
|
|
909
|
+
};
|
|
910
|
+
back.style.marginTop = '32px';
|
|
911
|
+
back.style.cursor = 'pointer';
|
|
912
|
+
back.style.fontWeight = '700';
|
|
913
|
+
back.style.textDecoration = 'underline';
|
|
914
|
+
content.push(notSent, email, info, back);
|
|
915
|
+
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
875
916
|
return result;
|
|
876
917
|
};
|
|
877
918
|
|
|
@@ -896,7 +937,10 @@ const onTokenAcquired = (token, onUserLogin) => {
|
|
|
896
937
|
};
|
|
897
938
|
const clearSession = () => {
|
|
898
939
|
// onUserChanged(null);
|
|
940
|
+
// TODO: find a better way to preserve backend-url
|
|
941
|
+
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
899
942
|
localStorage.clear();
|
|
943
|
+
setBackendUrl(backendUrl);
|
|
900
944
|
// @ts-ignore
|
|
901
945
|
window.store = {};
|
|
902
946
|
};
|
|
@@ -1023,12 +1067,15 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
|
|
|
1023
1067
|
}
|
|
1024
1068
|
const payload = { email, token };
|
|
1025
1069
|
const onRequestMagicLink = () => {
|
|
1026
|
-
|
|
1070
|
+
const onResponse = (page) => {
|
|
1027
1071
|
currentPage.remove();
|
|
1028
|
-
clientBody.appendChild(
|
|
1029
|
-
const magicLinkEmail =
|
|
1072
|
+
clientBody.appendChild(page);
|
|
1073
|
+
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
1030
1074
|
magicLinkEmail.textContent = email;
|
|
1031
|
-
}
|
|
1075
|
+
};
|
|
1076
|
+
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
1077
|
+
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
1078
|
+
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1032
1079
|
};
|
|
1033
1080
|
// @ts-ignore
|
|
1034
1081
|
if (window.store.fetchUserBackendUrl) {
|
|
@@ -1189,28 +1236,6 @@ const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, cli
|
|
|
1189
1236
|
return result;
|
|
1190
1237
|
};
|
|
1191
1238
|
|
|
1192
|
-
const applyContainerStyles = (container) => {
|
|
1193
|
-
container.style.backgroundColor = '#ffffffdd';
|
|
1194
|
-
container.style.borderRadius = '16px';
|
|
1195
|
-
container.style.inset = '50% 50% 50% 0';
|
|
1196
|
-
container.style.position = 'relative';
|
|
1197
|
-
container.style.transform = 'translateY(-50%)';
|
|
1198
|
-
container.style.width = '620px';
|
|
1199
|
-
container.style.alignItems = 'center';
|
|
1200
|
-
container.style.display = 'flex';
|
|
1201
|
-
container.style.flexDirection = 'column';
|
|
1202
|
-
container.style.fontSize = '16px';
|
|
1203
|
-
container.style.height = '100%';
|
|
1204
|
-
container.style.justifyContent = 'center';
|
|
1205
|
-
container.style.margin = '0 auto';
|
|
1206
|
-
container.style.paddingTop = '0';
|
|
1207
|
-
};
|
|
1208
|
-
const applyPageStyles = (page) => {
|
|
1209
|
-
page.style.backgroundPosition = '50%';
|
|
1210
|
-
page.style.backgroundSize = 'cover';
|
|
1211
|
-
page.style.display = 'block';
|
|
1212
|
-
page.style.height = '100%';
|
|
1213
|
-
};
|
|
1214
1239
|
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
1215
1240
|
const onReturn = () => clientApp.appendChild(loginPage);
|
|
1216
1241
|
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
@@ -1230,20 +1255,17 @@ const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes
|
|
|
1230
1255
|
}
|
|
1231
1256
|
};
|
|
1232
1257
|
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
1233
|
-
const
|
|
1234
|
-
applyPageStyles(result);
|
|
1235
|
-
const section = document.createElement('section');
|
|
1236
|
-
applyContainerStyles(section);
|
|
1258
|
+
const content = [];
|
|
1237
1259
|
const salutation = document.createElement('sign-in-salutation');
|
|
1238
1260
|
salutation.textContent = getTranslation('sign-in-salutation');
|
|
1239
1261
|
const explanation = document.createElement('sign-in-explanation');
|
|
1240
1262
|
explanation.textContent = getTranslation('sign-in-explanation');
|
|
1241
1263
|
const msg = document.createElement('sign-in-msg');
|
|
1242
1264
|
msg.textContent = getTranslation('sign-in-msg-general');
|
|
1243
|
-
|
|
1244
|
-
|
|
1265
|
+
content.push(salutation, explanation, msg);
|
|
1266
|
+
const result = basePage('login-page', backgroundImg, content);
|
|
1267
|
+
const section = result.querySelector('section');
|
|
1245
1268
|
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
1246
|
-
result.appendChild(section);
|
|
1247
1269
|
return result;
|
|
1248
1270
|
};
|
|
1249
1271
|
|