@fiduswriter/frontend 0.1.68 → 0.1.70
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/two_factor.css +0 -52
- package/css/user_template_manager.css +6 -0
- package/dist/css/bibliography/colors.css +0 -4
- package/dist/css/bibliography/forms.css +3 -61
- package/dist/css/document-template-editor/document_template_designer.css +68 -68
- package/dist/css/fwtoolkit/action_chooser_dialog.css +66 -0
- package/dist/css/fwtoolkit/action_toolbar.css +132 -0
- package/dist/css/fwtoolkit/alerts.css +53 -19
- package/dist/css/fwtoolkit/application_menu_controller.css +28 -0
- package/dist/css/fwtoolkit/attachment_field.css +19 -0
- package/dist/css/fwtoolkit/attachment_list.css +118 -0
- package/dist/css/fwtoolkit/avatar_label.css +80 -0
- package/dist/css/fwtoolkit/boolean_switch.css +128 -0
- package/dist/css/fwtoolkit/buttons.css +181 -85
- package/dist/css/fwtoolkit/category_filter_controller.css +11 -0
- package/dist/css/fwtoolkit/checkable_list.css +39 -6
- package/dist/css/fwtoolkit/colors.css +71 -69
- package/dist/css/fwtoolkit/common.css +49 -17
- package/dist/css/fwtoolkit/content_menu.css +49 -27
- package/dist/css/fwtoolkit/data_table.css +278 -41
- package/dist/css/fwtoolkit/datatable_bulk.css +106 -0
- package/dist/css/fwtoolkit/destination_settings_form.css +67 -0
- package/dist/css/fwtoolkit/dialog.css +100 -25
- package/dist/css/fwtoolkit/dialog_presets.css +157 -0
- package/dist/css/fwtoolkit/dialog_table.css +63 -26
- package/dist/css/fwtoolkit/directory_navigator.css +244 -0
- package/dist/css/fwtoolkit/drop_up.css +36 -24
- package/dist/css/fwtoolkit/faq_dialog.css +28 -4
- package/dist/css/fwtoolkit/file_input_field.css +150 -0
- package/dist/css/fwtoolkit/file_selector.css +265 -12
- package/dist/css/fwtoolkit/form_error_summary.css +53 -0
- package/dist/css/fwtoolkit/forms.css +261 -54
- package/dist/css/fwtoolkit/fwtoolkit.css +6618 -1522
- package/dist/css/fwtoolkit/grid_size_picker.css +119 -0
- package/dist/css/fwtoolkit/icon_button_group.css +110 -0
- package/dist/css/fwtoolkit/image_preview_field.css +156 -0
- package/dist/css/fwtoolkit/inline_status.css +69 -0
- package/dist/css/fwtoolkit/inline_tools.css +47 -16
- package/dist/css/fwtoolkit/input_list.css +33 -2
- package/dist/css/fwtoolkit/loader.css +12 -2
- package/dist/css/fwtoolkit/media_card_grid.css +251 -0
- package/dist/css/fwtoolkit/navigation_drawer.css +172 -0
- package/dist/css/fwtoolkit/one_time_code_field.css +135 -0
- package/dist/css/fwtoolkit/overflow_action_bar.css +28 -0
- package/dist/css/fwtoolkit/overview_menu.css +35 -27
- package/dist/css/fwtoolkit/permission_badge.css +121 -0
- package/dist/css/fwtoolkit/progress_task.css +51 -27
- package/dist/css/fwtoolkit/pulldown.css +50 -22
- package/dist/css/fwtoolkit/pulldown_menu.css +22 -11
- package/dist/css/fwtoolkit/remote_options_field.css +297 -0
- package/dist/css/fwtoolkit/reset.css +4 -3
- package/dist/css/fwtoolkit/resource_field.css +134 -0
- package/dist/css/fwtoolkit/sortable_list.css +160 -0
- package/dist/css/fwtoolkit/text.css +54 -15
- package/dist/css/fwtoolkit/token_input.css +189 -0
- package/dist/css/fwtoolkit/tokens.css +158 -0
- package/dist/css/fwtoolkit/tree_view.css +165 -0
- package/dist/css/fwtoolkit/two_pane_selector.css +150 -9
- package/dist/css/fwtoolkit/ui_tabs.css +41 -13
- package/dist/css/image-manager/dialog_usermedia.css +41 -41
- package/dist/css/manifest.json +29 -0
- package/dist/css/two_factor.css +0 -52
- package/dist/css/user_template_manager.css +6 -0
- package/dist/document_templates/editor.d.ts +3 -0
- package/dist/document_templates/editor.d.ts.map +1 -1
- package/dist/document_templates/editor.js +35 -18
- package/dist/document_templates/editor.js.map +1 -1
- package/dist/user/auth/two_factor.d.ts.map +1 -1
- package/dist/user/auth/two_factor.js +133 -157
- package/dist/user/auth/two_factor.js.map +1 -1
- package/package.json +9 -9
- package/src/document_templates/editor.ts +41 -21
- package/src/user/auth/two_factor.ts +203 -228
|
@@ -1,211 +1,150 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Dialog,
|
|
3
|
+
OneTimeCodeField,
|
|
3
4
|
activateWait,
|
|
4
5
|
addAlert,
|
|
5
6
|
deactivateWait,
|
|
6
|
-
|
|
7
|
+
escapeText
|
|
7
8
|
} from "fwtoolkit"
|
|
8
9
|
import QRCode from "qrcode"
|
|
9
10
|
import type {
|
|
10
11
|
TwoFactorSetupResponse,
|
|
11
|
-
TwoFactorStatusResponse
|
|
12
|
-
TwoFactorVerifyResponse
|
|
12
|
+
TwoFactorStatusResponse
|
|
13
13
|
} from "../../api/index.js"
|
|
14
14
|
import type {FrontendApp} from "../../types.js"
|
|
15
15
|
import type {LoginPage} from "./login.js"
|
|
16
16
|
|
|
17
|
+
const reportCodeError = (
|
|
18
|
+
field: OneTimeCodeField | undefined,
|
|
19
|
+
message: string
|
|
20
|
+
): void => {
|
|
21
|
+
addAlert("error", message)
|
|
22
|
+
field?.setError(message)
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
export const twoFactorSetupDialog = (app: FrontendApp): Promise<any> => {
|
|
18
26
|
let secretKey: string | null = null
|
|
19
27
|
let deviceId: string | null = null
|
|
20
28
|
|
|
21
29
|
activateWait()
|
|
22
|
-
return app.apiConnectors.auth
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const message = json.message || gettext("Two-factor setup failed.")
|
|
27
|
-
addAlert("error", message)
|
|
28
|
-
return Promise.reject(message)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
secretKey = json.secret_key
|
|
32
|
-
deviceId = json.device_id
|
|
33
|
-
const provisioningUri = json.provisioning_uri
|
|
30
|
+
return app.apiConnectors.auth
|
|
31
|
+
.twoFactorSetup()
|
|
32
|
+
.then((json: TwoFactorSetupResponse): any => {
|
|
33
|
+
deactivateWait()
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
width: 200,
|
|
42
|
-
margin: 2,
|
|
43
|
-
color: {
|
|
44
|
-
dark: "#000000",
|
|
45
|
-
light: "#ffffff"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
function (error: Error | null | undefined, canvas: HTMLCanvasElement) {
|
|
49
|
-
if (error) {
|
|
50
|
-
console.error("QR Code generation error:", error)
|
|
51
|
-
qrContainer.innerHTML = `<p style="color: red;">${gettext("Could not generate QR code. Please use the secret key below.")}</p>`
|
|
52
|
-
} else {
|
|
53
|
-
qrContainer.appendChild(canvas)
|
|
54
|
-
}
|
|
35
|
+
if (json.status !== "success") {
|
|
36
|
+
const message =
|
|
37
|
+
json.message || gettext("Two-factor setup failed.")
|
|
38
|
+
addAlert("error", message)
|
|
39
|
+
return Promise.reject(message)
|
|
55
40
|
}
|
|
56
|
-
)
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
classes: "fw-dark",
|
|
62
|
-
click: () => {
|
|
63
|
-
const codeInput = document.querySelector(
|
|
64
|
-
"#two-factor-code"
|
|
65
|
-
) as HTMLInputElement
|
|
66
|
-
const code = codeInput.value.trim()
|
|
42
|
+
secretKey = json.secret_key
|
|
43
|
+
deviceId = json.device_id
|
|
44
|
+
const provisioningUri = json.provisioning_uri
|
|
67
45
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
}
|
|
46
|
+
const qrContainer = document.createElement("div")
|
|
47
|
+
qrContainer.className = "two-factor-qr-container"
|
|
72
48
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
49
|
+
QRCode.toCanvas(
|
|
50
|
+
provisioningUri,
|
|
51
|
+
{
|
|
52
|
+
width: 200,
|
|
53
|
+
margin: 2,
|
|
54
|
+
color: {
|
|
55
|
+
dark: "#000000",
|
|
56
|
+
light: "#ffffff"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
function (
|
|
60
|
+
error: Error | null | undefined,
|
|
61
|
+
canvas: HTMLCanvasElement
|
|
62
|
+
) {
|
|
63
|
+
if (error) {
|
|
64
|
+
console.error("QR Code generation error:", error)
|
|
65
|
+
const message = document.createElement("p")
|
|
66
|
+
message.style.color = "red"
|
|
67
|
+
message.textContent = gettext(
|
|
68
|
+
"Could not generate QR code. Please use the secret key below."
|
|
69
|
+
)
|
|
70
|
+
qrContainer.replaceChildren(message)
|
|
71
|
+
} else {
|
|
72
|
+
qrContainer.replaceChildren(canvas)
|
|
73
|
+
}
|
|
89
74
|
}
|
|
90
|
-
|
|
91
|
-
{type: "cancel"}
|
|
92
|
-
]
|
|
75
|
+
)
|
|
93
76
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
let codeField: OneTimeCodeField | undefined
|
|
78
|
+
const dialog = new Dialog({
|
|
79
|
+
id: "two-factor-setup-dialog",
|
|
80
|
+
title: gettext("Set Up Two-Factor Authentication"),
|
|
81
|
+
body: `
|
|
98
82
|
<p>${gettext("Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.)")}</p>
|
|
99
83
|
<div class="two-factor-qr-wrapper"></div>
|
|
100
84
|
<p><strong>${gettext("Or enter this code manually:")}</strong></p>
|
|
101
|
-
<code class="two-factor-secret">${secretKey}</code>
|
|
85
|
+
<code class="two-factor-secret">${escapeText(secretKey)}</code>
|
|
102
86
|
<div class="two-factor-verify-section">
|
|
103
|
-
<
|
|
104
|
-
<input type="text" id="two-factor-code" placeholder="123456" maxlength="6" class="fw-button fw-large" autocomplete="one-time-code" />
|
|
87
|
+
<div id="two-factor-code-host"></div>
|
|
105
88
|
</div>
|
|
106
89
|
`,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
dialog.open()
|
|
113
|
-
|
|
114
|
-
const qrWrapper = dialog.dialogEl.querySelector(".two-factor-qr-wrapper")
|
|
115
|
-
if (qrWrapper && qrContainer) {
|
|
116
|
-
qrWrapper.appendChild(qrContainer)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const codeInput = dialog.dialogEl.querySelector("#two-factor-code")
|
|
120
|
-
if (codeInput) {
|
|
121
|
-
;(codeInput as HTMLElement).addEventListener("keypress", (event: Event) => {
|
|
122
|
-
if ((event as KeyboardEvent).key === "Enter") {
|
|
123
|
-
event.preventDefault()
|
|
124
|
-
buttons[0].click!()
|
|
125
|
-
}
|
|
90
|
+
buttons: [{type: "cancel"}],
|
|
91
|
+
onClose: () => codeField?.destroy(),
|
|
92
|
+
icon: "shield-alt",
|
|
93
|
+
width: 500
|
|
126
94
|
})
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
95
|
|
|
131
|
-
|
|
132
|
-
const buttons: DialogButtonSpec[] = [
|
|
133
|
-
{
|
|
134
|
-
text: gettext("Disable 2FA"),
|
|
135
|
-
classes: "fw-orange",
|
|
136
|
-
click: () => {
|
|
137
|
-
const passwordInput = document.getElementById(
|
|
138
|
-
"two-factor-disable-password"
|
|
139
|
-
) as HTMLInputElement | null
|
|
140
|
-
const codeInput = document.getElementById(
|
|
141
|
-
"two-factor-disable-code"
|
|
142
|
-
) as HTMLInputElement | null
|
|
143
|
-
const password = passwordInput ? passwordInput.value : ""
|
|
144
|
-
const code = codeInput ? codeInput.value.trim() : ""
|
|
145
|
-
|
|
146
|
-
if (password.length === 0) {
|
|
147
|
-
addAlert("error", gettext("Please enter your password."))
|
|
148
|
-
return
|
|
149
|
-
}
|
|
96
|
+
dialog.open()
|
|
150
97
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
98
|
+
const qrWrapper = dialog.dialogEl.querySelector(
|
|
99
|
+
".two-factor-qr-wrapper"
|
|
100
|
+
)
|
|
101
|
+
if (qrWrapper) {
|
|
102
|
+
qrWrapper.appendChild(qrContainer)
|
|
103
|
+
}
|
|
155
104
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
105
|
+
codeField = new OneTimeCodeField({
|
|
106
|
+
id: "two-factor-code",
|
|
107
|
+
label: gettext(
|
|
108
|
+
"Enter the 6-digit code from your authenticator app to verify:"
|
|
109
|
+
),
|
|
110
|
+
description: "",
|
|
111
|
+
length: 6,
|
|
112
|
+
onComplete: async code => {
|
|
113
|
+
try {
|
|
114
|
+
const response =
|
|
115
|
+
await app.apiConnectors.auth.twoFactorVerify({
|
|
116
|
+
code,
|
|
117
|
+
device_id: deviceId
|
|
118
|
+
})
|
|
119
|
+
if (response.status === "success") {
|
|
120
|
+
addAlert("success", response.message)
|
|
162
121
|
dialog.close()
|
|
163
122
|
window.location.reload()
|
|
164
123
|
} else {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// The server rejects missing/invalid re-authentication
|
|
170
|
-
// with a 4xx carrying a JSON message.
|
|
171
|
-
const response = errorResponse as Response | undefined
|
|
172
|
-
if (response && typeof response.json === "function") {
|
|
173
|
-
response
|
|
174
|
-
.json()
|
|
175
|
-
.then((json: {message?: string}) => {
|
|
176
|
-
addAlert(
|
|
177
|
-
"error",
|
|
178
|
-
json.message ||
|
|
179
|
-
gettext(
|
|
180
|
-
"Could not disable two-factor authentication."
|
|
181
|
-
)
|
|
182
|
-
)
|
|
183
|
-
})
|
|
184
|
-
.catch(() => {
|
|
185
|
-
addAlert(
|
|
186
|
-
"error",
|
|
187
|
-
gettext(
|
|
188
|
-
"Could not disable two-factor authentication."
|
|
189
|
-
)
|
|
190
|
-
)
|
|
191
|
-
})
|
|
192
|
-
} else {
|
|
193
|
-
addAlert(
|
|
194
|
-
"error",
|
|
195
|
-
gettext(
|
|
196
|
-
"Could not disable two-factor authentication."
|
|
197
|
-
)
|
|
124
|
+
reportCodeError(
|
|
125
|
+
codeField,
|
|
126
|
+
response.message ||
|
|
127
|
+
gettext("Could not verify the code.")
|
|
198
128
|
)
|
|
199
129
|
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
130
|
+
} catch {
|
|
131
|
+
reportCodeError(
|
|
132
|
+
codeField,
|
|
133
|
+
gettext("Could not verify the code.")
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
codeField.input.placeholder = "123456"
|
|
139
|
+
dialog.dialogEl
|
|
140
|
+
.querySelector("#two-factor-code-host")!
|
|
141
|
+
.appendChild(codeField.element)
|
|
142
|
+
codeField.input.focus()
|
|
143
|
+
})
|
|
144
|
+
}
|
|
208
145
|
|
|
146
|
+
export const twoFactorDisableDialog = (app: FrontendApp): any => {
|
|
147
|
+
let codeField: OneTimeCodeField | undefined
|
|
209
148
|
const dialog = new Dialog({
|
|
210
149
|
id: "two-factor-disable-dialog",
|
|
211
150
|
title: gettext("Disable Two-Factor Authentication"),
|
|
@@ -216,29 +155,75 @@ export const twoFactorDisableDialog = (app: FrontendApp): any => {
|
|
|
216
155
|
<input type="password" id="two-factor-disable-password" class="fw-button fw-large" autocomplete="current-password" data-1p-ignore data-lpignore="true" data-form-type="other" />
|
|
217
156
|
</div>
|
|
218
157
|
<div class="two-factor-verify-section">
|
|
219
|
-
<
|
|
220
|
-
<input type="text" id="two-factor-disable-code" placeholder="123456" maxlength="6" class="fw-button fw-large" autocomplete="one-time-code" />
|
|
158
|
+
<div id="two-factor-disable-code-host"></div>
|
|
221
159
|
</div>`,
|
|
222
|
-
buttons,
|
|
160
|
+
buttons: [{type: "cancel"}],
|
|
161
|
+
onClose: () => codeField?.destroy(),
|
|
223
162
|
icon: "exclamation-triangle"
|
|
224
163
|
})
|
|
225
164
|
|
|
226
165
|
dialog.open()
|
|
227
166
|
|
|
228
|
-
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
167
|
+
codeField = new OneTimeCodeField({
|
|
168
|
+
id: "two-factor-disable-code",
|
|
169
|
+
label: gettext("Authenticator code"),
|
|
170
|
+
description: "",
|
|
171
|
+
length: 6,
|
|
172
|
+
onComplete: async code => {
|
|
173
|
+
const password =
|
|
174
|
+
(
|
|
175
|
+
dialog.dialogEl.querySelector(
|
|
176
|
+
"#two-factor-disable-password"
|
|
177
|
+
) as HTMLInputElement | null
|
|
178
|
+
)?.value ?? ""
|
|
179
|
+
if (password.length === 0) {
|
|
180
|
+
addAlert("error", gettext("Please enter your password."))
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
activateWait()
|
|
185
|
+
try {
|
|
186
|
+
const response = await app.apiConnectors.auth.twoFactorDisable({
|
|
187
|
+
password,
|
|
188
|
+
code
|
|
189
|
+
})
|
|
190
|
+
if (response.status === "success") {
|
|
191
|
+
addAlert("success", response.message)
|
|
192
|
+
dialog.close()
|
|
193
|
+
window.location.reload()
|
|
194
|
+
} else {
|
|
195
|
+
reportCodeError(codeField, response.message)
|
|
196
|
+
}
|
|
197
|
+
} catch (errorResponse: unknown) {
|
|
198
|
+
let message = gettext(
|
|
199
|
+
"Could not disable two-factor authentication."
|
|
200
|
+
)
|
|
201
|
+
const response = errorResponse as Response | undefined
|
|
202
|
+
if (response && typeof response.json === "function") {
|
|
203
|
+
try {
|
|
204
|
+
const json = (await response.json()) as {
|
|
205
|
+
message?: string
|
|
206
|
+
}
|
|
207
|
+
message = json.message || message
|
|
208
|
+
} catch {
|
|
209
|
+
// Keep the generic message when the response is not JSON.
|
|
210
|
+
}
|
|
238
211
|
}
|
|
212
|
+
reportCodeError(codeField, message)
|
|
213
|
+
} finally {
|
|
214
|
+
deactivateWait()
|
|
239
215
|
}
|
|
240
|
-
|
|
241
|
-
}
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
codeField.input.placeholder = "123456"
|
|
219
|
+
dialog.dialogEl
|
|
220
|
+
.querySelector("#two-factor-disable-code-host")!
|
|
221
|
+
.appendChild(codeField.element)
|
|
222
|
+
;(
|
|
223
|
+
dialog.dialogEl.querySelector(
|
|
224
|
+
"#two-factor-disable-password"
|
|
225
|
+
) as HTMLInputElement
|
|
226
|
+
).focus()
|
|
242
227
|
|
|
243
228
|
return dialog
|
|
244
229
|
}
|
|
@@ -256,66 +241,56 @@ export const twoFactorLoginDialog = ({
|
|
|
256
241
|
loginPage: LoginPage
|
|
257
242
|
app: FrontendApp
|
|
258
243
|
}): any => {
|
|
259
|
-
|
|
260
|
-
{
|
|
261
|
-
text: gettext("Verify"),
|
|
262
|
-
classes: "fw-dark",
|
|
263
|
-
click: () => {
|
|
264
|
-
const twofactorInput = dialog.dialogEl.querySelector(
|
|
265
|
-
"#two-factor-code"
|
|
266
|
-
) as HTMLInputElement
|
|
267
|
-
const twofactor = twofactorInput ? twofactorInput.value.trim() : ""
|
|
268
|
-
|
|
269
|
-
if (twofactor.length !== 6) {
|
|
270
|
-
addAlert("error", gettext("Please enter a 6-digit code."))
|
|
271
|
-
return
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
activateWait()
|
|
275
|
-
app.apiConnectors.auth.twoFactorLogin({
|
|
276
|
-
login,
|
|
277
|
-
password,
|
|
278
|
-
remember,
|
|
279
|
-
twofactor
|
|
280
|
-
})
|
|
281
|
-
.then((json: TwoFactorVerifyResponse) => {
|
|
282
|
-
deactivateWait()
|
|
283
|
-
dialog.close()
|
|
284
|
-
loginPage.afterLogin(json)
|
|
285
|
-
})
|
|
286
|
-
.catch(() => {
|
|
287
|
-
addAlert("error", gettext("Could not verify the code."))
|
|
288
|
-
deactivateWait()
|
|
289
|
-
})
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
]
|
|
293
|
-
|
|
244
|
+
let codeField: OneTimeCodeField | undefined
|
|
294
245
|
const dialog = new Dialog({
|
|
295
246
|
id: "two-factor-login-dialog",
|
|
296
247
|
title: gettext("Two-Factor Authentication"),
|
|
297
248
|
body: `<p>${gettext("Enter the 6-digit code from your authenticator app:")}</p>
|
|
298
|
-
<
|
|
299
|
-
|
|
249
|
+
<div id="two-factor-code-host"></div>`,
|
|
250
|
+
onClose: () => codeField?.destroy(),
|
|
300
251
|
icon: "shield-alt",
|
|
301
252
|
width: 500
|
|
302
253
|
})
|
|
303
254
|
|
|
304
255
|
dialog.open()
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
256
|
+
|
|
257
|
+
codeField = new OneTimeCodeField({
|
|
258
|
+
id: "two-factor-code",
|
|
259
|
+
label: gettext("Enter the 6-digit code from your authenticator app:"),
|
|
260
|
+
description: "",
|
|
261
|
+
length: 6,
|
|
262
|
+
onComplete: async twofactor => {
|
|
263
|
+
activateWait()
|
|
264
|
+
try {
|
|
265
|
+
const response = await app.apiConnectors.auth.twoFactorLogin({
|
|
266
|
+
login,
|
|
267
|
+
password,
|
|
268
|
+
remember,
|
|
269
|
+
twofactor
|
|
270
|
+
})
|
|
271
|
+
dialog.close()
|
|
272
|
+
loginPage.afterLogin(response)
|
|
273
|
+
} catch {
|
|
274
|
+
reportCodeError(
|
|
275
|
+
codeField,
|
|
276
|
+
gettext("Could not verify the code.")
|
|
277
|
+
)
|
|
278
|
+
} finally {
|
|
279
|
+
deactivateWait()
|
|
311
280
|
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
codeField.input.placeholder = "123456"
|
|
284
|
+
dialog.dialogEl
|
|
285
|
+
.querySelector("#two-factor-code-host")!
|
|
286
|
+
.appendChild(codeField.element)
|
|
287
|
+
codeField.input.focus()
|
|
314
288
|
return dialog
|
|
315
289
|
}
|
|
316
290
|
|
|
317
291
|
export const checkTwoFactorStatus = (app: FrontendApp): Promise<boolean> => {
|
|
318
|
-
return app.apiConnectors.auth
|
|
292
|
+
return app.apiConnectors.auth
|
|
293
|
+
.twoFactorStatus()
|
|
319
294
|
.then((json: TwoFactorStatusResponse) => {
|
|
320
295
|
if (json.status === "success") {
|
|
321
296
|
return json.enabled
|