@fiduswriter/frontend 0.1.72 → 0.1.73
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/css/login.css +268 -0
- package/css/show_profile.css +111 -40
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +1 -0
- package/dist/app/index.js.map +1 -1
- package/dist/common/user_util.d.ts +8 -1
- package/dist/common/user_util.d.ts.map +1 -1
- package/dist/common/user_util.js +24 -0
- package/dist/common/user_util.js.map +1 -1
- package/dist/css/fwtoolkit/data_table.css +31 -6
- package/dist/css/fwtoolkit/dialog.css +51 -0
- package/dist/css/fwtoolkit/fwtoolkit.css +157 -26
- package/dist/css/fwtoolkit/inline_tools.css +5 -8
- package/dist/css/fwtoolkit/overview_menu.css +70 -12
- package/dist/css/login.css +268 -0
- package/dist/css/manifest.json +1 -0
- package/dist/css/show_profile.css +111 -40
- package/dist/feedback/index.d.ts.map +1 -1
- package/dist/feedback/index.js +6 -1
- package/dist/feedback/index.js.map +1 -1
- package/dist/menu/index.d.ts.map +1 -1
- package/dist/menu/index.js +16 -2
- package/dist/menu/index.js.map +1 -1
- package/dist/user/auth/login.d.ts +14 -0
- package/dist/user/auth/login.d.ts.map +1 -1
- package/dist/user/auth/login.js +253 -131
- package/dist/user/auth/login.js.map +1 -1
- package/dist/user/profile/dialog.d.ts +72 -0
- package/dist/user/profile/dialog.d.ts.map +1 -0
- package/dist/user/profile/dialog.js +436 -0
- package/dist/user/profile/dialog.js.map +1 -0
- package/dist/user/profile/dialogs.d.ts +6 -6
- package/dist/user/profile/dialogs.d.ts.map +1 -1
- package/dist/user/profile/dialogs.js +29 -14
- package/dist/user/profile/dialogs.js.map +1 -1
- package/dist/user/profile/index.d.ts +12 -14
- package/dist/user/profile/index.d.ts.map +1 -1
- package/dist/user/profile/index.js +35 -236
- package/dist/user/profile/index.js.map +1 -1
- package/dist/user/profile/templates.d.ts +14 -1
- package/dist/user/profile/templates.d.ts.map +1 -1
- package/dist/user/profile/templates.js +178 -191
- package/dist/user/profile/templates.js.map +1 -1
- package/package.json +3 -2
- package/src/app/index.ts +1 -0
- package/src/common/user_util.ts +26 -1
- package/src/feedback/index.ts +8 -1
- package/src/menu/index.ts +19 -2
- package/src/user/auth/login.ts +338 -153
- package/src/user/profile/dialog.ts +609 -0
- package/src/user/profile/dialogs.ts +51 -14
- package/src/user/profile/index.ts +37 -334
- package/src/user/profile/templates.ts +222 -223
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BooleanSwitch,
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogTabs,
|
|
5
|
+
activateWait,
|
|
6
|
+
addAlert,
|
|
7
|
+
deactivateWait,
|
|
8
|
+
dropdownSelect,
|
|
9
|
+
ensureCSS,
|
|
10
|
+
findTarget,
|
|
11
|
+
initFloatingLabels
|
|
12
|
+
} from "fwtoolkit"
|
|
13
|
+
|
|
14
|
+
import type {FrontendApp, User} from "../../types.js"
|
|
15
|
+
import type {PluginList} from "../../app/index.js"
|
|
16
|
+
import {refreshUserChrome} from "../../common/user_util.js"
|
|
17
|
+
import {DeleteUserDialog} from "./delete_user.js"
|
|
18
|
+
import {
|
|
19
|
+
addEmailDialog,
|
|
20
|
+
changeAvatarDialog,
|
|
21
|
+
changePrimaryEmailDialog,
|
|
22
|
+
changePwdDialog,
|
|
23
|
+
deleteAvatarDialog,
|
|
24
|
+
deleteEmailDialog,
|
|
25
|
+
deleteSocialaccountDialog
|
|
26
|
+
} from "./dialogs.js"
|
|
27
|
+
import {
|
|
28
|
+
profileAvatarTemplate,
|
|
29
|
+
profileBasicsTemplate,
|
|
30
|
+
profileEditorTemplate,
|
|
31
|
+
profileEmailsTemplate,
|
|
32
|
+
profileLanguageTemplate,
|
|
33
|
+
profilePluginTemplate,
|
|
34
|
+
profileSocialAccountsTemplate
|
|
35
|
+
} from "./templates.js"
|
|
36
|
+
|
|
37
|
+
export interface ProfileDialogOptions {
|
|
38
|
+
app: FrontendApp
|
|
39
|
+
user: User & {id?: number}
|
|
40
|
+
socialaccount_providers: Array<Record<string, unknown>>
|
|
41
|
+
profilePlugins?: PluginList
|
|
42
|
+
onClose?: () => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Design 5 "Configure profile" dialog.
|
|
47
|
+
*
|
|
48
|
+
* A tab dialog whose action buttons ("Delete account" and the primary
|
|
49
|
+
* "Confirm") sit in the title bar (`buttonsTop`), matching the design.
|
|
50
|
+
*
|
|
51
|
+
* The class also provides the plugin host surface used by profile plugins
|
|
52
|
+
* (`pluginTemplates`, `clickTargets`, `postRenderHandlers`, `save`, `dom`,
|
|
53
|
+
* `user`, `app`), so existing plugins keep working unchanged.
|
|
54
|
+
*/
|
|
55
|
+
export class ProfileDialog {
|
|
56
|
+
app: FrontendApp
|
|
57
|
+
user: User & {id?: number}
|
|
58
|
+
socialaccount_providers: Array<Record<string, unknown>>
|
|
59
|
+
pluginTemplates: string[]
|
|
60
|
+
clickTargets: Record<string, (el: Record<string, any>, event: Event) => void>
|
|
61
|
+
postRenderHandlers: Array<() => void>
|
|
62
|
+
plugins: Record<string, {init(): void}> | null
|
|
63
|
+
dom!: HTMLElement
|
|
64
|
+
profilePlugins: PluginList
|
|
65
|
+
dialog: Dialog | null
|
|
66
|
+
dialogTabs: DialogTabs | null
|
|
67
|
+
dirty: boolean
|
|
68
|
+
twoFactorSwitch: BooleanSwitch | null
|
|
69
|
+
twoFactorEnabled: boolean
|
|
70
|
+
onClose: (() => void) | false
|
|
71
|
+
activeTab: number
|
|
72
|
+
redraw = (): void => this.refreshContent()
|
|
73
|
+
|
|
74
|
+
constructor({
|
|
75
|
+
app,
|
|
76
|
+
user,
|
|
77
|
+
socialaccount_providers,
|
|
78
|
+
profilePlugins = [],
|
|
79
|
+
onClose
|
|
80
|
+
}: ProfileDialogOptions) {
|
|
81
|
+
this.app = app
|
|
82
|
+
this.user = user
|
|
83
|
+
this.socialaccount_providers = socialaccount_providers
|
|
84
|
+
this.profilePlugins = profilePlugins
|
|
85
|
+
this.pluginTemplates = []
|
|
86
|
+
this.plugins = null
|
|
87
|
+
this.dialog = null
|
|
88
|
+
this.dialogTabs = null
|
|
89
|
+
this.dirty = false
|
|
90
|
+
this.twoFactorSwitch = null
|
|
91
|
+
this.twoFactorEnabled = false
|
|
92
|
+
this.onClose = onClose || false
|
|
93
|
+
this.activeTab = 0
|
|
94
|
+
this.clickTargets = {
|
|
95
|
+
"#add-profile-email": (_el, _event) =>
|
|
96
|
+
addEmailDialog(this.app, this.redraw),
|
|
97
|
+
"#fw-edit-profile-pwd": (_el, _event) =>
|
|
98
|
+
changePwdDialog({username: this.user.username, app: this.app}),
|
|
99
|
+
".delete-email": (el, _event) =>
|
|
100
|
+
deleteEmailDialog(el.target, this.app, this.redraw),
|
|
101
|
+
".delete-socialaccount": (el, _event) =>
|
|
102
|
+
deleteSocialaccountDialog(el.target, this.app, this.redraw)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.postRenderHandlers = [
|
|
106
|
+
() => {
|
|
107
|
+
dropdownSelect(
|
|
108
|
+
this.dom.querySelector(
|
|
109
|
+
"#edit-avatar-pulldown"
|
|
110
|
+
) as HTMLSelectElement,
|
|
111
|
+
{
|
|
112
|
+
onChange: (value: string | false) => {
|
|
113
|
+
switch (value) {
|
|
114
|
+
case "change":
|
|
115
|
+
changeAvatarDialog(this.app, this.redraw)
|
|
116
|
+
break
|
|
117
|
+
case "delete":
|
|
118
|
+
deleteAvatarDialog(this.app, this.redraw)
|
|
119
|
+
break
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
button: this.dom.querySelector(
|
|
123
|
+
"#edit-avatar-btn"
|
|
124
|
+
) as HTMLElement | false | undefined
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
},
|
|
128
|
+
() => {
|
|
129
|
+
this.dom
|
|
130
|
+
.querySelectorAll(".primary-email-radio")
|
|
131
|
+
.forEach(el =>
|
|
132
|
+
el.addEventListener("change", () =>
|
|
133
|
+
changePrimaryEmailDialog(this.app, this.redraw)
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
if (this.app.settings.TWO_FACTOR_ENABLED) {
|
|
139
|
+
this.postRenderHandlers.push(() => this.initTwoFactorSwitch())
|
|
140
|
+
this.postRenderHandlers.push(() => this.updateTwoFactorStatus())
|
|
141
|
+
}
|
|
142
|
+
if (
|
|
143
|
+
this.app.settings.E2EE_MODE &&
|
|
144
|
+
this.app.settings.E2EE_MODE !== "disabled"
|
|
145
|
+
) {
|
|
146
|
+
this.clickTargets["#setup-e2ee-passphrase"] = (_el, _event) => {
|
|
147
|
+
this.setupE2EEPassphrase()
|
|
148
|
+
}
|
|
149
|
+
this.clickTargets["#change-e2ee-passphrase"] = (_el, _event) => {
|
|
150
|
+
this.changeE2EEPassphrase()
|
|
151
|
+
}
|
|
152
|
+
this.clickTargets["#recover-e2ee-passphrase"] = (_el, _event) => {
|
|
153
|
+
this.recoverE2EEPassphrase()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.postRenderHandlers.push(() =>
|
|
157
|
+
this.updateE2EEPassphraseStatus()
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
activateFidusPlugins(): void {
|
|
163
|
+
if (this.plugins) {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
this.plugins = {}
|
|
167
|
+
|
|
168
|
+
this.profilePlugins.forEach(([app, plugin]) => {
|
|
169
|
+
if (!this.app.settings.APPS.includes(app)) {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
Object.values(plugin).forEach(pluginExport => {
|
|
173
|
+
if (typeof pluginExport === "function") {
|
|
174
|
+
const name = (pluginExport as any).name
|
|
175
|
+
this.plugins![name] = new (pluginExport as any)(this)
|
|
176
|
+
this.plugins![name].init()
|
|
177
|
+
}
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
open(): void {
|
|
183
|
+
this.activateFidusPlugins()
|
|
184
|
+
ensureCSS([
|
|
185
|
+
staticUrl("css/show_profile.css"),
|
|
186
|
+
staticUrl("css/two_factor.css")
|
|
187
|
+
])
|
|
188
|
+
|
|
189
|
+
this.dialogTabs = new DialogTabs(this.buildTabs(), {
|
|
190
|
+
containerId: "profile-tabs",
|
|
191
|
+
onShow: index => {
|
|
192
|
+
this.activeTab = index
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
const dialog = new Dialog({
|
|
197
|
+
id: "profile-dialog",
|
|
198
|
+
title: gettext("Configure profile"),
|
|
199
|
+
width: 720,
|
|
200
|
+
scroll: true,
|
|
201
|
+
buttonsTop: true,
|
|
202
|
+
body: this.dialogTabs.render(),
|
|
203
|
+
onClose: this.onClose,
|
|
204
|
+
buttons: [
|
|
205
|
+
{
|
|
206
|
+
id: "delete-account",
|
|
207
|
+
text: gettext("Delete account"),
|
|
208
|
+
classes: "fw-dialog-button-link",
|
|
209
|
+
click: () => this.deleteAccount()
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
id: "submit-profile",
|
|
213
|
+
text: gettext("Confirm"),
|
|
214
|
+
classes: "fw-green fw-dialog-button-primary",
|
|
215
|
+
disabled: true,
|
|
216
|
+
click: () => this.save()
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
})
|
|
220
|
+
this.dialog = dialog
|
|
221
|
+
dialog.open()
|
|
222
|
+
|
|
223
|
+
this.dom = dialog.dialogEl.querySelector(
|
|
224
|
+
".fw-dialog-content"
|
|
225
|
+
) as HTMLElement
|
|
226
|
+
this.dialogTabs.bind(
|
|
227
|
+
this.dom.querySelector("#profile-tabs") as HTMLElement
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
initFloatingLabels(this.dom)
|
|
231
|
+
|
|
232
|
+
this.dom.addEventListener("click", (event: Event) => {
|
|
233
|
+
const el: Record<string, any> = {}
|
|
234
|
+
Object.entries(this.clickTargets).find(([selector, handler]) => {
|
|
235
|
+
if (findTarget(event, selector, el)) {
|
|
236
|
+
handler(el, event)
|
|
237
|
+
return true
|
|
238
|
+
}
|
|
239
|
+
return false
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
const markDirty = () => this.markDirty()
|
|
244
|
+
this.dom.addEventListener("input", markDirty)
|
|
245
|
+
this.dom.addEventListener("change", markDirty)
|
|
246
|
+
|
|
247
|
+
this.postRenderHandlers.forEach(handler => handler())
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
buildTabs() {
|
|
251
|
+
const settings = this.app.settings as Record<string, any>
|
|
252
|
+
const tabs = [
|
|
253
|
+
{
|
|
254
|
+
id: "profile-tab-basics",
|
|
255
|
+
title: gettext("Basics"),
|
|
256
|
+
template: () =>
|
|
257
|
+
profileBasicsTemplate(this.user, settings)
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
id: "profile-tab-avatar",
|
|
261
|
+
title: gettext("Profile image"),
|
|
262
|
+
template: () => profileAvatarTemplate(this.user)
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: "profile-tab-emails",
|
|
266
|
+
title: gettext("Email address"),
|
|
267
|
+
template: () => profileEmailsTemplate(this.user)
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
id: "profile-tab-language",
|
|
271
|
+
title: gettext("Language"),
|
|
272
|
+
template: () =>
|
|
273
|
+
profileLanguageTemplate(this.user, settings)
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
id: "profile-tab-editor",
|
|
277
|
+
title: gettext("Editor"),
|
|
278
|
+
template: () => profileEditorTemplate(this.user)
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
if (this.socialaccount_providers.length) {
|
|
282
|
+
tabs.push({
|
|
283
|
+
id: "profile-tab-social",
|
|
284
|
+
title: gettext("Social Account Providers"),
|
|
285
|
+
template: () =>
|
|
286
|
+
profileSocialAccountsTemplate(
|
|
287
|
+
this.user,
|
|
288
|
+
this.socialaccount_providers
|
|
289
|
+
)
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
if (this.pluginTemplates.length) {
|
|
293
|
+
tabs.push({
|
|
294
|
+
id: "profile-tab-extensions",
|
|
295
|
+
title: gettext("Extensions"),
|
|
296
|
+
template: () =>
|
|
297
|
+
profilePluginTemplate(this.pluginTemplates)
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
return tabs
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Redraw the tab contents in place after a sub-dialog changed something
|
|
305
|
+
* (avatar, e-mail addresses, …), keeping the dialog open on the tab the
|
|
306
|
+
* user was looking at.
|
|
307
|
+
*/
|
|
308
|
+
refreshContent(): void {
|
|
309
|
+
if (!this.dialog || !this.dialogTabs) {
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
this.updateUserData()
|
|
313
|
+
this.dom.innerHTML = this.dialogTabs.render()
|
|
314
|
+
const tabsEl = this.dom.querySelector("#profile-tabs") as HTMLElement
|
|
315
|
+
this.dialogTabs.bind(tabsEl)
|
|
316
|
+
if (this.activeTab) {
|
|
317
|
+
this.dialogTabs.showTab(this.activeTab, tabsEl)
|
|
318
|
+
}
|
|
319
|
+
initFloatingLabels(this.dom)
|
|
320
|
+
this.postRenderHandlers.forEach(handler => handler())
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
markDirty(): void {
|
|
324
|
+
if (this.dirty || !this.dialog) {
|
|
325
|
+
return
|
|
326
|
+
}
|
|
327
|
+
this.dirty = true
|
|
328
|
+
this.dialog.buttons.forEach(button => {
|
|
329
|
+
if (button.id === "submit-profile") {
|
|
330
|
+
button.disabled = false
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
this.dialog.refreshButtons()
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
resetDirty(): void {
|
|
337
|
+
this.dirty = false
|
|
338
|
+
if (!this.dialog) {
|
|
339
|
+
return
|
|
340
|
+
}
|
|
341
|
+
this.dialog.buttons.forEach(button => {
|
|
342
|
+
if (button.id === "submit-profile") {
|
|
343
|
+
button.disabled = true
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
this.dialog.refreshButtons()
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
deleteAccount(): void {
|
|
350
|
+
const dialog = new DeleteUserDialog(this.user.username, this.app)
|
|
351
|
+
dialog.init()
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
initTwoFactorSwitch(): void {
|
|
355
|
+
const host = this.dom.querySelector("#two-factor-switch-host")
|
|
356
|
+
if (!host) {
|
|
357
|
+
return
|
|
358
|
+
}
|
|
359
|
+
this.twoFactorSwitch = new BooleanSwitch({
|
|
360
|
+
id: "setup-two-factor",
|
|
361
|
+
label: "",
|
|
362
|
+
checked: this.twoFactorEnabled,
|
|
363
|
+
onChange: (checked: boolean) => {
|
|
364
|
+
if (checked === this.twoFactorEnabled) {
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
// The real enable/disable flows reload the page on success or
|
|
368
|
+
// leave the account state untouched on cancel; tie the switch
|
|
369
|
+
// back to the actual status while the dialog is open.
|
|
370
|
+
this.twoFactorSwitch!.input.checked = this.twoFactorEnabled
|
|
371
|
+
if (checked) {
|
|
372
|
+
import("../auth/two_factor.js").then(
|
|
373
|
+
({twoFactorSetupDialog}) => {
|
|
374
|
+
twoFactorSetupDialog(this.app)
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
} else {
|
|
378
|
+
import("../auth/two_factor.js").then(
|
|
379
|
+
({twoFactorDisableDialog}) => {
|
|
380
|
+
twoFactorDisableDialog(this.app)
|
|
381
|
+
}
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
host.replaceChildren(this.twoFactorSwitch.element)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
updateTwoFactorStatus(): void {
|
|
390
|
+
import("../auth/two_factor.js").then(({checkTwoFactorStatus}) => {
|
|
391
|
+
checkTwoFactorStatus(this.app).then((enabled: boolean) => {
|
|
392
|
+
const enabledStatus = this.dom.querySelector(
|
|
393
|
+
"#two-factor-enabled-status"
|
|
394
|
+
) as HTMLElement
|
|
395
|
+
const disabledStatus = this.dom.querySelector(
|
|
396
|
+
"#two-factor-disabled-status"
|
|
397
|
+
) as HTMLElement
|
|
398
|
+
|
|
399
|
+
if (enabledStatus) {
|
|
400
|
+
enabledStatus.style.display = enabled ? "inline" : "none"
|
|
401
|
+
}
|
|
402
|
+
if (disabledStatus) {
|
|
403
|
+
disabledStatus.style.display = enabled ? "none" : "inline"
|
|
404
|
+
}
|
|
405
|
+
if (this.twoFactorSwitch) {
|
|
406
|
+
this.twoFactorSwitch.input.checked = enabled
|
|
407
|
+
}
|
|
408
|
+
this.twoFactorEnabled = enabled
|
|
409
|
+
})
|
|
410
|
+
})
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
updateE2EEPassphraseStatus(): void {
|
|
414
|
+
import("fwtoolkit/e2ee/passphrase-manager").then(
|
|
415
|
+
({PassphraseManager}) => {
|
|
416
|
+
PassphraseManager.hasEncryptionKeys().then((hasKeys: boolean) => {
|
|
417
|
+
const enabledStatus = this.dom.querySelector(
|
|
418
|
+
"#e2ee-passphrase-enabled-status"
|
|
419
|
+
) as HTMLElement
|
|
420
|
+
const disabledStatus = this.dom.querySelector(
|
|
421
|
+
"#e2ee-passphrase-disabled-status"
|
|
422
|
+
) as HTMLElement
|
|
423
|
+
const setupBtn = this.dom.querySelector(
|
|
424
|
+
"#setup-e2ee-passphrase"
|
|
425
|
+
) as HTMLElement
|
|
426
|
+
const changeBtn = this.dom.querySelector(
|
|
427
|
+
"#change-e2ee-passphrase"
|
|
428
|
+
) as HTMLElement
|
|
429
|
+
const recoverBtn = this.dom.querySelector(
|
|
430
|
+
"#recover-e2ee-passphrase"
|
|
431
|
+
) as HTMLElement
|
|
432
|
+
|
|
433
|
+
if (hasKeys) {
|
|
434
|
+
enabledStatus.style.display = "inline"
|
|
435
|
+
disabledStatus.style.display = "none"
|
|
436
|
+
setupBtn.style.display = "none"
|
|
437
|
+
changeBtn.style.display = "inline"
|
|
438
|
+
recoverBtn.style.display = "inline"
|
|
439
|
+
} else {
|
|
440
|
+
enabledStatus.style.display = "none"
|
|
441
|
+
disabledStatus.style.display = "inline"
|
|
442
|
+
setupBtn.style.display = "inline"
|
|
443
|
+
changeBtn.style.display = "none"
|
|
444
|
+
recoverBtn.style.display = "none"
|
|
445
|
+
}
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async setupE2EEPassphrase(): Promise<void> {
|
|
452
|
+
const {PassphraseManager} = await import(
|
|
453
|
+
"fwtoolkit/e2ee/passphrase-manager"
|
|
454
|
+
)
|
|
455
|
+
const {setupPassphraseDialog} = await import(
|
|
456
|
+
"fwtoolkit/e2ee/passphrase-dialog"
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
setupPassphraseDialog(async (passphrase: string) => {
|
|
460
|
+
try {
|
|
461
|
+
const {recoveryKey} =
|
|
462
|
+
await PassphraseManager.setupEncryption(passphrase)
|
|
463
|
+
const {showRecoveryKeyDialog} = await import(
|
|
464
|
+
"fwtoolkit/e2ee/passphrase-dialog"
|
|
465
|
+
)
|
|
466
|
+
await showRecoveryKeyDialog(recoveryKey, () => {})
|
|
467
|
+
this.updateE2EEPassphraseStatus()
|
|
468
|
+
} catch (e: any) {
|
|
469
|
+
addAlert(
|
|
470
|
+
"error",
|
|
471
|
+
gettext("Failed to set up passphrase: ") + e.message
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
})
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async recoverE2EEPassphrase(): Promise<void> {
|
|
478
|
+
const {PassphraseManager} = await import(
|
|
479
|
+
"fwtoolkit/e2ee/passphrase-manager"
|
|
480
|
+
)
|
|
481
|
+
const {recoverWithKeyDialog, showRecoveryKeyDialog} = await import(
|
|
482
|
+
"fwtoolkit/e2ee/passphrase-dialog"
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
const recoverResult: any = await new Promise(resolve => {
|
|
486
|
+
recoverWithKeyDialog(resolve)
|
|
487
|
+
})
|
|
488
|
+
if (!recoverResult) {
|
|
489
|
+
return
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const {newRecoveryKey} =
|
|
493
|
+
await PassphraseManager.recoverWithRecoveryKey(
|
|
494
|
+
recoverResult.recoveryKey,
|
|
495
|
+
recoverResult.newPassphrase,
|
|
496
|
+
recoverResult.accountPassword
|
|
497
|
+
)
|
|
498
|
+
await new Promise<void>(resolve => {
|
|
499
|
+
showRecoveryKeyDialog(newRecoveryKey, resolve)
|
|
500
|
+
})
|
|
501
|
+
this.updateE2EEPassphraseStatus()
|
|
502
|
+
} catch (e: any) {
|
|
503
|
+
addAlert("error", gettext("Recovery failed: ") + e.message)
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async changeE2EEPassphrase(): Promise<void> {
|
|
508
|
+
const {PassphraseManager} = await import(
|
|
509
|
+
"fwtoolkit/e2ee/passphrase-manager"
|
|
510
|
+
)
|
|
511
|
+
const {changePassphraseDialog} = await import(
|
|
512
|
+
"fwtoolkit/e2ee/passphrase-dialog"
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
const changeResult: any = await new Promise(resolve => {
|
|
516
|
+
changePassphraseDialog(resolve)
|
|
517
|
+
})
|
|
518
|
+
if (!changeResult) {
|
|
519
|
+
return
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
await PassphraseManager.changePassphrase(
|
|
523
|
+
changeResult.oldPassphrase,
|
|
524
|
+
changeResult.newPassphrase,
|
|
525
|
+
changeResult.accountPassword
|
|
526
|
+
)
|
|
527
|
+
addAlert("success", gettext("Passphrase changed successfully."))
|
|
528
|
+
} catch (e: any) {
|
|
529
|
+
addAlert(
|
|
530
|
+
"error",
|
|
531
|
+
gettext("Failed to change passphrase: ") + e.message
|
|
532
|
+
)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
save(): Promise<void> {
|
|
537
|
+
activateWait()
|
|
538
|
+
const newLang = (
|
|
539
|
+
this.dom.querySelector("#language") as HTMLSelectElement
|
|
540
|
+
).value
|
|
541
|
+
const inlineReferences = (
|
|
542
|
+
this.dom.querySelector("#inline-references") as HTMLInputElement
|
|
543
|
+
).checked
|
|
544
|
+
const inlineMath = (
|
|
545
|
+
this.dom.querySelector("#inline-math") as HTMLInputElement
|
|
546
|
+
).checked
|
|
547
|
+
const grammarCheckContinuous = (
|
|
548
|
+
this.dom.querySelector(
|
|
549
|
+
"#grammar-check-continuous"
|
|
550
|
+
) as HTMLInputElement
|
|
551
|
+
).checked
|
|
552
|
+
let languageChange = false
|
|
553
|
+
return this.app.apiConnectors.userProfile
|
|
554
|
+
.save({
|
|
555
|
+
username: (
|
|
556
|
+
this.dom.querySelector("#username") as HTMLInputElement
|
|
557
|
+
).value,
|
|
558
|
+
first_name: (
|
|
559
|
+
this.dom.querySelector("#first_name") as HTMLInputElement
|
|
560
|
+
).value,
|
|
561
|
+
last_name: (
|
|
562
|
+
this.dom.querySelector("#last_name") as HTMLInputElement
|
|
563
|
+
).value,
|
|
564
|
+
language: newLang
|
|
565
|
+
})
|
|
566
|
+
.catch(() => addAlert("error", gettext("Could not save profile data")))
|
|
567
|
+
.then(() =>
|
|
568
|
+
this.app.apiConnectors.userProfile.updatePreferences({
|
|
569
|
+
inline_references: inlineReferences,
|
|
570
|
+
inline_math: inlineMath,
|
|
571
|
+
grammar_check_continuous: grammarCheckContinuous
|
|
572
|
+
})
|
|
573
|
+
)
|
|
574
|
+
.catch(() =>
|
|
575
|
+
addAlert("error", gettext("Could not save preferences"))
|
|
576
|
+
)
|
|
577
|
+
.then(() => {
|
|
578
|
+
deactivateWait()
|
|
579
|
+
return this.app.getConfiguration()
|
|
580
|
+
})
|
|
581
|
+
.then(() => {
|
|
582
|
+
const currentLang = document.documentElement.lang
|
|
583
|
+
languageChange = currentLang !== newLang
|
|
584
|
+
if (languageChange) {
|
|
585
|
+
window.location.reload()
|
|
586
|
+
return
|
|
587
|
+
}
|
|
588
|
+
// Keep the dialog open (mirrors the old stay-on-page
|
|
589
|
+
// behaviour); only the header chrome and dirty state update.
|
|
590
|
+
refreshUserChrome(this.app)
|
|
591
|
+
this.updateUserData()
|
|
592
|
+
this.resetDirty()
|
|
593
|
+
addAlert("info", gettext("Profile saved."))
|
|
594
|
+
})
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
updateUserData(): void {
|
|
598
|
+
const configUser = (this.app as any).user as
|
|
599
|
+
| (User & {id?: number})
|
|
600
|
+
| undefined
|
|
601
|
+
if (configUser) {
|
|
602
|
+
this.user = configUser
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
close(): void {
|
|
607
|
+
this.dialog?.close()
|
|
608
|
+
}
|
|
609
|
+
}
|