work-license-server 1.0.17 → 1.0.18
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/assets/admin.js +6 -2
- package/assets/landing.js +62 -6
- package/package.json +1 -1
package/assets/admin.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
catch { return readCookieSession(); }
|
|
37
37
|
}
|
|
38
|
-
function setStoredToken(tok, email = '') {
|
|
38
|
+
function setStoredToken(tok, email = '', userObj = null) {
|
|
39
39
|
adminToken = tok || '';
|
|
40
40
|
try {
|
|
41
41
|
if (tok) {
|
|
@@ -49,12 +49,16 @@
|
|
|
49
49
|
sessionStorage.removeItem(TOKEN_KEY);
|
|
50
50
|
localStorage.removeItem(TOKEN_KEY);
|
|
51
51
|
localStorage.removeItem('odant_work_session');
|
|
52
|
+
localStorage.removeItem('odant_work_user_cache');
|
|
52
53
|
sessionStorage.removeItem('odant_work_session');
|
|
53
54
|
document.cookie = 'odant_work_session=; path=/; max-age=0; SameSite=Lax';
|
|
54
55
|
}
|
|
55
56
|
if (email) {
|
|
56
57
|
localStorage.setItem('odant_work_email', email);
|
|
57
58
|
}
|
|
59
|
+
if (userObj && typeof userObj === 'object') {
|
|
60
|
+
localStorage.setItem('odant_work_user_cache', JSON.stringify(userObj));
|
|
61
|
+
}
|
|
58
62
|
}
|
|
59
63
|
catch { /* приватный режим */ }
|
|
60
64
|
}
|
|
@@ -189,7 +193,7 @@
|
|
|
189
193
|
if (!user.isAdmin) {
|
|
190
194
|
throw new Error(`Аккаунт ${user.email} не обладает правами администратора (BOSS) сервера лицензирования.`);
|
|
191
195
|
}
|
|
192
|
-
setStoredToken(user.sessionKey, user.email);
|
|
196
|
+
setStoredToken(user.sessionKey, user.email, user);
|
|
193
197
|
resetAdmStep();
|
|
194
198
|
showAdminApp(user.email);
|
|
195
199
|
await refreshRegistry();
|
package/assets/landing.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
let REGIONS = (D.regions || []).slice();
|
|
15
15
|
let currentUser = null;
|
|
16
16
|
let currentStage = 'product';
|
|
17
|
+
let requestedInitialStage = '';
|
|
17
18
|
let selectedCode = null;
|
|
18
19
|
let pendingAuthAction = null;
|
|
19
20
|
|
|
@@ -137,7 +138,7 @@
|
|
|
137
138
|
}
|
|
138
139
|
catch { return ''; }
|
|
139
140
|
}
|
|
140
|
-
function persistSessionInBrowser(sessionKey = '', email = '', isAdmin = false) {
|
|
141
|
+
function persistSessionInBrowser(sessionKey = '', email = '', isAdmin = false, userObj = null) {
|
|
141
142
|
try {
|
|
142
143
|
if (sessionKey) {
|
|
143
144
|
localStorage.setItem('odant_work_session', sessionKey);
|
|
@@ -151,6 +152,9 @@
|
|
|
151
152
|
if (email) {
|
|
152
153
|
localStorage.setItem('odant_work_email', email);
|
|
153
154
|
}
|
|
155
|
+
if (userObj && typeof userObj === 'object') {
|
|
156
|
+
localStorage.setItem('odant_work_user_cache', JSON.stringify(userObj));
|
|
157
|
+
}
|
|
154
158
|
}
|
|
155
159
|
catch { /* приватный режим */ }
|
|
156
160
|
}
|
|
@@ -158,12 +162,57 @@
|
|
|
158
162
|
try {
|
|
159
163
|
localStorage.removeItem('odant_work_session');
|
|
160
164
|
localStorage.removeItem('odant_work_admin_token');
|
|
165
|
+
localStorage.removeItem('odant_work_user_cache');
|
|
161
166
|
sessionStorage.removeItem('odant_work_session');
|
|
162
167
|
sessionStorage.removeItem('odant_work_admin_token');
|
|
163
168
|
document.cookie = 'odant_work_session=; path=/; max-age=0; SameSite=Lax';
|
|
164
169
|
}
|
|
165
170
|
catch { /* ignore */ }
|
|
166
171
|
}
|
|
172
|
+
function hydrateCachedUser() {
|
|
173
|
+
try {
|
|
174
|
+
const key = localStorage.getItem('odant_work_session')
|
|
175
|
+
|| sessionStorage.getItem('odant_work_session')
|
|
176
|
+
|| localStorage.getItem('odant_work_admin_token')
|
|
177
|
+
|| readCookieSession()
|
|
178
|
+
|| '';
|
|
179
|
+
if (!key) return;
|
|
180
|
+
const raw = localStorage.getItem('odant_work_user_cache');
|
|
181
|
+
if (raw) {
|
|
182
|
+
const cached = JSON.parse(raw);
|
|
183
|
+
if (cached?.email) {
|
|
184
|
+
currentUser = { ...cached, sessionKey: key, ofertaAccepted: cached.ofertaAccepted !== false };
|
|
185
|
+
onAuthenticated();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Если есть подписанный токен wks_1.<payload>.<sig>, декодируем payload синхронно до ответа /api/auth/me
|
|
190
|
+
if (key.startsWith('wks_1.')) {
|
|
191
|
+
const parts = key.split('.');
|
|
192
|
+
if (parts[1]) {
|
|
193
|
+
const b64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
194
|
+
const json = decodeURIComponent(escape(atob(b64)));
|
|
195
|
+
const payload = JSON.parse(json);
|
|
196
|
+
if (payload?.email) {
|
|
197
|
+
currentUser = {
|
|
198
|
+
userId: payload.userId || '',
|
|
199
|
+
email: payload.email,
|
|
200
|
+
name: payload.name || payload.email,
|
|
201
|
+
companyName: payload.companyName || '',
|
|
202
|
+
inn: payload.inn || '',
|
|
203
|
+
isAdmin: Boolean(payload.isAdmin),
|
|
204
|
+
ofertaAccepted: true,
|
|
205
|
+
sessionKey: key,
|
|
206
|
+
servers: [],
|
|
207
|
+
franchises: [],
|
|
208
|
+
};
|
|
209
|
+
onAuthenticated();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch { /* ignore */ }
|
|
215
|
+
}
|
|
167
216
|
|
|
168
217
|
function openAuth(hintMsg = '', intentTitle = '') {
|
|
169
218
|
if ($('#authErrorMsg')) $('#authErrorMsg').textContent = hintMsg || '';
|
|
@@ -286,7 +335,7 @@
|
|
|
286
335
|
try {
|
|
287
336
|
const data = await api('/api/auth/verify-code', { email, code });
|
|
288
337
|
currentUser = data;
|
|
289
|
-
persistSessionInBrowser(data.sessionKey, data.email, data.isAdmin);
|
|
338
|
+
persistSessionInBrowser(data.sessionKey, data.email, data.isAdmin, data);
|
|
290
339
|
resetAuthStep();
|
|
291
340
|
onAuthenticated();
|
|
292
341
|
closeAuth();
|
|
@@ -335,9 +384,12 @@
|
|
|
335
384
|
const data = await api('/api/auth/me?sessionKey=' + encodeURIComponent(key));
|
|
336
385
|
if (data.authenticated && data.user) {
|
|
337
386
|
currentUser = { ...data.user, sessionKey: data.user.sessionKey || key };
|
|
338
|
-
persistSessionInBrowser(currentUser.sessionKey, currentUser.email, currentUser.isAdmin);
|
|
387
|
+
persistSessionInBrowser(currentUser.sessionKey, currentUser.email, currentUser.isAdmin, currentUser);
|
|
339
388
|
onAuthenticated();
|
|
340
|
-
if (location.hash === '#addons' && isUserReadyForOrders())
|
|
389
|
+
if ((requestedInitialStage === 'addons' || location.hash === '#addons') && isUserReadyForOrders()) {
|
|
390
|
+
requestedInitialStage = '';
|
|
391
|
+
switchStage('addons', { scroll: false });
|
|
392
|
+
}
|
|
341
393
|
}
|
|
342
394
|
}
|
|
343
395
|
catch { /* сессия отозвана */ }
|
|
@@ -1834,14 +1886,18 @@
|
|
|
1834
1886
|
|
|
1835
1887
|
function start() {
|
|
1836
1888
|
applyTheme(document.documentElement.getAttribute('data-theme') || 'dark');
|
|
1889
|
+
requestedInitialStage = D.initialStage || location.hash.slice(1);
|
|
1890
|
+
hydrateCachedUser();
|
|
1837
1891
|
bind();
|
|
1838
1892
|
renderOrbit();
|
|
1839
1893
|
recalcBaseOrder();
|
|
1840
1894
|
recalcPartner();
|
|
1841
1895
|
renderRegionsTable();
|
|
1842
1896
|
initBackdrop();
|
|
1843
|
-
const
|
|
1844
|
-
|
|
1897
|
+
const targetStage = (requestedInitialStage === 'addons' && isUserReadyForOrders())
|
|
1898
|
+
? 'addons'
|
|
1899
|
+
: (requestedInitialStage && requestedInitialStage !== 'addons' && requestedInitialStage !== 'admin' ? requestedInitialStage : 'product');
|
|
1900
|
+
switchStage(targetStage, { scroll: false });
|
|
1845
1901
|
if (document.fonts?.ready) document.fonts.ready.then(moveIndicator);
|
|
1846
1902
|
initMap().then(() => selectRegion(selectedCode || 'RU-SVE'));
|
|
1847
1903
|
restoreSession();
|
package/package.json
CHANGED