@fiduswriter/frontend 0.1.71 → 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/templates.d.ts.map +1 -1
- package/dist/common/templates.js +1 -0
- package/dist/common/templates.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/templates.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
package/src/user/auth/login.ts
CHANGED
|
@@ -1,9 +1,140 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
OneTimeCodeField,
|
|
3
|
+
activateWait,
|
|
4
|
+
addAlert,
|
|
5
|
+
deactivateWait,
|
|
6
|
+
ensureCSS,
|
|
7
|
+
escapeText,
|
|
8
|
+
langName,
|
|
9
|
+
setDocTitle,
|
|
10
|
+
staticUrl
|
|
11
|
+
} from "fwtoolkit"
|
|
12
|
+
import {FeedbackTab} from "../../feedback/index.js"
|
|
2
13
|
import {PreloginPage, type PreloginApp} from "../../prelogin/index.js"
|
|
3
14
|
import {socialProviderIcon} from "./social_icons.js"
|
|
4
15
|
|
|
16
|
+
interface LoginWindowOptions {
|
|
17
|
+
language: string
|
|
18
|
+
socialaccount_providers: Array<Record<string, unknown>>
|
|
19
|
+
settings: Record<string, any>
|
|
20
|
+
footerLinks: Array<{text: string; link: string; external?: boolean}>
|
|
21
|
+
showPasswordLogin: boolean
|
|
22
|
+
showSignup: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Design 5: the login page is a small centered window (card) instead of the
|
|
26
|
+
// full pre-login chrome. GDPR: the user has to enter the full username and
|
|
27
|
+
// password (no semi-logged-in account chooser) and the 2FA code when their
|
|
28
|
+
// account requires it.
|
|
29
|
+
const loginWindowTemplate = ({
|
|
30
|
+
language,
|
|
31
|
+
socialaccount_providers,
|
|
32
|
+
settings,
|
|
33
|
+
footerLinks,
|
|
34
|
+
showPasswordLogin,
|
|
35
|
+
showSignup
|
|
36
|
+
}: LoginWindowOptions): string => `
|
|
37
|
+
<div id="fw-wait">
|
|
38
|
+
<i class="fa fa-spinner fa-pulse"></i>
|
|
39
|
+
</div>
|
|
40
|
+
<div class="fw-login-page-inner">
|
|
41
|
+
<div class="fw-login-window">
|
|
42
|
+
<h1 class="fw-login-logo">
|
|
43
|
+
${
|
|
44
|
+
settings?.BRANDING_LOGO
|
|
45
|
+
? `<span class="fw-login-branding-logo"><img src="${staticUrl(settings.BRANDING_LOGO as string)}" alt="Logo" /></span>`
|
|
46
|
+
: `<span class="fw-logo-text"></span><img src="${staticUrl("svg/icon.svg")}" alt="Logo" />`
|
|
47
|
+
}
|
|
48
|
+
</h1>
|
|
49
|
+
<p class="fw-login-greeting">${gettext("Hey!")}</p>
|
|
50
|
+
<h1 class="fw-login-title">${gettext("Log in")}</h1>
|
|
51
|
+
<div class="fw-login-card-contents">
|
|
52
|
+
${
|
|
53
|
+
settings?.SOCIALACCOUNT_OPEN && socialaccount_providers.length
|
|
54
|
+
? `<div class="socialaccount_ballot fw-login-social">
|
|
55
|
+
<ul class="socialaccount_providers">
|
|
56
|
+
${socialaccount_providers
|
|
57
|
+
.map(
|
|
58
|
+
(provider: any) => `<li>
|
|
59
|
+
<a title="${escapeText(provider.name)}" class="fw-button fw-socialaccount fw-${escapeText(provider.id)}"
|
|
60
|
+
href="${escapeText(provider.login_url)}">
|
|
61
|
+
<span class="fab fa-${socialProviderIcon(provider.id)}"></span>
|
|
62
|
+
${gettext("Login with")} ${escapeText(provider.name)}
|
|
63
|
+
</a>
|
|
64
|
+
</li>`
|
|
65
|
+
)
|
|
66
|
+
.join("")}
|
|
67
|
+
</ul>
|
|
68
|
+
</div>`
|
|
69
|
+
: ""
|
|
70
|
+
}
|
|
71
|
+
${
|
|
72
|
+
showPasswordLogin
|
|
73
|
+
? `<form novalidate>
|
|
74
|
+
<ul id="non-field-errors" class="fw-errorlist"></ul>
|
|
75
|
+
<div class="fw-login-fields">
|
|
76
|
+
<div class="fw-floating-field">
|
|
77
|
+
<label for="id-login">${gettext("Username")}</label>
|
|
78
|
+
<input type="text" name="login" placeholder=" " required="" id="id-login" autocomplete="username" autofocus="autofocus">
|
|
79
|
+
<ul id="id-login-errors" class="fw-errorlist"></ul>
|
|
80
|
+
</div>
|
|
81
|
+
<div class="fw-floating-field">
|
|
82
|
+
<label for="id-password">${gettext("Password")}</label>
|
|
83
|
+
<input type="password" name="password" placeholder=" " required="" id="id-password" autocomplete="current-password">
|
|
84
|
+
<ul id="id-password-errors" class="fw-errorlist"></ul>
|
|
85
|
+
</div>
|
|
86
|
+
<div class="fw-login-password-extras">
|
|
87
|
+
<label for="id-show-password">
|
|
88
|
+
<input type="checkbox" id="id-show-password" name="show-password">
|
|
89
|
+
${gettext("Show password")}
|
|
90
|
+
</label>
|
|
91
|
+
<label for="id-remember">
|
|
92
|
+
<input type="checkbox" id="id-remember" name="remember">
|
|
93
|
+
${gettext("Remember me")}
|
|
94
|
+
</label>
|
|
95
|
+
</div>
|
|
96
|
+
<div class="fw-login-2fa-host" id="fw-login-2fa-host" hidden></div>
|
|
97
|
+
</div>
|
|
98
|
+
<div class="fw-login-submit-row">
|
|
99
|
+
<button class="fw-button fw-green fw-dialog-button-primary" type="submit" id="login-submit">${gettext("Continue")}</button>
|
|
100
|
+
</div>
|
|
101
|
+
<div class="fw-login-secondary-links">
|
|
102
|
+
<a id="lost-passwd" href="/account/password-reset/">${gettext("Forgot Password?")}</a>
|
|
103
|
+
${
|
|
104
|
+
showSignup
|
|
105
|
+
? `<a id="fw-login-signup" href="/account/sign-up/">${gettext("New here? Sign up")}</a>`
|
|
106
|
+
: ""
|
|
107
|
+
}
|
|
108
|
+
</div>
|
|
109
|
+
</form>`
|
|
110
|
+
: ""
|
|
111
|
+
}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
<div class="fw-login-footer">
|
|
115
|
+
<select id="lang-selection" aria-label="${gettext("Select language")}">
|
|
116
|
+
${((settings?.LANGUAGES as Array<[string, string]>) || [])
|
|
117
|
+
.map(
|
|
118
|
+
([code, _name]) =>
|
|
119
|
+
`<option value="${code}" ${language === code ? "selected" : ""}>${langName(code)}</option>`
|
|
120
|
+
)
|
|
121
|
+
.join("")}
|
|
122
|
+
</select>
|
|
123
|
+
<ul class="fw-footer-links">
|
|
124
|
+
${footerLinks
|
|
125
|
+
.map(
|
|
126
|
+
fLink =>
|
|
127
|
+
`<li><a href="${fLink.link}" target="_blank"${fLink.external ? ' rel="noreferrer"' : ""}>${fLink.text}</a></li>`
|
|
128
|
+
)
|
|
129
|
+
.join("")}
|
|
130
|
+
</ul>
|
|
131
|
+
</div>
|
|
132
|
+
</div>`
|
|
133
|
+
|
|
5
134
|
export class LoginPage extends PreloginPage {
|
|
6
135
|
socialaccount_providers: Array<Record<string, unknown>>
|
|
136
|
+
twoFactorField: OneTimeCodeField | undefined
|
|
137
|
+
pendingCredentials: {login: string; password: string; remember: boolean} | null
|
|
7
138
|
|
|
8
139
|
constructor({
|
|
9
140
|
app,
|
|
@@ -18,183 +149,230 @@ export class LoginPage extends PreloginPage {
|
|
|
18
149
|
this.socialaccount_providers = socialaccount_providers
|
|
19
150
|
this.title = gettext("Login")
|
|
20
151
|
this.pluginLoaders = []
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
? [
|
|
25
|
-
{type: "label", text: gettext("New here?"), link: ""},
|
|
26
|
-
{
|
|
27
|
-
type: "button",
|
|
28
|
-
text: gettext("Sign up"),
|
|
29
|
-
link: "/account/sign-up/"
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
: []) as any
|
|
152
|
+
this.twoFactorField = undefined
|
|
153
|
+
this.pendingCredentials = null
|
|
154
|
+
this.headerLinks = []
|
|
33
155
|
}
|
|
34
156
|
|
|
35
157
|
render(): void {
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
: ""
|
|
58
|
-
}
|
|
59
|
-
</div>
|
|
60
|
-
${
|
|
61
|
-
this.app.settings?.PASSWORD_LOGIN
|
|
62
|
-
? `<div class="fw-login-right">
|
|
63
|
-
<form>
|
|
64
|
-
<ul id="non-field-errors" class="fw-errorlist"></ul>
|
|
65
|
-
<div class="input-wrapper">
|
|
66
|
-
<label for="id-login">${gettext("Username")}</label>
|
|
67
|
-
<input type="text" name="login" placeholder="${gettext("Username or e-mail")}" autofocus="autofocus" required="" id="id-login" autocomplete="username">
|
|
68
|
-
<ul id="id-login-errors" class="fw-errorlist"></ul>
|
|
69
|
-
</div>
|
|
70
|
-
<div class="input-wrapper">
|
|
71
|
-
<label for="id-password">${gettext("Password")}</label>
|
|
72
|
-
<input type="password" name="password" placeholder="${gettext("Password")}" required="" id="id-password" autocomplete="current-password">
|
|
73
|
-
<ul id="id-password-errors" class="fw-errorlist"></ul>
|
|
74
|
-
</div>
|
|
75
|
-
<div class="submit-wrapper">
|
|
76
|
-
<button class="fw-button fw-dark fw-uppercase" type="submit" id="login-submit">${gettext("Log in")}</button>
|
|
77
|
-
<br>
|
|
78
|
-
<input type="checkbox" name="remember" id="id-remember">
|
|
79
|
-
<label for="id-remember">${gettext("Remember me")}</label>
|
|
80
|
-
</div>
|
|
81
|
-
<a id="lost-passwd" href="/account/password-reset/">${gettext("Forgot Password?")}</a>
|
|
82
|
-
</form>
|
|
83
|
-
</div>`
|
|
84
|
-
: ""
|
|
85
|
-
}`
|
|
86
|
-
super.render()
|
|
158
|
+
this.dom = document.createElement("body")
|
|
159
|
+
this.dom.classList.add("fw-login-page")
|
|
160
|
+
this.dom.classList.add("fw-scrollable")
|
|
161
|
+
this.dom.innerHTML = loginWindowTemplate({
|
|
162
|
+
language: this.language,
|
|
163
|
+
socialaccount_providers: this.socialaccount_providers,
|
|
164
|
+
settings: (this.app.settings || {}) as Record<string, any>,
|
|
165
|
+
footerLinks: this.footerLinks,
|
|
166
|
+
showPasswordLogin: Boolean(this.app.settings?.PASSWORD_LOGIN),
|
|
167
|
+
showSignup: Boolean(
|
|
168
|
+
this.app.settings?.REGISTRATION_OPEN &&
|
|
169
|
+
this.app.settings?.PASSWORD_LOGIN
|
|
170
|
+
)
|
|
171
|
+
})
|
|
172
|
+
document.body = this.dom
|
|
173
|
+
ensureCSS([
|
|
174
|
+
staticUrl("css/login.css"),
|
|
175
|
+
staticUrl("css/two_factor.css")
|
|
176
|
+
])
|
|
177
|
+
setDocTitle(this.title, this.app as {name: string})
|
|
178
|
+
new FeedbackTab(this.app).init()
|
|
87
179
|
}
|
|
88
180
|
|
|
89
181
|
bind(): void {
|
|
90
182
|
super.bind()
|
|
91
|
-
const socialButtons = document.body.querySelectorAll(".fw-button.fw-socialaccount")
|
|
92
|
-
let btnWidth = 1
|
|
93
183
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
184
|
+
const showPassword = document.querySelector(
|
|
185
|
+
"#id-show-password"
|
|
186
|
+
) as HTMLInputElement | null
|
|
187
|
+
const passwordInput = document.querySelector(
|
|
188
|
+
"#id-password"
|
|
189
|
+
) as HTMLInputElement | null
|
|
190
|
+
if (showPassword && passwordInput) {
|
|
191
|
+
showPassword.addEventListener("change", () => {
|
|
192
|
+
passwordInput.type = showPassword.checked
|
|
193
|
+
? "text"
|
|
194
|
+
: "password"
|
|
195
|
+
})
|
|
196
|
+
}
|
|
102
197
|
|
|
103
|
-
const loginSubmit = document.querySelector(
|
|
198
|
+
const loginSubmit = document.querySelector(
|
|
199
|
+
"#login-submit"
|
|
200
|
+
) as HTMLButtonElement | null
|
|
104
201
|
if (!loginSubmit) {
|
|
105
202
|
return
|
|
106
203
|
}
|
|
107
204
|
|
|
108
|
-
loginSubmit.
|
|
109
|
-
|
|
205
|
+
const form = loginSubmit.closest("form")
|
|
206
|
+
if (form) {
|
|
207
|
+
form.addEventListener("submit", (event: Event) => {
|
|
208
|
+
event.preventDefault()
|
|
209
|
+
this.submitLogin()
|
|
210
|
+
})
|
|
211
|
+
} else {
|
|
212
|
+
// No surrounding <form>: submit directly from the button click.
|
|
213
|
+
loginSubmit.addEventListener("click", (event: Event) => {
|
|
214
|
+
event.preventDefault()
|
|
215
|
+
this.submitLogin()
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
}
|
|
110
219
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
220
|
+
submitLogin(): void {
|
|
221
|
+
const nonFieldErrors = document.querySelector("#non-field-errors")
|
|
222
|
+
const idLogin = document.querySelector("#id-login") as HTMLInputElement
|
|
223
|
+
const idLoginErrors = document.querySelector("#id-login-errors")
|
|
224
|
+
const idPassword = document.querySelector(
|
|
225
|
+
"#id-password"
|
|
226
|
+
) as HTMLInputElement
|
|
227
|
+
const idPasswordErrors = document.querySelector("#id-password-errors")
|
|
228
|
+
const idRemember = document.querySelector(
|
|
229
|
+
"#id-remember"
|
|
230
|
+
) as HTMLInputElement
|
|
118
231
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
232
|
+
if (
|
|
233
|
+
!idLogin ||
|
|
234
|
+
!idLoginErrors ||
|
|
235
|
+
!idPassword ||
|
|
236
|
+
!idPasswordErrors ||
|
|
237
|
+
!idRemember
|
|
238
|
+
) {
|
|
239
|
+
return
|
|
240
|
+
}
|
|
122
241
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const login = idLogin.value
|
|
128
|
-
const password = idPassword.value
|
|
129
|
-
const remember = idRemember.checked
|
|
130
|
-
let errors = false
|
|
131
|
-
if (!login.length) {
|
|
132
|
-
idLoginErrors.innerHTML = `<li>${gettext("This field is required.")}</li>`
|
|
133
|
-
errors = true
|
|
134
|
-
}
|
|
135
|
-
if (!password.length) {
|
|
136
|
-
idPasswordErrors.innerHTML = `<li>${gettext("This field is required.")}</li>`
|
|
137
|
-
errors = true
|
|
138
|
-
}
|
|
139
|
-
if (errors) {
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
return this.app.apiConnectors.auth.login({login, password, remember})
|
|
143
|
-
.catch((response: any) => {
|
|
144
|
-
if (!(response instanceof Response) || response.status !== 400) {
|
|
145
|
-
return Promise.reject(response)
|
|
146
|
-
}
|
|
147
|
-
return response.json().then((json: any) => {
|
|
148
|
-
const needCode =
|
|
149
|
-
json.form.fields.twofactor.errors.includes("required")
|
|
150
|
-
if (
|
|
151
|
-
needCode &&
|
|
152
|
-
!json.form.errors.length &&
|
|
153
|
-
!json.form.fields.login.errors.length &&
|
|
154
|
-
!json.form.fields.password.errors.length
|
|
155
|
-
) {
|
|
156
|
-
import("./two_factor.js").then(({twoFactorLoginDialog}) => {
|
|
157
|
-
twoFactorLoginDialog({
|
|
158
|
-
login,
|
|
159
|
-
password,
|
|
160
|
-
remember,
|
|
161
|
-
loginPage: this,
|
|
162
|
-
app: this.app
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
} else {
|
|
166
|
-
json.form.errors.forEach(
|
|
167
|
-
(error: string) =>
|
|
168
|
-
(nonFieldErrors!.innerHTML += `<li>${escapeText(error)}</li>`)
|
|
169
|
-
)
|
|
170
|
-
json.form.fields.login.errors.forEach(
|
|
171
|
-
(error: string) =>
|
|
172
|
-
(idLoginErrors.innerHTML += `<li>${escapeText(error)}</li>`)
|
|
173
|
-
)
|
|
174
|
-
json.form.fields.password.errors.forEach(
|
|
175
|
-
(error: string) =>
|
|
176
|
-
(idPasswordErrors.innerHTML += `<li>${escapeText(error)}</li>`)
|
|
177
|
-
)
|
|
178
|
-
}
|
|
242
|
+
nonFieldErrors!.innerHTML = ""
|
|
243
|
+
idLoginErrors.innerHTML = ""
|
|
244
|
+
idPasswordErrors.innerHTML = ""
|
|
179
245
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
246
|
+
const login = idLogin.value
|
|
247
|
+
const password = idPassword.value
|
|
248
|
+
const remember = idRemember.checked
|
|
249
|
+
let errors = false
|
|
250
|
+
if (!login.length) {
|
|
251
|
+
idLoginErrors.innerHTML = `<li>${gettext("This field is required.")}</li>`
|
|
252
|
+
errors = true
|
|
253
|
+
}
|
|
254
|
+
if (!password.length) {
|
|
255
|
+
idPasswordErrors.innerHTML = `<li>${gettext("This field is required.")}</li>`
|
|
256
|
+
errors = true
|
|
257
|
+
}
|
|
258
|
+
if (errors) {
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
activateWait()
|
|
263
|
+
this.app.apiConnectors.auth
|
|
264
|
+
.login({login, password, remember})
|
|
265
|
+
.catch((response: any) => {
|
|
266
|
+
if (!(response instanceof Response) || response.status !== 400) {
|
|
267
|
+
return Promise.reject(response)
|
|
268
|
+
}
|
|
269
|
+
return response.json().then((json: any) => {
|
|
270
|
+
const needCode =
|
|
271
|
+
json.form.fields.twofactor.errors.includes("required")
|
|
272
|
+
if (
|
|
273
|
+
needCode &&
|
|
274
|
+
!json.form.errors.length &&
|
|
275
|
+
!json.form.fields.login.errors.length &&
|
|
276
|
+
!json.form.fields.password.errors.length
|
|
277
|
+
) {
|
|
278
|
+
this.revealTwoFactorField({login, password, remember})
|
|
279
|
+
} else {
|
|
280
|
+
json.form.errors.forEach(
|
|
281
|
+
(error: string) =>
|
|
282
|
+
(nonFieldErrors!.innerHTML += `<li>${escapeText(error)}</li>`)
|
|
283
|
+
)
|
|
284
|
+
json.form.fields.login.errors.forEach(
|
|
285
|
+
(error: string) =>
|
|
286
|
+
(idLoginErrors.innerHTML += `<li>${escapeText(error)}</li>`)
|
|
287
|
+
)
|
|
288
|
+
json.form.fields.password.errors.forEach(
|
|
289
|
+
(error: string) =>
|
|
290
|
+
(idPasswordErrors.innerHTML += `<li>${escapeText(error)}</li>`)
|
|
291
|
+
)
|
|
188
292
|
}
|
|
189
|
-
|
|
293
|
+
|
|
294
|
+
return {json, status: response.status}
|
|
190
295
|
})
|
|
296
|
+
})
|
|
297
|
+
.then((result: any) => {
|
|
298
|
+
if (!result) {
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
const {json, status, requiresEmailConfirmation} = result
|
|
302
|
+
if (status === 400) {
|
|
303
|
+
return
|
|
304
|
+
}
|
|
305
|
+
this.afterLogin(json, requiresEmailConfirmation)
|
|
306
|
+
})
|
|
307
|
+
.catch(() => {
|
|
308
|
+
addNonFieldError(gettext("Could not log in."))
|
|
309
|
+
})
|
|
310
|
+
.then(() => deactivateWait())
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
revealTwoFactorField({
|
|
314
|
+
login,
|
|
315
|
+
password,
|
|
316
|
+
remember
|
|
317
|
+
}: {
|
|
318
|
+
login: string
|
|
319
|
+
password: string
|
|
320
|
+
remember: boolean
|
|
321
|
+
}): void {
|
|
322
|
+
if (this.twoFactorField) {
|
|
323
|
+
this.twoFactorField.input.focus()
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
const host = document.querySelector("#fw-login-2fa-host") as HTMLElement
|
|
327
|
+
if (!host) {
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
this.pendingCredentials = {login, password, remember}
|
|
331
|
+
host.hidden = false
|
|
332
|
+
this.twoFactorField = new OneTimeCodeField({
|
|
333
|
+
id: "two-factor-code",
|
|
334
|
+
label: gettext("Enter the 6-digit code from your authenticator app:"),
|
|
335
|
+
description: "",
|
|
336
|
+
length: 6,
|
|
337
|
+
onComplete: async twofactor => {
|
|
338
|
+
await this.submitTwoFactorCode(twofactor)
|
|
339
|
+
}
|
|
191
340
|
})
|
|
341
|
+
this.twoFactorField.input.placeholder = "123456"
|
|
342
|
+
host.replaceChildren(this.twoFactorField.element)
|
|
343
|
+
this.twoFactorField.input.focus()
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async submitTwoFactorCode(twofactor: string): Promise<void> {
|
|
347
|
+
if (!this.pendingCredentials) {
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
const {login, password, remember} = this.pendingCredentials
|
|
351
|
+
activateWait()
|
|
352
|
+
try {
|
|
353
|
+
const response =
|
|
354
|
+
await this.app.apiConnectors.auth.twoFactorLogin({
|
|
355
|
+
login,
|
|
356
|
+
password,
|
|
357
|
+
remember,
|
|
358
|
+
twofactor
|
|
359
|
+
})
|
|
360
|
+
this.pendingCredentials = null
|
|
361
|
+
this.afterLogin(response)
|
|
362
|
+
} catch {
|
|
363
|
+
this.twoFactorField?.setError(gettext("Could not verify the code."))
|
|
364
|
+
addAlert("error", gettext("Could not verify the code."))
|
|
365
|
+
} finally {
|
|
366
|
+
deactivateWait()
|
|
367
|
+
}
|
|
192
368
|
}
|
|
193
369
|
|
|
194
370
|
afterLogin(json: any, requiresEmailConfirmation?: boolean): void {
|
|
195
371
|
const currentLang = document.documentElement.lang
|
|
196
372
|
if (requiresEmailConfirmation) {
|
|
197
|
-
const contentsEl = document.querySelector(
|
|
373
|
+
const contentsEl = document.querySelector(
|
|
374
|
+
".fw-login-card-contents"
|
|
375
|
+
)
|
|
198
376
|
if (contentsEl) {
|
|
199
377
|
contentsEl.innerHTML = `<div class="fw-login-left">
|
|
200
378
|
<h1 class="fw-login-title">${gettext("Verify Your E-mail Address")}</h1>
|
|
@@ -222,3 +400,10 @@ export class LoginPage extends PreloginPage {
|
|
|
222
400
|
}
|
|
223
401
|
}
|
|
224
402
|
}
|
|
403
|
+
|
|
404
|
+
const addNonFieldError = (message: string): void => {
|
|
405
|
+
const nonFieldErrors = document.querySelector("#non-field-errors")
|
|
406
|
+
if (nonFieldErrors) {
|
|
407
|
+
nonFieldErrors.innerHTML += `<li>${escapeText(message)}</li>`
|
|
408
|
+
}
|
|
409
|
+
}
|