odant-work 1.0.108 → 1.0.110

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.
@@ -1,4 +1,15 @@
1
1
  const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
2
+ function normalizePhoneClient(raw = '') {
3
+ let s = String(raw || '').trim().replace(/[\s().-]+/g, '');
4
+ if (!s) return '';
5
+ if (s.startsWith('00')) s = '+' + s.slice(2);
6
+ if (!s.startsWith('+')) {
7
+ if (/^8\d{10}$/.test(s)) s = '+7' + s.slice(1);
8
+ else if (/^7\d{10}$/.test(s)) s = '+' + s;
9
+ else return '';
10
+ }
11
+ return /^\+[1-9]\d{6,14}$/.test(s) ? s : '';
12
+ }
2
13
  ODA({ is: 'user-profile', imports: 'oda//otp.js',
3
14
  template:/* html */`
4
15
  <style>
@@ -10,13 +21,14 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
10
21
  padding: max(8px, var(--safe-top, 0px)) max(12px, var(--safe-right, 0px)) max(16px, var(--safe-bottom, 0px)) max(12px, var(--safe-left, 0px));
11
22
  box-sizing: border-box;
12
23
  }
13
- input {
24
+ input, textarea {
14
25
  border: 1px solid gray;
15
26
  padding: 8px;
16
27
  border-radius: 8px;
17
28
  font-size: large;
18
29
  width: 100%;
19
30
  box-sizing: border-box;
31
+ font-family: inherit;
20
32
  }
21
33
  button {
22
34
  min-height: 44px;
@@ -49,27 +61,131 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
49
61
  border-radius: 8px;
50
62
  padding: 6px 8px;
51
63
  }
64
+ .mode-switch {
65
+ display: flex;
66
+ width: 100%;
67
+ gap: 6px;
68
+ background: rgba(100,116,139,0.12);
69
+ padding: 4px;
70
+ border-radius: 10px;
71
+ box-sizing: border-box;
72
+ }
73
+ .mode-switch button {
74
+ flex: 1 1 0;
75
+ min-height: 34px;
76
+ padding: 6px 10px;
77
+ font-size: 13px;
78
+ font-weight: 600;
79
+ border: none;
80
+ border-radius: 8px;
81
+ background: transparent;
82
+ color: inherit;
83
+ }
84
+ .mode-switch button.active {
85
+ background: var(--content-background, #ffffff);
86
+ box-shadow: 0 1px 3px rgba(0,0,0,0.12);
87
+ }
88
+ .disabled-box {
89
+ display: flex;
90
+ flex-direction: column;
91
+ gap: 10px;
92
+ width: 100%;
93
+ padding: 14px;
94
+ border-radius: 12px;
95
+ border: 1px solid rgba(239,68,68,0.35);
96
+ background: rgba(239,68,68,0.06);
97
+ box-sizing: border-box;
98
+ text-align: center;
99
+ }
100
+ .support-card {
101
+ padding: 8px 10px;
102
+ border-radius: 8px;
103
+ background: rgba(255,255,255,0.7);
104
+ border: 1px solid rgba(148,163,184,0.35);
105
+ font-size: 13px;
106
+ line-height: 1.45;
107
+ text-align: left;
108
+ }
109
+ .phone-bind-row {
110
+ display: flex;
111
+ gap: 8px;
112
+ width: 100%;
113
+ align-items: center;
114
+ }
115
+ .phone-bind-row input {
116
+ flex: 1 1 auto;
117
+ font-size: medium;
118
+ }
119
+ .phone-bind-row button {
120
+ min-height: 38px;
121
+ padding: 6px 12px;
122
+ font-size: 13px;
123
+ white-space: nowrap;
124
+ }
52
125
  </style>
53
126
  <div no-flex vertical class="profile-wrap">
54
127
  <div ~if="pendingInvite?.valid" style="padding:10px 12px;border-radius:8px;border:1px solid #10b981;background:rgba(16,185,129,0.1);font-size:small;line-height:1.4;text-align:center;">
55
128
  <b>Приглашение:</b> {{pendingInvite.pointLabel}} → <b>{{pendingInvite.placeLabel}}</b>
56
129
  </div>
57
- <div vertical style="gap: 16px; align-items: center;">
130
+ <div vertical style="gap: 14px; align-items: center;">
58
131
  <div class="photo" vertical style="padding: 16px; border-radius: 50%;">
59
132
  <oda-icon :icon="photoIcon" round @tap="!isOtherUser && loadPhoto()" style="border-radius: 50%; fill: white; color: white;" icon-size="180"></oda-icon>
60
133
  </div>
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">
134
+ <input id="name" :disabled="isOtherUser || state.name === 'disabled'" placeholder="Имя" ::value="params.name" name="name">
135
+ <input id="surname" :disabled="isOtherUser || state.name === 'disabled'" placeholder="Фамилия" ::value="params.surname" name="surname">
136
+ <input id="patronymic" :disabled="isOtherUser || state.name === 'disabled'" placeholder="Отчество" ::value="params.patronymic" name="patronymic">
137
+
138
+ <div ~if="!isOtherUser && !isLogin && !showCode && state.name !== 'disabled'" class="mode-switch">
139
+ <button type="button" :class="contactMode === 'email' ? 'active' : ''" @tap="contactMode = 'email'">Email</button>
140
+ <button type="button" :class="contactMode === 'phone' ? 'active' : ''" @tap="contactMode = 'phone'">Телефон</button>
141
+ </div>
142
+
143
+ <input ~if="contactMode === 'email' || isOtherUser || isLogin" id="email" :disabled="isOtherUser || isLogin || showCode || state.name === 'disabled'" placeholder="Email" ::value="params.email" type="email" name="email" :error="contactMode === 'email' && !correctEmail && !!params.email" :success="correctEmail">
144
+ <input ~if="!isOtherUser && !isLogin && contactMode === 'phone'" id="phone" :disabled="showCode || state.name === 'disabled'" placeholder="Телефон (+79991234567)" ::value="params.phone" type="tel" name="tel" :error="!!params.phone && !correctPhone" :success="correctPhone">
145
+
146
+ <div ~if="!isOtherUser && isLogin" vertical style="width:100%;gap:8px;">
147
+ <div class="phone-bind-row">
148
+ <input id="profilePhone" :disabled="showBindPhoneCode" placeholder="Телефон (+79991234567)" ::value="bindPhoneInput" type="tel">
149
+ <button type="button" class="info-invert" :disabled="!correctBindPhone || showBindPhoneCode" @tap.stop.prevent="bindPhoneStart">{{params.phone ? 'Сменить' : 'Привязать'}}</button>
150
+ </div>
151
+ <div ~if="params.phone" style="font-size:12px;color:#059669;">Подтверждённый телефон для входа: <b>{{params.phone}}</b></div>
152
+ <oda-otp-input ~if="showBindPhoneCode" center @complete="_onBindPhoneCode"></oda-otp-input>
153
+ <div ~if="bindPhoneText" style="font-size:12.5px;text-align:center;" :error="!!bindPhoneError">{{bindPhoneText}}</div>
154
+ </div>
155
+
65
156
  <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;">
157
+ <button ~if="!isOtherUser && state.label && !showCode && state.name !== 'disabled'" center horizontal :disabled="!correctContact" flex raised :class="state.class" @tap.stop.prevent="register_start" style="gap: 8px;align-items: center;">
67
158
  <span>{{state.label}}</span>
68
159
  <oda-icon ~if="state.icon" :icon="state.icon"></oda-icon>
69
160
  </button>
161
+
162
+ <div ~if="!isOtherUser && state.name === 'disabled'" class="disabled-box">
163
+ <div style="font-weight:700;color:#b91c1c;">Учётная запись отключена администратором</div>
164
+ <div style="font-size:13.5px;line-height:1.45;">Обратитесь к администратору или войдите с другой учётной записью.</div>
165
+ <div ~if="supportContact" class="support-card">
166
+ <div ~if="supportContact.label"><b>Контакт:</b> {{supportContact.label}}</div>
167
+ <div ~if="supportContact.email"><b>Email:</b> {{supportContact.email}}</div>
168
+ <div ~if="supportContact.phone"><b>Телефон:</b> {{supportContact.phone}}</div>
169
+ <div ~if="supportContact.note">{{supportContact.note}}</div>
170
+ </div>
171
+ <div style="display:flex;flex-direction:column;gap:8px;margin-top:4px;">
172
+ <button type="button" class="info-invert" @tap.stop.prevent="switchAccount">Войти с другим аккаунтом</button>
173
+ <button type="button" @tap.stop.prevent="openAppealForm" ~if="!showAppeal && !appealSent">Написать администратору</button>
174
+ <div ~if="showAppeal && !appealSent" style="display:flex;flex-direction:column;gap:8px;text-align:left;">
175
+ <textarea rows="3" placeholder="Краткое сообщение администратору…" ::value="appealMessage" style="font-size:14px;"></textarea>
176
+ <div style="display:flex;gap:8px;">
177
+ <button type="button" class="success-invert" style="flex:1;" :disabled="appealBusy || !appealMessage?.trim()" @tap.stop.prevent="sendAppeal">{{appealBusy ? 'Отправка…' : 'Отправить'}}</button>
178
+ <button type="button" @tap.stop.prevent="showAppeal = false">Отмена</button>
179
+ </div>
180
+ </div>
181
+ <div ~if="appealSent" style="font-size:13px;color:#059669;font-weight:600;">{{appealStatusText}}</div>
182
+ <div ~if="appealError" style="font-size:12.5px;color:#b91c1c;">{{appealError}}</div>
183
+ <button type="button" style="min-height:34px;font-size:13px;background:transparent;border:1px solid rgba(100,116,139,0.4);" @tap.stop.prevent="check(true)">Проверить снова</button>
184
+ </div>
185
+ </div>
70
186
  </div>
71
- <div flex style="text-align: center;" ~html="state.legend"></div>
72
- <div flex style="text-align: center;" :error="!!error" @tap="fill_code">{{text}}</div>
187
+ <div ~if="state.name !== 'disabled'" flex style="text-align: center;" ~html="state.legend"></div>
188
+ <div ~if="state.name !== 'disabled'" flex style="text-align: center;" :error="!!error" @tap="fill_code">{{text}}</div>
73
189
  </div>
74
190
  `,
75
191
  $item: {
@@ -81,6 +197,18 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
81
197
  error: null,
82
198
  text: '',
83
199
  isLoggingIn: false,
200
+ contactMode: 'email',
201
+ supportContact: null,
202
+ showAppeal: false,
203
+ appealMessage: '',
204
+ appealBusy: false,
205
+ appealSent: false,
206
+ appealStatusText: '',
207
+ appealError: '',
208
+ bindPhoneInput: '',
209
+ showBindPhoneCode: false,
210
+ bindPhoneText: '',
211
+ bindPhoneError: false,
84
212
  get isOtherUser() {
85
213
  return Boolean(this.$item?.id && WORK?.uid && this.$item.id !== WORK.uid);
86
214
  },
@@ -101,11 +229,20 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
101
229
  const errMsg = String(this.error?.message || this.error || '');
102
230
  const isDisabledAccount = /отключена администратором|account_disabled/i.test(errMsg) || Boolean(WORK?._accountDisabled);
103
231
  const keyRejected = !isDisabledAccount && /user not registered|need publickey|login failed|challenge issued for another user/i.test(errMsg);
232
+ if (isDisabledAccount && !this.isLogin)
233
+ return {
234
+ name: 'disabled',
235
+ label: '',
236
+ legend: 'Учётная запись отключена администратором. Обратитесь к администратору или войдите с другой учётной записью.',
237
+ class: 'error-invert'
238
+ };
104
239
  if(!this.isRegistered || !this.hasKey || keyRejected)
105
240
  return {
106
241
  name: 'unregistered',
107
242
  label: 'Register KEY',
108
- legend: 'Для входа в систему необходимо зарегистрировать ключ безопасности. <p>Ключ будет создан на Вашем устройстве, и привязан к адресу электронной почты.',
243
+ legend: this.contactMode === 'phone'
244
+ ? 'Для входа в систему необходимо зарегистрировать ключ безопасности. <p>Ключ будет создан на Вашем устройстве и привязан к номеру телефона.'
245
+ : 'Для входа в систему необходимо зарегистрировать ключ безопасности. <p>Ключ будет создан на Вашем устройстве, и привязан к адресу электронной почты.',
109
246
  class: 'success-invert'
110
247
  }
111
248
  if(!this.isLogin) {
@@ -116,13 +253,6 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
116
253
  legend: 'Выполняется вход в систему…',
117
254
  class: 'info-invert'
118
255
  }
119
- if (isDisabledAccount)
120
- return {
121
- name: 'need-login',
122
- label: 'Повторить вход',
123
- legend: 'Учётная запись отключена администратором. После повторного включения нажмите «Повторить вход».',
124
- class: 'error-invert'
125
- }
126
256
  return {
127
257
  name: 'need-login',
128
258
  label: 'Войти',
@@ -204,8 +334,8 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
204
334
  return !!WORK.uid && this.credentials?.uid === WORK.uid;
205
335
  },
206
336
  get isChanged() {
207
- for(let key in this.params){
208
- if(this.credentials?.[key] !== this.params[key])
337
+ for (const key of ['name', 'surname', 'patronymic', 'email', 'icon']) {
338
+ if ((this.credentials?.[key] || '') !== (this.params[key] || ''))
209
339
  return true;
210
340
  }
211
341
  return false;
@@ -214,6 +344,7 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
214
344
  attached() {
215
345
  this._syncFromItem(this.$item);
216
346
  this._loadPendingInvite();
347
+ this._loadSupportContact();
217
348
  this._onAuthState = () => {
218
349
  if (this.isOtherUser)
219
350
  return;
@@ -221,6 +352,7 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
221
352
  if (WORK._loginError) {
222
353
  this.error = WORK._loginError;
223
354
  this.text = WORK._loginError?.message || String(WORK._loginError);
355
+ this._loadSupportContact();
224
356
  }
225
357
  else if (this.isLogin) {
226
358
  this.error = null;
@@ -232,6 +364,16 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
232
364
  WORK.authEvents?.addEventListener?.('auth', this._onAuthState);
233
365
  WORK.authEvents?.addEventListener?.('login-state', this._onAuthState);
234
366
  },
367
+ async _loadSupportContact() {
368
+ if (this._supportContactLoaded)
369
+ return;
370
+ this._supportContactLoaded = true;
371
+ try {
372
+ const res = await WORK.fetch('/', 'support_contact_info', {});
373
+ this.supportContact = res?.contact || null;
374
+ }
375
+ catch { /* ignore */ }
376
+ },
235
377
  detached() {
236
378
  if (this._onAuthState) {
237
379
  WORK.authEvents?.removeEventListener?.('auth', this._onAuthState);
@@ -250,6 +392,7 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
250
392
  surname: d.surname || '',
251
393
  patronymic: d.patronymic || '',
252
394
  email: d.email || '',
395
+ phone: d.phone || '',
253
396
  icon: item.icon || d.icon || '',
254
397
  };
255
398
  this.error = null;
@@ -258,6 +401,15 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
258
401
  return;
259
402
  }
260
403
  this.credentials = this.workSecure.getItem('credentials');
404
+ if (this.credentials?.phone && !this.bindPhoneInput)
405
+ this.bindPhoneInput = this.credentials.phone;
406
+ if (WORK.USER?.DATA?.phone && !this.params.phone) {
407
+ this.params.phone = WORK.USER.DATA.phone;
408
+ if (!this.bindPhoneInput)
409
+ this.bindPhoneInput = WORK.USER.DATA.phone;
410
+ }
411
+ if (this.credentials && !this.credentials.email && this.credentials.phone)
412
+ this.contactMode = 'phone';
261
413
  this.isLoggingIn = Boolean(WORK._loginInProgress);
262
414
  if (WORK._loginError) {
263
415
  this.error = WORK._loginError;
@@ -278,8 +430,14 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
278
430
  const info = await WORK.fetch('/', 'invite_info', {}, { token: tok });
279
431
  if (info?.valid) {
280
432
  this.pendingInvite = info;
281
- if (info.channel === 'email' && info.recipient && !this.params.email)
433
+ if (info.channel === 'email' && info.recipient && !this.params.email) {
434
+ this.contactMode = 'email';
282
435
  this.params.email = info.recipient;
436
+ }
437
+ else if (info.channel === 'phone' && info.recipient && !this.params.phone) {
438
+ this.contactMode = 'phone';
439
+ this.params.phone = info.recipient;
440
+ }
283
441
  }
284
442
  }
285
443
  catch { /* ignore */ }
@@ -302,18 +460,41 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
302
460
  if (trimmed.length > 254 || !trimmed.includes('@')) return false;
303
461
  return emailRegex.test(trimmed);
304
462
  },
463
+ get correctPhone() {
464
+ this.uid = undefined;
465
+ this.photoColor = undefined;
466
+ return Boolean(normalizePhoneClient(this.params.phone || ''));
467
+ },
468
+ get correctContact() {
469
+ return this.contactMode === 'phone' ? this.correctPhone : this.correctEmail;
470
+ },
471
+ get correctBindPhone() {
472
+ return Boolean(normalizePhoneClient(this.bindPhoneInput || ''));
473
+ },
305
474
  params: {
306
475
  name: '',
307
476
  surname: '',
308
477
  patronymic: '',
309
478
  email: '',
479
+ phone: '',
310
480
  icon: '',
311
481
  get label(){
312
- return ((this.surname || '') + ' ' + (this.name || '') + ' ' + (this.patronymic || '')).trim() || this.email;
482
+ return ((this.surname || '') + ' ' + (this.name || '') + ' ' + (this.patronymic || '')).trim() || this.email || this.phone;
313
483
  }
314
484
  },
315
485
  get uid() {
316
- return crypto.subtle.digest('SHA-256', new TextEncoder().encode(this.params.email)).then(hashBuffer => {
486
+ if (this._resolvedRegUid)
487
+ return Promise.resolve(this._resolvedRegUid);
488
+ if (this.contactMode === 'phone') {
489
+ const norm = normalizePhoneClient(this.params.phone || '');
490
+ if (!norm)
491
+ return Promise.resolve('');
492
+ return crypto.subtle.digest('SHA-256', new TextEncoder().encode('tel:' + norm)).then(hashBuffer => {
493
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
494
+ return hashArray.map(b => b.toString(16).padStart(2, '0')).join('').slice(0, 16).toUpperCase();
495
+ });
496
+ }
497
+ return crypto.subtle.digest('SHA-256', new TextEncoder().encode(this.params.email || '')).then(hashBuffer => {
317
498
  const hashArray = Array.from(new Uint8Array(hashBuffer));
318
499
  const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
319
500
  const userId = hashHex.slice(0, 16);
@@ -349,11 +530,22 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
349
530
  case 'changed':
350
531
  case 'unregistered': {
351
532
  this.error = null;
533
+ this._resolvedRegUid = '';
352
534
  try {
353
535
  const registrationId = globalThis.crypto?.randomUUID?.() || WORK.genGUID?.() || (Date.now().toString(36) + Math.random().toString(36).slice(2));
354
- const regPayload = { ...this.params, registrationId, ...(this.pendingInviteToken ? { inviteToken: this.pendingInviteToken } : {}) };
536
+ const regPayload = {
537
+ ...this.params,
538
+ contactType: this.contactMode,
539
+ ...(this.contactMode === 'phone' ? { phone: normalizePhoneClient(this.params.phone || ''), email: '' } : { phone: '' }),
540
+ registrationId,
541
+ ...(this.pendingInviteToken ? { inviteToken: this.pendingInviteToken } : {}),
542
+ };
355
543
  const res = await WORK.fetch("/", 'user_register_start', {}, regPayload);
356
544
  this._registrationId = registrationId;
545
+ if (res && typeof res === 'object' && res.uid) {
546
+ this._resolvedRegUid = res.uid;
547
+ this.params.uid = res.uid;
548
+ }
357
549
  if (res && typeof res === 'object' && res.autoCode) {
358
550
  this.text = res.message || 'Идет процесс регистрации ключа безопасности...';
359
551
  await this._onCode({ detail: { value: res.autoCode } });
@@ -378,6 +570,12 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
378
570
 
379
571
  // 1. Проверяем код и получаем challenge
380
572
  let options = await WORK.fetch("/", 'user_register_process', regQuery, this.params);
573
+ if (options?.uid)
574
+ this.params.uid = this._resolvedRegUid = options.uid;
575
+ if (options?.email && !this.params.email)
576
+ this.params.email = options.email;
577
+ if (options?.phone && !this.params.phone)
578
+ this.params.phone = options.phone;
381
579
 
382
580
  // 2. Создаем ключи
383
581
  const keyPair = await window.crypto.subtle.generateKey({
@@ -404,6 +602,7 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
404
602
  };
405
603
  const resp = await WORK.fetch("/", 'user_register_finish', {}, finishPayload);
406
604
  this._registrationId = '';
605
+ this._resolvedRegUid = '';
407
606
  if (this.pendingInviteToken) {
408
607
  try { sessionStorage.removeItem('work.pendingInviteToken'); } catch { /* ignore */ }
409
608
  this.pendingInviteToken = '';
@@ -423,6 +622,8 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
423
622
  this.workSecure.flush?.();
424
623
  await this.check(true);
425
624
  this.credentials = this.params;
625
+ if (this.params.phone)
626
+ this.bindPhoneInput = this.params.phone;
426
627
  this.isLogin = undefined;
427
628
  }
428
629
  catch (e) {
@@ -431,6 +632,119 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
431
632
  this.text = e.message;
432
633
  }
433
634
  },
635
+ async switchAccount() {
636
+ const msg = 'Текущие локальные данные и ключ входа на этом устройстве будут очищены для входа в другой аккаунт. Продолжить?';
637
+ try {
638
+ if (typeof WORK?.showConfirm === 'function')
639
+ await WORK.showConfirm(msg);
640
+ else if (!window.confirm(msg))
641
+ return;
642
+ }
643
+ catch {
644
+ return;
645
+ }
646
+ this.workSecure.setItem('credentials', null);
647
+ this.workSecure.setItem('KEY', null);
648
+ this.workSecure.flush?.();
649
+ WORK._accountDisabled = false;
650
+ WORK._disabledUid = '';
651
+ WORK._loginError = null;
652
+ WORK.uid = '';
653
+ WORK.USER = undefined;
654
+ this.credentials = null;
655
+ this.error = null;
656
+ this.text = '';
657
+ this.showCode = false;
658
+ this.showAppeal = false;
659
+ this.appealSent = false;
660
+ this.appealError = '';
661
+ this._resolvedRegUid = '';
662
+ this.params = { ...this.params, uid: undefined, email: '', phone: '', name: '', surname: '', patronymic: '', icon: '' };
663
+ this.isLogin = undefined;
664
+ },
665
+ openAppealForm() {
666
+ this.showAppeal = true;
667
+ this.appealError = '';
668
+ },
669
+ async sendAppeal() {
670
+ const msg = String(this.appealMessage || '').trim();
671
+ if (!msg || this.appealBusy)
672
+ return;
673
+ this.appealBusy = true;
674
+ this.appealError = '';
675
+ try {
676
+ const creds = this.workSecure.getItem('credentials');
677
+ const rawKey = this.workSecure.getItem('KEY');
678
+ const uid = creds?.uid;
679
+ if (!uid || !rawKey)
680
+ throw new Error('Локальный ключ подписи не найден');
681
+ const challengeId = globalThis.crypto?.randomUUID?.() || (Date.now().toString(36) + Math.random().toString(36).slice(2));
682
+ const challenge = await WORK.fetch('/', 'user_login_appeal_challenge', { uid, challengeId });
683
+ const keyBytes = Uint8Array.from(atob(rawKey), c => c.charCodeAt(0));
684
+ const privateKey = await crypto.subtle.importKey('pkcs8', keyBytes, { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, true, ['sign']);
685
+ const sigBuf = await crypto.subtle.sign({ name: 'RSASSA-PKCS1-v1_5' }, privateKey, new TextEncoder().encode(challenge));
686
+ const signature = WORK.arrayBufferToBase64(sigBuf);
687
+ const res = await WORK.fetch('/', 'user_appeal_disabled', {}, {
688
+ uid,
689
+ time: creds.time,
690
+ challengeId,
691
+ signature,
692
+ message: msg,
693
+ });
694
+ this.appealSent = true;
695
+ this.showAppeal = false;
696
+ this.appealStatusText = res?.message || 'Обращение отправлено администратору.';
697
+ }
698
+ catch (err) {
699
+ this.appealError = err?.message || String(err || 'Не удалось отправить обращение');
700
+ }
701
+ finally {
702
+ this.appealBusy = false;
703
+ }
704
+ },
705
+ async bindPhoneStart() {
706
+ const norm = normalizePhoneClient(this.bindPhoneInput || '');
707
+ if (!norm)
708
+ return;
709
+ this.bindPhoneError = false;
710
+ this.bindPhoneText = 'Отправка кода…';
711
+ try {
712
+ const res = await WORK.fetch('/', 'user_bind_phone_start', {}, { phone: norm });
713
+ this.showBindPhoneCode = true;
714
+ this.bindPhoneText = res?.message || 'Введите код подтверждения';
715
+ }
716
+ catch (err) {
717
+ this.bindPhoneError = true;
718
+ this.bindPhoneText = err?.message || String(err || 'Ошибка отправки кода');
719
+ }
720
+ },
721
+ async _onBindPhoneCode(e) {
722
+ try {
723
+ const code = await e.detail.value;
724
+ const res = await WORK.fetch('/', 'user_bind_phone_finish', {}, { code });
725
+ this.showBindPhoneCode = false;
726
+ this.bindPhoneError = false;
727
+ this.bindPhoneText = 'Телефон успешно подтверждён: ' + (res?.phone || this.bindPhoneInput);
728
+ if (res?.phone) {
729
+ this.params.phone = res.phone;
730
+ this.bindPhoneInput = res.phone;
731
+ const curCreds = this.workSecure.getItem('credentials');
732
+ if (curCreds) {
733
+ curCreds.phone = res.phone;
734
+ this.workSecure.setItem('credentials', curCreds);
735
+ this.workSecure.flush?.();
736
+ }
737
+ }
738
+ }
739
+ catch (err) {
740
+ this.bindPhoneError = true;
741
+ this.bindPhoneText = err?.message || String(err || 'Неверный код');
742
+ if (/неверный проверочный код/i.test(this.bindPhoneText))
743
+ this.showBindPhoneCode = true;
744
+ else
745
+ this.showBindPhoneCode = false;
746
+ }
747
+ },
434
748
  async check(force = false) {
435
749
  this.isLoggingIn = true;
436
750
  this.error = null;
@@ -33,7 +33,9 @@ export const MEMBERS = Object.freeze({
33
33
  // вход и публичное
34
34
  user_register_start: L.PUBLIC, user_register_process: L.PUBLIC, user_register_finish: L.PUBLIC,
35
35
  user_login_start: L.PUBLIC, user_login_finish: L.PUBLIC, user_exit: L.PUBLIC,
36
- get_public_vapid: L.PUBLIC,
36
+ user_login_appeal_challenge: L.PUBLIC, user_appeal_disabled: L.PUBLIC,
37
+ user_bind_phone_start: L.AUTH, user_bind_phone_finish: L.AUTH,
38
+ get_public_vapid: L.PUBLIC, support_contact_info: L.PUBLIC,
37
39
  // чтение
38
40
  info: L.READ, load: L.READ, download: L.READ, read_text: L.READ, get_imports: L.READ, office_load: L.READ,
39
41
  get_schema: L.READ, services_schema: L.READ, handlers: L.READ, manifest: L.READ,
@@ -95,6 +97,7 @@ export const MEMBERS = Object.freeze({
95
97
  save_secret: L.BOSS, clear_rag: L.BOSS, security_log: L.BOSS, agent_panel: L.BOSS,
96
98
  set_enabled: L.BOSS, export_archive: L.READ, import_archive: L.BOSS, delete_log_entry: L.WRITE,
97
99
  distro_info: L.READ, export_distro: L.READ, version_status: L.READ, version_update_restart: L.BOSS,
100
+ sms_settings_get: L.BOSS, sms_settings_save: L.BOSS, sms_settings_test: L.BOSS,
98
101
  });
99
102
 
100
103
  /** Никогда не вызываются снаружи, даже если объявлены в class.js. */