@nymphjs/tilmeld-components 1.0.0-beta.14 → 1.0.0-beta.141
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/CHANGELOG.md +536 -0
- package/README.md +6 -4
- package/dist/Account.svelte +518 -0
- package/dist/ChangePassword.svelte +311 -0
- package/dist/Login.svelte +614 -0
- package/dist/Recover.svelte +479 -0
- package/dist/RevokeTokens.svelte +238 -0
- package/dist/TwoFactor.svelte +558 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/{lib → dist}/index.js.map +1 -1
- package/jest.config.js +32 -0
- package/package.json +54 -43
- package/src/Account.svelte +359 -190
- package/src/ChangePassword.svelte +190 -92
- package/src/Login.svelte +344 -120
- package/src/Recover.svelte +301 -183
- package/src/RevokeTokens.svelte +238 -0
- package/src/TwoFactor.svelte +558 -0
- package/src/index.d.ts +3 -1
- package/src/index.ts +3 -1
- package/tsconfig.json +8 -4
- package/typedoc.json +4 -0
- package/dist/index.cjs +0 -3
- package/dist/index.cjs.LICENSE.txt +0 -45
- package/dist/index.cjs.map +0 -1
- package/jest.config.cjs +0 -6
- package/lib/Account.svelte +0 -333
- package/lib/Account.svelte.map +0 -1
- package/lib/ChangePassword.svelte +0 -188
- package/lib/ChangePassword.svelte.map +0 -1
- package/lib/Login.svelte +0 -353
- package/lib/Login.svelte.map +0 -1
- package/lib/Recover.svelte +0 -339
- package/lib/Recover.svelte.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -6
- package/webpack.config.cjs +0 -35
package/src/Login.svelte
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
<svelte:options runes />
|
|
2
|
+
|
|
1
3
|
<div
|
|
2
4
|
style="width: {width}; {style}"
|
|
3
5
|
use:useActions={use}
|
|
4
|
-
|
|
5
|
-
{...exclude($$restProps, [
|
|
6
|
+
{...exclude(restProps, [
|
|
6
7
|
'successRegisteredMessage$',
|
|
7
8
|
'successLoginMessage$',
|
|
8
9
|
'username$',
|
|
@@ -11,6 +12,8 @@
|
|
|
11
12
|
'name$',
|
|
12
13
|
'email$',
|
|
13
14
|
'phone$',
|
|
15
|
+
'code$',
|
|
16
|
+
'codeMessage$',
|
|
14
17
|
'loginButton$',
|
|
15
18
|
'registerButton$',
|
|
16
19
|
'registerLink$',
|
|
@@ -20,46 +23,92 @@
|
|
|
20
23
|
'progress$',
|
|
21
24
|
])}
|
|
22
25
|
>
|
|
23
|
-
{#if clientConfig == null ||
|
|
26
|
+
{#if $clientConfig == null || loading}
|
|
24
27
|
<div style="display: flex; justify-content: center; align-items: center;">
|
|
25
28
|
<CircularProgress
|
|
26
29
|
style="height: 32px; width: 32px;"
|
|
27
30
|
indeterminate
|
|
28
|
-
{...prefixFilter(
|
|
31
|
+
{...prefixFilter(restProps, 'progress$')}
|
|
29
32
|
/>
|
|
30
33
|
</div>
|
|
31
34
|
{:else if successRegisteredMessage}
|
|
32
|
-
<div {...prefixFilter(
|
|
35
|
+
<div {...prefixFilter(restProps, 'successRegisteredMessage$')}>
|
|
33
36
|
{successRegisteredMessage}
|
|
34
37
|
</div>
|
|
35
38
|
{:else if successLoginMessage}
|
|
36
|
-
<div {...prefixFilter(
|
|
39
|
+
<div {...prefixFilter(restProps, 'successLoginMessage$')}>
|
|
37
40
|
{successLoginMessage}
|
|
38
41
|
</div>
|
|
42
|
+
{:else if totp}
|
|
43
|
+
<form onsubmit={preventDefault(stopPropagation(login))}>
|
|
44
|
+
<div {...prefixFilter(restProps, 'codeMessage$')}>
|
|
45
|
+
Enter the 6-digit 2FA code from your authenticator app.
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div>
|
|
49
|
+
<Textfield
|
|
50
|
+
bind:value={code}
|
|
51
|
+
label="2FA Code"
|
|
52
|
+
style="width: 100%;"
|
|
53
|
+
input$autocomplete="one-time-code"
|
|
54
|
+
input$name="one-time-code"
|
|
55
|
+
{...prefixFilter(restProps, 'code$')}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
{#if failureMessage}
|
|
60
|
+
<div class="tilmeld-login-failure">
|
|
61
|
+
{failureMessage}
|
|
62
|
+
</div>
|
|
63
|
+
{/if}
|
|
64
|
+
|
|
65
|
+
<div class="tilmeld-login-buttons">
|
|
66
|
+
<Button
|
|
67
|
+
variant="raised"
|
|
68
|
+
type="submit"
|
|
69
|
+
onclick={login}
|
|
70
|
+
{...prefixFilter(restProps, 'loginButton$')}
|
|
71
|
+
>
|
|
72
|
+
<Label>Log In</Label>
|
|
73
|
+
</Button>
|
|
74
|
+
</div>
|
|
75
|
+
</form>
|
|
39
76
|
{:else}
|
|
40
|
-
<form
|
|
77
|
+
<form
|
|
78
|
+
onsubmit={preventDefault(
|
|
79
|
+
stopPropagation(() => {
|
|
80
|
+
if (mode === 'login') {
|
|
81
|
+
login();
|
|
82
|
+
} else {
|
|
83
|
+
register();
|
|
84
|
+
}
|
|
85
|
+
}),
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
41
88
|
<div>
|
|
42
89
|
<Textfield
|
|
43
90
|
bind:value={username}
|
|
44
91
|
bind:this={usernameElem}
|
|
45
|
-
label={clientConfig.emailUsernames ? 'Email' : 'Username'}
|
|
46
|
-
type={clientConfig.emailUsernames ? 'email' : 'text'}
|
|
92
|
+
label={$clientConfig.emailUsernames ? 'Email' : 'Username'}
|
|
93
|
+
type={$clientConfig.emailUsernames ? 'email' : 'text'}
|
|
47
94
|
style="width: 100%;"
|
|
48
95
|
helperLine$style="width: 100%;"
|
|
49
96
|
invalid={usernameVerified === false}
|
|
50
|
-
input$autocomplete={clientConfig.emailUsernames
|
|
97
|
+
input$autocomplete={$clientConfig.emailUsernames
|
|
51
98
|
? 'email'
|
|
52
99
|
: 'username'}
|
|
53
|
-
input$name={clientConfig.emailUsernames ? 'email' : 'username'}
|
|
100
|
+
input$name={$clientConfig.emailUsernames ? 'email' : 'username'}
|
|
54
101
|
input$autocapitalize="off"
|
|
55
102
|
input$spellcheck="false"
|
|
56
|
-
{...prefixFilter(
|
|
103
|
+
{...prefixFilter(restProps, 'username$')}
|
|
57
104
|
>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
105
|
+
{#snippet helper()}
|
|
106
|
+
<HelperText persistent>
|
|
107
|
+
{#if mode !== 'login'}
|
|
108
|
+
{usernameVerifiedMessage || ''}
|
|
109
|
+
{/if}
|
|
110
|
+
</HelperText>
|
|
111
|
+
{/snippet}
|
|
63
112
|
</Textfield>
|
|
64
113
|
</div>
|
|
65
114
|
|
|
@@ -69,16 +118,16 @@
|
|
|
69
118
|
label="Password"
|
|
70
119
|
type="password"
|
|
71
120
|
style="width: 100%;"
|
|
72
|
-
input$autocomplete="{clientConfig.allowRegistration &&
|
|
121
|
+
input$autocomplete="{$clientConfig.allowRegistration &&
|
|
73
122
|
mode !== 'login'
|
|
74
123
|
? 'new'
|
|
75
124
|
: 'current'}-password"
|
|
76
125
|
input$name="password"
|
|
77
|
-
{...prefixFilter(
|
|
126
|
+
{...prefixFilter(restProps, 'password$')}
|
|
78
127
|
/>
|
|
79
128
|
</div>
|
|
80
129
|
|
|
81
|
-
{#if clientConfig.allowRegistration && mode !== 'login'}
|
|
130
|
+
{#if $clientConfig.allowRegistration && mode !== 'login'}
|
|
82
131
|
<div>
|
|
83
132
|
<Textfield
|
|
84
133
|
bind:value={password2}
|
|
@@ -87,11 +136,11 @@
|
|
|
87
136
|
style="width: 100%;"
|
|
88
137
|
input$autocomplete="new-password"
|
|
89
138
|
input$name="password2"
|
|
90
|
-
{...prefixFilter(
|
|
139
|
+
{...prefixFilter(restProps, 'password2$')}
|
|
91
140
|
/>
|
|
92
141
|
</div>
|
|
93
142
|
|
|
94
|
-
{#if clientConfig.regFields.
|
|
143
|
+
{#if $clientConfig.regFields.includes('name')}
|
|
95
144
|
<div>
|
|
96
145
|
<Textfield
|
|
97
146
|
bind:value={name}
|
|
@@ -100,12 +149,12 @@
|
|
|
100
149
|
style="width: 100%;"
|
|
101
150
|
input$autocomplete="name"
|
|
102
151
|
input$name="name"
|
|
103
|
-
{...prefixFilter(
|
|
152
|
+
{...prefixFilter(restProps, 'name$')}
|
|
104
153
|
/>
|
|
105
154
|
</div>
|
|
106
155
|
{/if}
|
|
107
156
|
|
|
108
|
-
{#if
|
|
157
|
+
{#if !$clientConfig.emailUsernames && $clientConfig.regFields.includes('email')}
|
|
109
158
|
<div>
|
|
110
159
|
<Textfield
|
|
111
160
|
bind:value={email}
|
|
@@ -116,12 +165,12 @@
|
|
|
116
165
|
input$name="email"
|
|
117
166
|
input$autocapitalize="off"
|
|
118
167
|
input$spellcheck="false"
|
|
119
|
-
{...prefixFilter(
|
|
168
|
+
{...prefixFilter(restProps, 'email$')}
|
|
120
169
|
/>
|
|
121
170
|
</div>
|
|
122
171
|
{/if}
|
|
123
172
|
|
|
124
|
-
{#if clientConfig.regFields.
|
|
173
|
+
{#if $clientConfig.regFields.includes('phone')}
|
|
125
174
|
<div>
|
|
126
175
|
<Textfield
|
|
127
176
|
bind:value={phone}
|
|
@@ -130,13 +179,13 @@
|
|
|
130
179
|
style="width: 100%;"
|
|
131
180
|
input$autocomplete="tel"
|
|
132
181
|
input$name="phone"
|
|
133
|
-
{...prefixFilter(
|
|
182
|
+
{...prefixFilter(restProps, 'phone$')}
|
|
134
183
|
/>
|
|
135
184
|
</div>
|
|
136
185
|
{/if}
|
|
137
186
|
{/if}
|
|
138
187
|
|
|
139
|
-
|
|
188
|
+
{@render additional?.()}
|
|
140
189
|
|
|
141
190
|
{#if failureMessage}
|
|
142
191
|
<div class="tilmeld-login-failure">
|
|
@@ -149,8 +198,8 @@
|
|
|
149
198
|
<Button
|
|
150
199
|
variant="raised"
|
|
151
200
|
type="submit"
|
|
152
|
-
|
|
153
|
-
{...prefixFilter(
|
|
201
|
+
onclick={login}
|
|
202
|
+
{...prefixFilter(restProps, 'loginButton$')}
|
|
154
203
|
>
|
|
155
204
|
<Label>Log In</Label>
|
|
156
205
|
</Button>
|
|
@@ -158,29 +207,29 @@
|
|
|
158
207
|
<Button
|
|
159
208
|
variant="raised"
|
|
160
209
|
type="submit"
|
|
161
|
-
|
|
162
|
-
{...prefixFilter(
|
|
210
|
+
onclick={register}
|
|
211
|
+
{...prefixFilter(restProps, 'registerButton$')}
|
|
163
212
|
>
|
|
164
213
|
<Label>Create Account</Label>
|
|
165
214
|
</Button>
|
|
166
215
|
{/if}
|
|
167
216
|
</div>
|
|
168
217
|
|
|
169
|
-
{#if clientConfig.allowRegistration && showExistingUserToggle}
|
|
218
|
+
{#if $clientConfig.allowRegistration && showExistingUserToggle}
|
|
170
219
|
<div class="tilmeld-login-action">
|
|
171
220
|
{#if mode === 'login'}
|
|
172
221
|
<a
|
|
173
|
-
href=
|
|
174
|
-
|
|
175
|
-
{...prefixFilter(
|
|
222
|
+
href={'javascript:void(0);'}
|
|
223
|
+
onclick={() => (mode = 'register')}
|
|
224
|
+
{...prefixFilter(restProps, 'registerLink$')}
|
|
176
225
|
>
|
|
177
226
|
Create an account.
|
|
178
227
|
</a>
|
|
179
228
|
{:else}
|
|
180
229
|
<a
|
|
181
|
-
href=
|
|
182
|
-
|
|
183
|
-
{...prefixFilter(
|
|
230
|
+
href={'javascript:void(0);'}
|
|
231
|
+
onclick={() => (mode = 'login')}
|
|
232
|
+
{...prefixFilter(restProps, 'loginLink$')}
|
|
184
233
|
>
|
|
185
234
|
Log in to your account.
|
|
186
235
|
</a>
|
|
@@ -188,117 +237,276 @@
|
|
|
188
237
|
</div>
|
|
189
238
|
{/if}
|
|
190
239
|
|
|
191
|
-
{#if !hideRecovery && clientConfig.pwRecovery && mode === 'login'}
|
|
240
|
+
{#if !hideRecovery && $clientConfig.userFields.includes('email') && $clientConfig.pwRecovery && mode === 'login'}
|
|
192
241
|
<div class="tilmeld-login-action">
|
|
193
242
|
<a
|
|
194
|
-
href=
|
|
195
|
-
|
|
196
|
-
{...prefixFilter(
|
|
243
|
+
href={'javascript:void(0);'}
|
|
244
|
+
onclick={() => (recoverOpen = true)}
|
|
245
|
+
{...prefixFilter(restProps, 'recoverLink$')}
|
|
197
246
|
>
|
|
198
247
|
I can't access my account.
|
|
199
248
|
</a>
|
|
200
249
|
</div>
|
|
201
|
-
<Recover
|
|
202
|
-
{User}
|
|
203
|
-
bind:open={recoverOpen}
|
|
204
|
-
bind:clientConfig
|
|
205
|
-
{...prefixFilter($$restProps, 'recover$')}
|
|
206
|
-
/>
|
|
207
250
|
{/if}
|
|
208
251
|
</form>
|
|
252
|
+
<Recover
|
|
253
|
+
{User}
|
|
254
|
+
bind:open={recoverOpen}
|
|
255
|
+
bind:clientConfig
|
|
256
|
+
{...prefixFilter(restProps, 'recover$')}
|
|
257
|
+
/>
|
|
209
258
|
{/if}
|
|
210
259
|
</div>
|
|
211
260
|
|
|
212
261
|
<script lang="ts">
|
|
213
|
-
import {
|
|
214
|
-
import {
|
|
262
|
+
import type { ComponentProps, Snippet } from 'svelte';
|
|
263
|
+
import { onMount } from 'svelte';
|
|
264
|
+
import type { Writable } from 'svelte/store';
|
|
265
|
+
import { writable } from 'svelte/store';
|
|
215
266
|
import CircularProgress from '@smui/circular-progress';
|
|
216
267
|
import Button, { Label } from '@smui/button';
|
|
217
268
|
import Textfield from '@smui/textfield';
|
|
218
269
|
import HelperText from '@smui/textfield/helper-text';
|
|
219
270
|
import type { ActionArray } from '@smui/common/internal';
|
|
220
|
-
import {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
prefixFilter,
|
|
224
|
-
useActions,
|
|
225
|
-
} from '@smui/common/internal';
|
|
271
|
+
import { exclude, prefixFilter, useActions } from '@smui/common/internal';
|
|
272
|
+
import { preventDefault, stopPropagation } from '@smui/common/events';
|
|
273
|
+
import type { SmuiElementPropMap } from '@smui/common';
|
|
226
274
|
import type {
|
|
227
275
|
User as UserClass,
|
|
228
276
|
ClientConfig,
|
|
277
|
+
UserData,
|
|
278
|
+
CurrentUserData,
|
|
229
279
|
} from '@nymphjs/tilmeld-client';
|
|
230
280
|
import {
|
|
231
281
|
login as loginAction,
|
|
232
282
|
register as registerAction,
|
|
233
283
|
checkUsername as checkUsernameAction,
|
|
284
|
+
NeedTOTPError,
|
|
234
285
|
} from '@nymphjs/tilmeld-client';
|
|
235
286
|
import Recover from './Recover.svelte';
|
|
236
287
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
288
|
+
type OwnProps = {
|
|
289
|
+
/**
|
|
290
|
+
* An array of Action or [Action, ActionProps] to be applied to the element.
|
|
291
|
+
*/
|
|
292
|
+
use?: ActionArray;
|
|
293
|
+
/**
|
|
294
|
+
* A list of CSS styles.
|
|
295
|
+
*/
|
|
296
|
+
style?: string;
|
|
297
|
+
/**
|
|
298
|
+
* A writable store of the Nymph client config.
|
|
299
|
+
*
|
|
300
|
+
* It will be retrieved from the server if not provided.
|
|
301
|
+
*/
|
|
302
|
+
clientConfig?: Writable<ClientConfig | undefined>;
|
|
303
|
+
/**
|
|
304
|
+
* The User class from Nymph.
|
|
305
|
+
*/
|
|
306
|
+
User: typeof UserClass;
|
|
307
|
+
/**
|
|
308
|
+
* Hide the recovery link that only appears if password recovery is on.
|
|
309
|
+
*/
|
|
310
|
+
hideRecovery?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Give focus to the username box (or email box) when the form is ready.
|
|
313
|
+
*/
|
|
314
|
+
autofocus?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* This determines whether the 'Log In' or 'Sign Up' button is activated
|
|
317
|
+
* and which corresponding form is shown.
|
|
318
|
+
*/
|
|
319
|
+
mode?: 'login' | 'register';
|
|
320
|
+
/**
|
|
321
|
+
* Whether to show the 'Log In'/'Sign Up' switcher buttons.
|
|
322
|
+
*/
|
|
323
|
+
showExistingUserToggle?: boolean;
|
|
324
|
+
/**
|
|
325
|
+
* The width of the form.
|
|
326
|
+
*/
|
|
327
|
+
width?: string;
|
|
328
|
+
/**
|
|
329
|
+
* User provided. You can bind to it if you need to.
|
|
330
|
+
*/
|
|
331
|
+
username?: string;
|
|
332
|
+
/**
|
|
333
|
+
* User provided. You can bind to it if you need to.
|
|
334
|
+
*/
|
|
335
|
+
password?: string;
|
|
336
|
+
/**
|
|
337
|
+
* User provided. You can bind to it if you need to.
|
|
338
|
+
*/
|
|
339
|
+
password2?: string;
|
|
340
|
+
/**
|
|
341
|
+
* User provided. You can bind to it if you need to.
|
|
342
|
+
*/
|
|
343
|
+
name?: string;
|
|
344
|
+
/**
|
|
345
|
+
* User provided. You can bind to it if you need to.
|
|
346
|
+
*/
|
|
347
|
+
email?: string;
|
|
348
|
+
/**
|
|
349
|
+
* User provided. You can bind to it if you need to.
|
|
350
|
+
*/
|
|
351
|
+
phone?: string;
|
|
352
|
+
/**
|
|
353
|
+
* User provided. You can bind to it if you need to.
|
|
354
|
+
*/
|
|
355
|
+
code?: string;
|
|
356
|
+
/**
|
|
357
|
+
* Provide this for anything else that should go up to the server.
|
|
358
|
+
*
|
|
359
|
+
* You can look for it in the User events.
|
|
360
|
+
*/
|
|
361
|
+
additionalData?: { [k: string]: any };
|
|
255
362
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
/** User provided. You can bind to it if you need to. */
|
|
261
|
-
export let password2 = '';
|
|
262
|
-
/** User provided. You can bind to it if you need to. */
|
|
263
|
-
export let name = '';
|
|
264
|
-
/** User provided. You can bind to it if you need to. */
|
|
265
|
-
export let email = '';
|
|
266
|
-
/** User provided. You can bind to it if you need to. */
|
|
267
|
-
export let phone = '';
|
|
363
|
+
/**
|
|
364
|
+
* A spot for additional content.
|
|
365
|
+
*/
|
|
366
|
+
additional?: Snippet;
|
|
268
367
|
|
|
269
|
-
|
|
270
|
-
|
|
368
|
+
/**
|
|
369
|
+
* A callback to be called when a user is registered.
|
|
370
|
+
*/
|
|
371
|
+
onregister?: (details: {
|
|
372
|
+
user: UserClass & UserData & CurrentUserData;
|
|
373
|
+
}) => void;
|
|
374
|
+
/**
|
|
375
|
+
* A callback to be called when a user is logged in.
|
|
376
|
+
*/
|
|
377
|
+
onlogin?: (details: {
|
|
378
|
+
user: UserClass & UserData & CurrentUserData;
|
|
379
|
+
}) => void;
|
|
380
|
+
};
|
|
381
|
+
let {
|
|
382
|
+
use = [],
|
|
383
|
+
style = '',
|
|
384
|
+
clientConfig = $bindable(writable(false as unknown as undefined)),
|
|
385
|
+
User,
|
|
386
|
+
hideRecovery = false,
|
|
387
|
+
autofocus = true,
|
|
388
|
+
mode = $bindable('login'),
|
|
389
|
+
showExistingUserToggle = true,
|
|
390
|
+
width = '220px',
|
|
391
|
+
username = $bindable(''),
|
|
392
|
+
password = $bindable(''),
|
|
393
|
+
password2 = $bindable(''),
|
|
394
|
+
name = $bindable(''),
|
|
395
|
+
email = $bindable(''),
|
|
396
|
+
phone = $bindable(''),
|
|
397
|
+
code = $bindable(''),
|
|
398
|
+
additionalData,
|
|
399
|
+
additional,
|
|
400
|
+
onregister,
|
|
401
|
+
onlogin,
|
|
402
|
+
...restProps
|
|
403
|
+
}: OwnProps & {
|
|
404
|
+
[
|
|
405
|
+
k in keyof SmuiElementPropMap['div'] as `successRegisteredMessage\$${k}`
|
|
406
|
+
]?: SmuiElementPropMap['div'][k];
|
|
407
|
+
} & {
|
|
408
|
+
[
|
|
409
|
+
k in keyof SmuiElementPropMap['div'] as `successLoginMessage\$${k}`
|
|
410
|
+
]?: SmuiElementPropMap['div'][k];
|
|
411
|
+
} & {
|
|
412
|
+
[
|
|
413
|
+
k in keyof ComponentProps<typeof Textfield> as `username\$${k}`
|
|
414
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
415
|
+
} & {
|
|
416
|
+
[
|
|
417
|
+
k in keyof ComponentProps<typeof Textfield> as `password\$${k}`
|
|
418
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
419
|
+
} & {
|
|
420
|
+
[
|
|
421
|
+
k in keyof ComponentProps<typeof Textfield> as `password2\$${k}`
|
|
422
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
423
|
+
} & {
|
|
424
|
+
[
|
|
425
|
+
k in keyof ComponentProps<typeof Textfield> as `name\$${k}`
|
|
426
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
427
|
+
} & {
|
|
428
|
+
[
|
|
429
|
+
k in keyof ComponentProps<typeof Textfield> as `email\$${k}`
|
|
430
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
431
|
+
} & {
|
|
432
|
+
[
|
|
433
|
+
k in keyof ComponentProps<typeof Textfield> as `phone\$${k}`
|
|
434
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
435
|
+
} & {
|
|
436
|
+
[
|
|
437
|
+
k in keyof ComponentProps<typeof Textfield> as `code\$${k}`
|
|
438
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
439
|
+
} & {
|
|
440
|
+
[
|
|
441
|
+
k in keyof SmuiElementPropMap['div'] as `codeMessage\$${k}`
|
|
442
|
+
]?: SmuiElementPropMap['div'][k];
|
|
443
|
+
} & {
|
|
444
|
+
[
|
|
445
|
+
k in keyof ComponentProps<typeof CircularProgress> as `progress\$${k}`
|
|
446
|
+
]?: ComponentProps<typeof CircularProgress>[k];
|
|
447
|
+
} & {
|
|
448
|
+
[
|
|
449
|
+
k in keyof ComponentProps<
|
|
450
|
+
typeof Button<undefined, 'button'>
|
|
451
|
+
> as `loginButton\$${k}`
|
|
452
|
+
]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
|
|
453
|
+
} & {
|
|
454
|
+
[
|
|
455
|
+
k in keyof ComponentProps<
|
|
456
|
+
typeof Button<undefined, 'button'>
|
|
457
|
+
> as `registerButton\$${k}`
|
|
458
|
+
]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
|
|
459
|
+
} & {
|
|
460
|
+
[
|
|
461
|
+
k in keyof SmuiElementPropMap['a'] as `registerLink\$${k}`
|
|
462
|
+
]?: SmuiElementPropMap['a'][k];
|
|
463
|
+
} & {
|
|
464
|
+
[
|
|
465
|
+
k in keyof SmuiElementPropMap['a'] as `loginLink\$${k}`
|
|
466
|
+
]?: SmuiElementPropMap['a'][k];
|
|
467
|
+
} & {
|
|
468
|
+
[
|
|
469
|
+
k in keyof SmuiElementPropMap['a'] as `recoverLink\$${k}`
|
|
470
|
+
]?: SmuiElementPropMap['a'][k];
|
|
471
|
+
} & {
|
|
472
|
+
[
|
|
473
|
+
k in keyof ComponentProps<typeof Recover> as `recover\$${k}`
|
|
474
|
+
]?: ComponentProps<typeof Recover>[k];
|
|
475
|
+
} = $props();
|
|
271
476
|
|
|
272
|
-
let usernameElem: Textfield;
|
|
273
|
-
let successLoginMessage: string | undefined =
|
|
274
|
-
let successRegisteredMessage: string | undefined =
|
|
275
|
-
let failureMessage: string | undefined =
|
|
276
|
-
let usernameTimer:
|
|
277
|
-
let usernameVerified: boolean | undefined =
|
|
278
|
-
let usernameVerifiedMessage: string | undefined =
|
|
279
|
-
let
|
|
280
|
-
let
|
|
281
|
-
let recoverOpen = false;
|
|
477
|
+
let usernameElem: Textfield | undefined = $state();
|
|
478
|
+
let successLoginMessage: string | undefined = $state();
|
|
479
|
+
let successRegisteredMessage: string | undefined = $state();
|
|
480
|
+
let failureMessage: string | undefined = $state();
|
|
481
|
+
let usernameTimer: number | undefined = undefined;
|
|
482
|
+
let usernameVerified: boolean | undefined = $state();
|
|
483
|
+
let usernameVerifiedMessage: string | undefined = $state();
|
|
484
|
+
let totp = $state(false);
|
|
485
|
+
let loading = $state(false);
|
|
486
|
+
let recoverOpen = $state(false);
|
|
282
487
|
|
|
283
|
-
|
|
284
|
-
|
|
488
|
+
const nameFirst = $derived(name?.match(/^(.*?)(?: ([^ ]+))?$/)?.[1] ?? '');
|
|
489
|
+
const nameLast = $derived(name?.match(/^(.*?)(?: ([^ ]+))?$/)?.[2] ?? '');
|
|
285
490
|
|
|
286
491
|
let _previousMode = mode;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
492
|
+
$effect(() => {
|
|
493
|
+
if (mode !== _previousMode) {
|
|
494
|
+
failureMessage = '';
|
|
495
|
+
checkUsername(username);
|
|
496
|
+
_previousMode = mode;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
292
499
|
|
|
293
|
-
|
|
500
|
+
$effect(() => {
|
|
294
501
|
checkUsername(username);
|
|
295
|
-
}
|
|
502
|
+
});
|
|
296
503
|
|
|
297
504
|
onMount(async () => {
|
|
298
|
-
if (clientConfig === undefined) {
|
|
299
|
-
clientConfig =
|
|
505
|
+
if ($clientConfig === (false as unknown as undefined)) {
|
|
506
|
+
$clientConfig = undefined;
|
|
507
|
+
$clientConfig = await User.getClientConfig();
|
|
300
508
|
}
|
|
301
|
-
if (
|
|
509
|
+
if (!$clientConfig.allowRegistration) {
|
|
302
510
|
mode = 'login';
|
|
303
511
|
}
|
|
304
512
|
if (autofocus && usernameElem) {
|
|
@@ -309,22 +517,34 @@
|
|
|
309
517
|
async function login() {
|
|
310
518
|
successLoginMessage = undefined;
|
|
311
519
|
failureMessage = undefined;
|
|
312
|
-
|
|
520
|
+
loading = true;
|
|
313
521
|
try {
|
|
314
|
-
const data = await loginAction(
|
|
522
|
+
const data = await loginAction(
|
|
523
|
+
User,
|
|
524
|
+
username,
|
|
525
|
+
password,
|
|
526
|
+
code,
|
|
527
|
+
additionalData,
|
|
528
|
+
);
|
|
315
529
|
successLoginMessage = data.message;
|
|
316
|
-
|
|
530
|
+
if (data.user) {
|
|
531
|
+
onlogin?.({ user: data.user });
|
|
532
|
+
}
|
|
317
533
|
} catch (e: any) {
|
|
318
|
-
|
|
534
|
+
if (e instanceof NeedTOTPError) {
|
|
535
|
+
totp = true;
|
|
536
|
+
} else {
|
|
537
|
+
failureMessage = e?.message;
|
|
538
|
+
}
|
|
319
539
|
}
|
|
320
|
-
|
|
540
|
+
loading = false;
|
|
321
541
|
}
|
|
322
542
|
|
|
323
543
|
async function register() {
|
|
324
544
|
successRegisteredMessage = undefined;
|
|
325
545
|
successLoginMessage = undefined;
|
|
326
546
|
failureMessage = undefined;
|
|
327
|
-
|
|
547
|
+
loading = true;
|
|
328
548
|
try {
|
|
329
549
|
const data = await registerAction(User, {
|
|
330
550
|
username,
|
|
@@ -338,15 +558,19 @@
|
|
|
338
558
|
...(additionalData ? { additionalData } : {}),
|
|
339
559
|
});
|
|
340
560
|
successRegisteredMessage = data.message;
|
|
341
|
-
|
|
561
|
+
if (data.user) {
|
|
562
|
+
onregister?.({ user: data.user });
|
|
563
|
+
}
|
|
342
564
|
if (data.loggedin) {
|
|
343
565
|
successLoginMessage = data.message;
|
|
344
|
-
|
|
566
|
+
if (data.user) {
|
|
567
|
+
onlogin?.({ user: data.user });
|
|
568
|
+
}
|
|
345
569
|
}
|
|
346
570
|
} catch (e: any) {
|
|
347
571
|
failureMessage = e?.message;
|
|
348
572
|
}
|
|
349
|
-
|
|
573
|
+
loading = false;
|
|
350
574
|
}
|
|
351
575
|
|
|
352
576
|
function checkUsername(newValue: string) {
|