odant-work 1.0.99 → 1.0.101
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/#system/package-manifest.json +8 -8
- package/$server/$folder/$class/$structure/$user/class.js +1 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/profile/$handler/class.js +5 -2
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/staff/$handler/class.js +3 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/tokens/$handler/class.js +24 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/users/$handler/class.js +213 -0
- package/$server/$folder/lib/consultant/consultant.js +6 -1
- package/$server/$folder/lib/explorer/explorer.js +18 -1
- package/$server/$folder/lib/prompt-bar/prompt-bar.js +15 -1
- package/$server/$folder/lib/tree/tree.js +2 -3
- package/MODULES/$domain/class.js +1 -0
- package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/class.js +1 -0
- package/{$server/$folder/$class/$users → USERS/$user}/class.js +4 -1
- package/oda/oda.js +15 -1
- package/package.json +1 -1
- package/readme.md +1 -1
- package/sources/client/handler.js +17 -5
- package/sources/client.js +68 -35
- package/sources/host/auth-methods.js +14 -3
- package/sources/modules/rag/extract.js +1 -1
- package/sources/modules/user-profile/user-profile.js +120 -115
- package/sources/modules/user-profile/user-tokens.js +185 -0
- package/sources/server/class/distro.js +9 -5
- package/sources/server/class/security.js +34 -10
- package/sources/server/folder.js +7 -7
- package/sources/server/user.js +3 -0
- package/USERS/$users/class.js +0 -4
package/sources/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Reactor } from "./reactor.js";
|
|
|
5
5
|
import { RTCCaller } from "./modules/call/call.js";
|
|
6
6
|
import "./modules/user-profile/user-profile.js";
|
|
7
7
|
import "./modules/user-profile/user-token.js";
|
|
8
|
+
import "./modules/user-profile/user-tokens.js";
|
|
8
9
|
window.RTCCaller = RTCCaller;
|
|
9
10
|
class WORK_ServerError extends Error{}
|
|
10
11
|
window.CORE = CORE;
|
|
@@ -437,53 +438,85 @@ WORK.login = async function(force = false){
|
|
|
437
438
|
WORK.credentials = window.top.WORK.credentials;
|
|
438
439
|
WORK.uid = window.top.WORK.uid || '';
|
|
439
440
|
WORK.USER = window.top.WORK.USER;
|
|
441
|
+
WORK._loginError = null;
|
|
440
442
|
return res;
|
|
441
443
|
}
|
|
442
444
|
}
|
|
443
|
-
catch {
|
|
445
|
+
catch (err) {
|
|
446
|
+
if (!err || err.name === 'SecurityError') { /* cross-origin fallback */ }
|
|
447
|
+
else {
|
|
448
|
+
WORK._loginError = err;
|
|
449
|
+
throw err;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
444
452
|
}
|
|
445
453
|
if (!force && WORK._loginPromise && WORK._loginTargetUid === nextUid)
|
|
446
454
|
return WORK._loginPromise;
|
|
447
455
|
WORK._loginTargetUid = nextUid;
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
456
|
+
WORK._loginError = null;
|
|
457
|
+
WORK._loginInProgress = true;
|
|
458
|
+
try {
|
|
459
|
+
WORK.authEvents?.dispatchEvent?.(new CustomEvent('login-state', { detail: { pending: true, error: null } }));
|
|
460
|
+
} catch {}
|
|
461
|
+
const run = (async () => {
|
|
462
|
+
try {
|
|
463
|
+
WORK.credentials = nextCreds;
|
|
464
|
+
let KEY = secure.getItem('KEY');
|
|
465
|
+
let uid = WORK.credentials?.uid;
|
|
466
|
+
if(uid && KEY){
|
|
467
|
+
if (WORK.uid && WORK.uid !== uid)
|
|
468
|
+
await WORK.removeCurrentPushSubscription?.();
|
|
469
|
+
let challengeId = crypto.randomUUID();
|
|
470
|
+
const challenge = await WORK.fetch("/", 'user_login_start', { uid, challengeId});
|
|
471
|
+
KEY = Uint8Array.from(atob(KEY), c => c.charCodeAt(0));
|
|
472
|
+
let privateKey = await crypto.subtle.importKey("pkcs8", KEY, { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, true, ["sign"]);
|
|
473
|
+
let signature = await crypto.subtle.sign({ name: "RSASSA-PKCS1-v1_5" }, privateKey, new TextEncoder().encode(challenge));
|
|
474
|
+
signature = WORK.arrayBufferToBase64(signature);
|
|
475
|
+
let pendingInviteToken = '';
|
|
476
|
+
try { pendingInviteToken = sessionStorage.getItem('work.pendingInviteToken') || ''; } catch { /* ignore */ }
|
|
477
|
+
const res = await WORK.fetch("/", 'user_login_finish' , { uid, time: WORK.credentials.time, challengeId}, {signature, ...(pendingInviteToken ? { inviteToken: pendingInviteToken } : {})});
|
|
478
|
+
if (pendingInviteToken) {
|
|
479
|
+
try { sessionStorage.removeItem('work.pendingInviteToken'); } catch { /* ignore */ }
|
|
480
|
+
}
|
|
481
|
+
WORK.uid = uid;
|
|
482
|
+
WORK._loginError = null;
|
|
483
|
+
WORK._anonExitSynced = false;
|
|
484
|
+
await WORK.syncAuthUI();
|
|
485
|
+
WORK.refreshChatUnread?.();
|
|
486
|
+
WORK.notifyAuth?.({ uid, reason: 'login' });
|
|
487
|
+
return res;
|
|
488
|
+
}
|
|
489
|
+
const hadAuth = Boolean(WORK.uid);
|
|
490
|
+
if (WORK.uid)
|
|
454
491
|
await WORK.removeCurrentPushSubscription?.();
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
try { pendingInviteToken = sessionStorage.getItem('work.pendingInviteToken') || ''; } catch { /* ignore */ }
|
|
463
|
-
const res = await WORK.fetch("/", 'user_login_finish' , { uid, time: WORK.credentials.time, challengeId}, {signature, ...(pendingInviteToken ? { inviteToken: pendingInviteToken } : {})});
|
|
464
|
-
if (pendingInviteToken) {
|
|
465
|
-
try { sessionStorage.removeItem('work.pendingInviteToken'); } catch { /* ignore */ }
|
|
492
|
+
WORK.uid = '';
|
|
493
|
+
WORK._loginError = null;
|
|
494
|
+
WORK.USER = undefined;
|
|
495
|
+
WORK.chatUnread = { total: 0, byThread: {}, byNode: {}, byPeer: {} };
|
|
496
|
+
if (hadAuth || !WORK._anonExitSynced) {
|
|
497
|
+
WORK._anonExitSynced = true;
|
|
498
|
+
await WORK.fetch("/", 'user_exit', {}, {}).catch(() => {});
|
|
466
499
|
}
|
|
467
|
-
WORK.uid = uid;
|
|
468
|
-
WORK._anonExitSynced = false;
|
|
469
500
|
await WORK.syncAuthUI();
|
|
470
|
-
WORK.
|
|
471
|
-
|
|
472
|
-
|
|
501
|
+
WORK.notifyAuth?.({ uid: '', reason: 'logout' });
|
|
502
|
+
}
|
|
503
|
+
catch (err) {
|
|
504
|
+
WORK._loginError = err;
|
|
505
|
+
if (WORK._loginPromise === run)
|
|
506
|
+
WORK._loginPromise = null;
|
|
507
|
+
throw err;
|
|
473
508
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
WORK._anonExitSynced = true;
|
|
482
|
-
await WORK.fetch("/", 'user_exit', {}, {}).catch(() => {});
|
|
509
|
+
finally {
|
|
510
|
+
WORK._loginInProgress = false;
|
|
511
|
+
try {
|
|
512
|
+
WORK.authEvents?.dispatchEvent?.(new CustomEvent('login-state', {
|
|
513
|
+
detail: { pending: false, error: WORK._loginError || null, uid: WORK.uid || '' }
|
|
514
|
+
}));
|
|
515
|
+
} catch {}
|
|
483
516
|
}
|
|
484
|
-
await WORK.syncAuthUI();
|
|
485
|
-
WORK.notifyAuth?.({ uid: '', reason: 'logout' });
|
|
486
517
|
})();
|
|
518
|
+
WORK._loginPromise = run;
|
|
519
|
+
return run;
|
|
487
520
|
}
|
|
488
521
|
WORK.applyChatReadLocal = function ({ threadId = '', kind = '', nodePath = '', peerId = '' } = {}) {
|
|
489
522
|
const u = WORK.chatUnread;
|
|
@@ -608,7 +641,7 @@ class WebSocketEvents {
|
|
|
608
641
|
onopen(e) {
|
|
609
642
|
this.send(JSON.stringify(Object.keys(CORE.$item.ITEMS)));
|
|
610
643
|
WORK.connected = true;
|
|
611
|
-
WORK.login();
|
|
644
|
+
WORK.login().catch(() => {});
|
|
612
645
|
}
|
|
613
646
|
onclose(e) {
|
|
614
647
|
WORK.connected = false;
|
|
@@ -378,12 +378,20 @@ export const authMethods = {
|
|
|
378
378
|
const uid = String(rawUid || '').trim().toUpperCase();
|
|
379
379
|
if (!UID_RE.test(uid))
|
|
380
380
|
throw new Error("uid required");
|
|
381
|
-
|
|
381
|
+
const challengeKey = challengeId != null ? String(challengeId) : '';
|
|
382
|
+
if (session.uid === uid) {
|
|
383
|
+
if (challengeKey) {
|
|
384
|
+
const entry = pendingLogins.get(challengeKey);
|
|
385
|
+
if (entry?.uid === uid)
|
|
386
|
+
pendingLogins.delete(challengeKey);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
382
390
|
let signature = params.post?.signature;
|
|
383
391
|
if (!signature) throw new Error("login session break. Need signature.");
|
|
384
|
-
const challengeEntry = pendingLogins.get(
|
|
392
|
+
const challengeEntry = pendingLogins.get(challengeKey);
|
|
385
393
|
if (!challengeEntry) throw new Error("login session break. Challenge expired or missing.");
|
|
386
|
-
pendingLogins.delete(
|
|
394
|
+
pendingLogins.delete(challengeKey);
|
|
387
395
|
const challengeValue = challengeEntry.value ?? challengeEntry;
|
|
388
396
|
if (!challengeEntry.expiresAt || Date.now() > challengeEntry.expiresAt)
|
|
389
397
|
throw new Error("login session break. Challenge expired.");
|
|
@@ -477,6 +485,9 @@ export const authMethods = {
|
|
|
477
485
|
}
|
|
478
486
|
const affected = Object.values($server.sessions).filter(s => s.uid === uid);
|
|
479
487
|
this.constructor.clearAllSessionsForUid(uid);
|
|
488
|
+
for (const [id, c] of pendingLogins)
|
|
489
|
+
if (c?.uid === uid)
|
|
490
|
+
pendingLogins.delete(id);
|
|
480
491
|
const { time } = params.post || {};
|
|
481
492
|
if (time)
|
|
482
493
|
delete session[time];
|
|
@@ -87,7 +87,7 @@ export function kindOf(p) {
|
|
|
87
87
|
if (name === 'class.js') {
|
|
88
88
|
const meta = segs[segs.length - 2];
|
|
89
89
|
const owner = segs[segs.length - 3];
|
|
90
|
-
if (meta === '$handler' ||
|
|
90
|
+
if (meta === '$handler' || segs.includes('handlers'))
|
|
91
91
|
return null;
|
|
92
92
|
if (meta?.[0] === '$' && (owner === undefined || owner[0] !== '$'))
|
|
93
93
|
return 'class';
|
|
@@ -56,62 +56,72 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
56
56
|
</div>
|
|
57
57
|
<div vertical style="gap: 16px; align-items: center;">
|
|
58
58
|
<div class="photo" vertical style="padding: 16px; border-radius: 50%;">
|
|
59
|
-
<oda-icon :icon="photoIcon" round @tap="loadPhoto" style="border-radius: 50%; fill: white; color: white;" icon-size="180"></oda-icon>
|
|
59
|
+
<oda-icon :icon="photoIcon" round @tap="!isOtherUser && loadPhoto()" style="border-radius: 50%; fill: white; color: white;" icon-size="180"></oda-icon>
|
|
60
60
|
</div>
|
|
61
|
-
<input id="name" placeholder="Имя" ::value="params.name" name="name">
|
|
62
|
-
<input id="surname" placeholder="Фамилия" ::value="params.surname" name="surname">
|
|
63
|
-
<input id="patronymic" placeholder="Отчество" ::value="params.patronymic" name="patronymic">
|
|
64
|
-
<input id="email" :disabled="isLogin || showCode" placeholder="Email" ::value="params.email" type="email" name="email" :error="!correctEmail" :success="correctEmail">
|
|
65
|
-
<oda-otp-input ~if="showCode" center @complete="_onCode"></oda-otp-input>
|
|
66
|
-
<button ~if="state.label && !showCode" center horizontal :disabled="!correctEmail" flex raised :class="state.class" @tap.stop.prevent="register_start" style="gap: 8px;align-items: center;">
|
|
61
|
+
<input id="name" :disabled="isOtherUser" placeholder="Имя" ::value="params.name" name="name">
|
|
62
|
+
<input id="surname" :disabled="isOtherUser" placeholder="Фамилия" ::value="params.surname" name="surname">
|
|
63
|
+
<input id="patronymic" :disabled="isOtherUser" placeholder="Отчество" ::value="params.patronymic" name="patronymic">
|
|
64
|
+
<input id="email" :disabled="isOtherUser || isLogin || showCode" placeholder="Email" ::value="params.email" type="email" name="email" :error="!correctEmail" :success="correctEmail">
|
|
65
|
+
<oda-otp-input ~if="!isOtherUser && showCode" center @complete="_onCode"></oda-otp-input>
|
|
66
|
+
<button ~if="!isOtherUser && state.label && !showCode" center horizontal :disabled="!correctEmail" flex raised :class="state.class" @tap.stop.prevent="register_start" style="gap: 8px;align-items: center;">
|
|
67
67
|
<span>{{state.label}}</span>
|
|
68
68
|
<oda-icon ~if="state.icon" :icon="state.icon"></oda-icon>
|
|
69
69
|
</button>
|
|
70
|
-
<div ~if="isLogin && state?.name === 'ok' && !showCode" vertical style="gap: 8px; width: 100%; border-top: 1px solid rgba(128,128,128,.3); padding-top: 12px; margin-top: 4px;">
|
|
71
|
-
<div style="font-size: medium; font-weight: 600; text-align: center;">Подключения</div>
|
|
72
|
-
<button center horizontal flex @tap.stop.prevent="mcp_token" title="Один токен для внешних ИИ-клиентов (MCP) и расширения WORK Chrome Bridge">
|
|
73
|
-
<span>Токен для подключения</span>
|
|
74
|
-
</button>
|
|
75
|
-
<div style="font-size: small; text-align: center; opacity: 0.75; line-height: 1.35;">
|
|
76
|
-
Этот же токен вместе с адресом WORK вводится в расширении <b>WORK Chrome Bridge</b> и MCP-клиентах.
|
|
77
|
-
</div>
|
|
78
|
-
<button center horizontal flex @tap.stop.prevent="mcp_list" title="Список токенов: срок жизни, последнее использование, отзыв по одному">
|
|
79
|
-
<span>Список токенов…</span>
|
|
80
|
-
</button>
|
|
81
|
-
<div ~if="mcpList" vertical style="gap: 8px; width: 100%;">
|
|
82
|
-
<div ~if="!mcpList.length" style="font-size: small; text-align: center;">токенов нет</div>
|
|
83
|
-
<div ~for="mcpList" horizontal style="gap: 8px; align-items: center; justify-content: space-between; border: 1px solid gray; border-radius: 8px; padding: 4px 8px;">
|
|
84
|
-
<span flex>{{$for.item.label}}{{$for.item.role ? ' (' + $for.item.role + ')' : ''}}</span>
|
|
85
|
-
<span no-flex style="font-size: small;">{{$for.item.expired ? 'истёк' : 'до ' + fmtDate($for.item.expires)}} · был{{fmtDate($for.item.lastUsed)}}</span>
|
|
86
|
-
<button no-flex style="height: 32px; font-size: medium;" @tap.stop.prevent="mcp_revoke_one($for.item.id)">Отозвать</button>
|
|
87
|
-
</div>
|
|
88
|
-
</div>
|
|
89
|
-
<button center horizontal flex @tap.stop.prevent="mcp_revoke">
|
|
90
|
-
<span>Отозвать все токены</span>
|
|
91
|
-
</button>
|
|
92
|
-
</div>
|
|
93
70
|
</div>
|
|
94
71
|
<div flex style="text-align: center;" ~html="state.legend"></div>
|
|
95
72
|
<div flex style="text-align: center;" :error="!!error" @tap="fill_code">{{text}}</div>
|
|
96
73
|
</div>
|
|
97
74
|
`,
|
|
75
|
+
$item: {
|
|
76
|
+
$def: null,
|
|
77
|
+
set(n) {
|
|
78
|
+
this._syncFromItem(n);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
98
81
|
error: null,
|
|
99
82
|
text: '',
|
|
83
|
+
isLoggingIn: false,
|
|
84
|
+
get isOtherUser() {
|
|
85
|
+
return Boolean(this.$item?.id && WORK?.uid && this.$item.id !== WORK.uid);
|
|
86
|
+
},
|
|
87
|
+
get hasKey() {
|
|
88
|
+
return Boolean(this.credentials?.uid && this.workSecure.getItem('KEY'));
|
|
89
|
+
},
|
|
100
90
|
get state(){
|
|
101
|
-
if(
|
|
91
|
+
if (this.isOtherUser) {
|
|
92
|
+
const targetUid = this.$item?.id || this.params?.uid || '';
|
|
93
|
+
const enabled = this.$item?.DATA?.enabled !== false;
|
|
94
|
+
return {
|
|
95
|
+
name: 'other',
|
|
96
|
+
label: '',
|
|
97
|
+
legend: (targetUid ? ('uid: ' + targetUid) : '') + (enabled ? '' : ' · <b>Отключён</b>'),
|
|
98
|
+
class: 'info-invert'
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const errMsg = String(this.error?.message || this.error || '');
|
|
102
|
+
const keyRejected = /user not registered|need publickey|login failed|challenge issued for another user/i.test(errMsg);
|
|
103
|
+
if(!this.isRegistered || !this.hasKey || keyRejected)
|
|
102
104
|
return {
|
|
103
105
|
name: 'unregistered',
|
|
104
106
|
label: 'Register KEY',
|
|
105
107
|
legend: 'Для входа в систему необходимо зарегистрировать ключ безопасности. <p>Ключ будет создан на Вашем устройстве, и привязан к адресу электронной почты.',
|
|
106
108
|
class: 'success-invert'
|
|
107
109
|
}
|
|
108
|
-
if(!this.isLogin)
|
|
110
|
+
if(!this.isLogin) {
|
|
111
|
+
if (this.isLoggingIn)
|
|
112
|
+
return {
|
|
113
|
+
name: 'logging-in',
|
|
114
|
+
label: '',
|
|
115
|
+
legend: 'Выполняется вход в систему…',
|
|
116
|
+
class: 'info-invert'
|
|
117
|
+
}
|
|
109
118
|
return {
|
|
110
|
-
name: 'need-
|
|
111
|
-
label: '
|
|
112
|
-
legend: '
|
|
113
|
-
class: '
|
|
119
|
+
name: 'need-login',
|
|
120
|
+
label: 'Войти',
|
|
121
|
+
legend: 'Для входа в систему нажмите «Войти».',
|
|
122
|
+
class: 'success-invert'
|
|
114
123
|
}
|
|
124
|
+
}
|
|
115
125
|
if(this.isChanged)
|
|
116
126
|
return {
|
|
117
127
|
name: 'changed',
|
|
@@ -194,8 +204,57 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
194
204
|
},
|
|
195
205
|
|
|
196
206
|
attached() {
|
|
197
|
-
this.
|
|
207
|
+
this._syncFromItem(this.$item);
|
|
198
208
|
this._loadPendingInvite();
|
|
209
|
+
this._onAuthState = () => {
|
|
210
|
+
if (this.isOtherUser)
|
|
211
|
+
return;
|
|
212
|
+
this.isLoggingIn = Boolean(WORK._loginInProgress);
|
|
213
|
+
if (WORK._loginError) {
|
|
214
|
+
this.error = WORK._loginError;
|
|
215
|
+
this.text = WORK._loginError?.message || String(WORK._loginError);
|
|
216
|
+
}
|
|
217
|
+
else if (this.isLogin) {
|
|
218
|
+
this.error = null;
|
|
219
|
+
this.text = '';
|
|
220
|
+
}
|
|
221
|
+
this.isLogin = undefined;
|
|
222
|
+
this.render?.();
|
|
223
|
+
};
|
|
224
|
+
WORK.authEvents?.addEventListener?.('auth', this._onAuthState);
|
|
225
|
+
WORK.authEvents?.addEventListener?.('login-state', this._onAuthState);
|
|
226
|
+
},
|
|
227
|
+
detached() {
|
|
228
|
+
if (this._onAuthState) {
|
|
229
|
+
WORK.authEvents?.removeEventListener?.('auth', this._onAuthState);
|
|
230
|
+
WORK.authEvents?.removeEventListener?.('login-state', this._onAuthState);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
async _syncFromItem(item) {
|
|
234
|
+
if (item?.id && WORK?.uid && item.id !== WORK.uid) {
|
|
235
|
+
try { await item.init; } catch {}
|
|
236
|
+
const d = item.DATA || {};
|
|
237
|
+
this.credentials = null;
|
|
238
|
+
this.params = {
|
|
239
|
+
...this.params,
|
|
240
|
+
uid: item.id,
|
|
241
|
+
name: d.name || '',
|
|
242
|
+
surname: d.surname || '',
|
|
243
|
+
patronymic: d.patronymic || '',
|
|
244
|
+
email: d.email || '',
|
|
245
|
+
icon: item.icon || d.icon || '',
|
|
246
|
+
};
|
|
247
|
+
this.error = null;
|
|
248
|
+
this.text = '';
|
|
249
|
+
this.showCode = false;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.credentials = this.workSecure.getItem('credentials');
|
|
253
|
+
this.isLoggingIn = Boolean(WORK._loginInProgress);
|
|
254
|
+
if (WORK._loginError) {
|
|
255
|
+
this.error = WORK._loginError;
|
|
256
|
+
this.text = WORK._loginError?.message || String(WORK._loginError);
|
|
257
|
+
}
|
|
199
258
|
},
|
|
200
259
|
pendingInvite: null,
|
|
201
260
|
pendingInviteToken: '',
|
|
@@ -255,78 +314,12 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
255
314
|
},
|
|
256
315
|
reg: null,
|
|
257
316
|
showCode: false,
|
|
258
|
-
mcpList: null,
|
|
259
|
-
fmtDate(ms) {
|
|
260
|
-
return ms ? new Date(ms).toLocaleDateString() : '—';
|
|
261
|
-
},
|
|
262
|
-
/** Список токенов MCP: подпись, срок жизни, последнее использование; каждый можно отозвать отдельно. */
|
|
263
|
-
async mcp_list() {
|
|
264
|
-
this.mcpList = this.mcpList ? null : await WORK.fetch('/', 'mcp_token_list', {}, {});
|
|
265
|
-
},
|
|
266
|
-
async mcp_revoke_one(id) {
|
|
267
|
-
try {
|
|
268
|
-
await WORK.showConfirm('Отозвать этот токен? Подключённый клиент перестанет работать.');
|
|
269
|
-
}
|
|
270
|
-
catch { return; }
|
|
271
|
-
try {
|
|
272
|
-
await WORK.fetch('/', 'mcp_token_revoke', {}, { id });
|
|
273
|
-
this.mcpList = await WORK.fetch('/', 'mcp_token_list', {}, {});
|
|
274
|
-
}
|
|
275
|
-
catch (e) {
|
|
276
|
-
this.text = e.message;
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
317
|
get workSecure() {
|
|
280
318
|
return ODA.LocalStorage.create('work-secure');
|
|
281
319
|
},
|
|
282
|
-
/** Токен подключения (MCP и WORK Chrome Bridge): выпускается вошедшим пользователем, показывается один раз. */
|
|
283
|
-
async mcp_token() {
|
|
284
|
-
try {
|
|
285
|
-
await WORK.showConfirm('Выпустить персональный токен для подключения (WORK Chrome Bridge, OpenCode, Claude Code…)? Он даёт доступ к WORK с вашими правами и покажется один раз.');
|
|
286
|
-
}
|
|
287
|
-
catch { return; }
|
|
288
|
-
try {
|
|
289
|
-
const r = await WORK.fetch('/', 'mcp_token_create', {}, { label: 'Подключение (MCP / Chrome)' });
|
|
290
|
-
if (this.mcpList)
|
|
291
|
-
this.mcpList = await WORK.fetch('/', 'mcp_token_list', {}, {});
|
|
292
|
-
if (typeof WORK.showModal === 'function') {
|
|
293
|
-
const dlg = ODA.createComponent('user-token', {
|
|
294
|
-
token: r.token,
|
|
295
|
-
origin: location.origin,
|
|
296
|
-
});
|
|
297
|
-
try {
|
|
298
|
-
await WORK.showModal(dlg, {
|
|
299
|
-
TITLE: { label: 'Токен подключения' },
|
|
300
|
-
allowClose: true,
|
|
301
|
-
BUTTONS: [],
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
catch { /* закрыли окно */ }
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
prompt('Токен подключения — скопируйте, повторно он не показывается.\nАдрес сервера: ' + location.origin + '\nАдрес MCP: ' + location.origin + '/mcp', r.token);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
catch (e) {
|
|
311
|
-
this.text = e.message;
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
async mcp_revoke() {
|
|
315
|
-
try {
|
|
316
|
-
await WORK.showConfirm('Отозвать все токены подключения? Подключённые внешние клиенты и Chrome Bridge перестанут работать.');
|
|
317
|
-
}
|
|
318
|
-
catch { return; }
|
|
319
|
-
try {
|
|
320
|
-
const r = await WORK.fetch('/', 'mcp_token_revoke', {}, { all: true });
|
|
321
|
-
if (this.mcpList)
|
|
322
|
-
this.mcpList = await WORK.fetch('/', 'mcp_token_list', {}, {});
|
|
323
|
-
this.text = 'Токенов отозвано: ' + (r?.revoked ?? 0);
|
|
324
|
-
}
|
|
325
|
-
catch (e) {
|
|
326
|
-
this.text = e.message;
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
320
|
async register_start(e) {
|
|
321
|
+
if (this.isOtherUser)
|
|
322
|
+
return false;
|
|
330
323
|
this.params.uid = await this.uid;
|
|
331
324
|
switch (this.state?.name) {
|
|
332
325
|
case 'ok': {
|
|
@@ -338,14 +331,16 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
338
331
|
WORK.USER = undefined;
|
|
339
332
|
WORK.credentials = this.workSecure.setItem('credentials', this.params);
|
|
340
333
|
this.workSecure.setItem('KEY', null);
|
|
334
|
+
this.workSecure.flush?.();
|
|
341
335
|
|
|
342
336
|
location.reload();
|
|
343
337
|
} break;
|
|
344
|
-
case 'need-
|
|
345
|
-
this.check();
|
|
338
|
+
case 'need-login': {
|
|
339
|
+
await this.check(true);
|
|
346
340
|
} break;
|
|
347
341
|
case 'changed':
|
|
348
342
|
case 'unregistered': {
|
|
343
|
+
this.error = null;
|
|
349
344
|
try {
|
|
350
345
|
const registrationId = globalThis.crypto?.randomUUID?.() || WORK.genGUID?.() || (Date.now().toString(36) + Math.random().toString(36).slice(2));
|
|
351
346
|
const regPayload = { ...this.params, registrationId, ...(this.pendingInviteToken ? { inviteToken: this.pendingInviteToken } : {}) };
|
|
@@ -364,7 +359,6 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
364
359
|
}
|
|
365
360
|
} break;
|
|
366
361
|
}
|
|
367
|
-
this.error = null;
|
|
368
362
|
return true;
|
|
369
363
|
},
|
|
370
364
|
async _onCode(e) {
|
|
@@ -418,7 +412,8 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
418
412
|
let privateKey = await window.crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
|
|
419
413
|
privateKey = WORK.arrayBufferToBase64(privateKey);
|
|
420
414
|
this.workSecure.setItem('KEY', privateKey);
|
|
421
|
-
|
|
415
|
+
this.workSecure.flush?.();
|
|
416
|
+
await this.check(true);
|
|
422
417
|
this.credentials = this.params;
|
|
423
418
|
this.isLogin = undefined;
|
|
424
419
|
}
|
|
@@ -428,14 +423,24 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
428
423
|
this.text = e.message;
|
|
429
424
|
}
|
|
430
425
|
},
|
|
431
|
-
check() {
|
|
432
|
-
|
|
426
|
+
async check(force = false) {
|
|
427
|
+
this.isLoggingIn = true;
|
|
428
|
+
this.error = null;
|
|
429
|
+
this.text = 'Выполняется вход в систему…';
|
|
430
|
+
try {
|
|
431
|
+
const res = await WORK.login(force);
|
|
433
432
|
this.error = null;
|
|
434
|
-
this.text = res;
|
|
435
|
-
|
|
433
|
+
this.text = res || '';
|
|
434
|
+
return res;
|
|
435
|
+
}
|
|
436
|
+
catch (e) {
|
|
436
437
|
this.error = e;
|
|
437
|
-
this.text = e
|
|
438
|
-
|
|
438
|
+
this.text = e?.message || String(e || '');
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
this.isLoggingIn = Boolean(WORK._loginInProgress);
|
|
443
|
+
}
|
|
439
444
|
}
|
|
440
445
|
})
|
|
441
446
|
|