@nymphjs/tilmeld-components 1.0.0-beta.14 → 1.0.0-beta.140
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 +532 -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
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
<svelte:options runes />
|
|
2
|
+
|
|
3
|
+
{#if $user != null}
|
|
4
|
+
<Dialog
|
|
5
|
+
{use}
|
|
6
|
+
bind:open
|
|
7
|
+
aria-labelledby="tilmeld-revoke-tokens-title"
|
|
8
|
+
aria-describedby="tilmeld-revoke-tokens-content"
|
|
9
|
+
surface$class="tilmeld-revoke-tokens-dialog-surface"
|
|
10
|
+
{...exclude(restProps, [
|
|
11
|
+
'password$',
|
|
12
|
+
'closeButton$',
|
|
13
|
+
'saveButton$',
|
|
14
|
+
'progress$',
|
|
15
|
+
])}
|
|
16
|
+
>
|
|
17
|
+
<!-- Title cannot contain leading whitespace due to mdc-typography-baseline-top() -->
|
|
18
|
+
<Title id="tilmeld-revoke-tokens-title">{title}</Title>
|
|
19
|
+
<Content id="tilmeld-revoke-tokens-content">
|
|
20
|
+
<form onsubmit={preventDefault(stopPropagation(revokeTokens))}>
|
|
21
|
+
<div>
|
|
22
|
+
{description}
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div style="margin-top: 1em;">
|
|
26
|
+
<Textfield
|
|
27
|
+
bind:value={password}
|
|
28
|
+
label="Password"
|
|
29
|
+
type="password"
|
|
30
|
+
style="width: 100%;"
|
|
31
|
+
input$autocomplete="current-password"
|
|
32
|
+
{...prefixFilter(restProps, 'password$')}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
{@render additional?.()}
|
|
37
|
+
|
|
38
|
+
{#if failureMessage}
|
|
39
|
+
<div class="tilmeld-revoke-tokens-failure">
|
|
40
|
+
{failureMessage}
|
|
41
|
+
</div>
|
|
42
|
+
{/if}
|
|
43
|
+
|
|
44
|
+
{#if loading}
|
|
45
|
+
<div class="tilmeld-revoke-tokens-loading">
|
|
46
|
+
<CircularProgress
|
|
47
|
+
style="height: 24px; width: 24px;"
|
|
48
|
+
indeterminate
|
|
49
|
+
{...prefixFilter(restProps, 'progress$')}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
{/if}
|
|
53
|
+
</form>
|
|
54
|
+
</Content>
|
|
55
|
+
<Actions>
|
|
56
|
+
<Button disabled={loading} {...prefixFilter(restProps, 'closeButton$')}>
|
|
57
|
+
<Label>Close</Label>
|
|
58
|
+
</Button>
|
|
59
|
+
<Button
|
|
60
|
+
onclick={preventDefault(stopPropagation(revokeTokens))}
|
|
61
|
+
disabled={loading}
|
|
62
|
+
{...prefixFilter(restProps, 'saveButton$')}
|
|
63
|
+
>
|
|
64
|
+
<Label>Log Out Other Sessions</Label>
|
|
65
|
+
</Button>
|
|
66
|
+
</Actions>
|
|
67
|
+
</Dialog>
|
|
68
|
+
{/if}
|
|
69
|
+
|
|
70
|
+
<script lang="ts">
|
|
71
|
+
import type { ComponentProps, Snippet } from 'svelte';
|
|
72
|
+
import { onMount, onDestroy } from 'svelte';
|
|
73
|
+
import type { Writable } from 'svelte/store';
|
|
74
|
+
import { writable } from 'svelte/store';
|
|
75
|
+
import CircularProgress from '@smui/circular-progress';
|
|
76
|
+
import Dialog, { Title, Content, Actions } from '@smui/dialog';
|
|
77
|
+
import Textfield from '@smui/textfield';
|
|
78
|
+
import Button, { Label } from '@smui/button';
|
|
79
|
+
import type { ActionArray } from '@smui/common/internal';
|
|
80
|
+
import { exclude, prefixFilter } from '@smui/common/internal';
|
|
81
|
+
import { preventDefault, stopPropagation } from '@smui/common/events';
|
|
82
|
+
import type { CurrentUserData } from '@nymphjs/tilmeld-client';
|
|
83
|
+
import type { User as UserClass } from '@nymphjs/tilmeld-client';
|
|
84
|
+
|
|
85
|
+
type OwnProps = {
|
|
86
|
+
/**
|
|
87
|
+
* An array of Action or [Action, ActionProps] to be applied to the element.
|
|
88
|
+
*/
|
|
89
|
+
use?: ActionArray;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the dialog is open.
|
|
92
|
+
*/
|
|
93
|
+
open?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The title of the dialog.
|
|
96
|
+
*/
|
|
97
|
+
title?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The description of the action given to the user.
|
|
100
|
+
*/
|
|
101
|
+
description?: string;
|
|
102
|
+
/**
|
|
103
|
+
* The User class from Nymph.
|
|
104
|
+
*/
|
|
105
|
+
User: typeof UserClass;
|
|
106
|
+
/**
|
|
107
|
+
* A writable store of the current user.
|
|
108
|
+
*
|
|
109
|
+
* It will be retrieved from the server if not provided.
|
|
110
|
+
*/
|
|
111
|
+
user?: Writable<(UserClass & CurrentUserData) | null | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* User provided. You can bind to it if you need to.
|
|
114
|
+
*/
|
|
115
|
+
password?: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A spot for additional content.
|
|
119
|
+
*/
|
|
120
|
+
additional?: Snippet;
|
|
121
|
+
};
|
|
122
|
+
let {
|
|
123
|
+
use = [],
|
|
124
|
+
open = $bindable(false),
|
|
125
|
+
title = 'Log Out of Other Sessions',
|
|
126
|
+
description = 'This will log you out of all other sessions. You can use this if you think your account has been compromised. You will need to log in again on your other devices.',
|
|
127
|
+
User,
|
|
128
|
+
user = $bindable(writable(false as unknown as undefined)),
|
|
129
|
+
password = $bindable(''),
|
|
130
|
+
additional,
|
|
131
|
+
...restProps
|
|
132
|
+
}: OwnProps & {
|
|
133
|
+
[
|
|
134
|
+
k in keyof ComponentProps<typeof Textfield> as `password\$${k}`
|
|
135
|
+
]?: ComponentProps<typeof Textfield>[k];
|
|
136
|
+
} & {
|
|
137
|
+
[
|
|
138
|
+
k in keyof ComponentProps<typeof CircularProgress> as `progress\$${k}`
|
|
139
|
+
]?: ComponentProps<typeof CircularProgress>[k];
|
|
140
|
+
} & {
|
|
141
|
+
[
|
|
142
|
+
k in keyof ComponentProps<
|
|
143
|
+
typeof Button<undefined, 'button'>
|
|
144
|
+
> as `closeButton\$${k}`
|
|
145
|
+
]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
|
|
146
|
+
} & {
|
|
147
|
+
[
|
|
148
|
+
k in keyof ComponentProps<
|
|
149
|
+
typeof Button<undefined, 'button'>
|
|
150
|
+
> as `saveButton\$${k}`
|
|
151
|
+
]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
|
|
152
|
+
} = $props();
|
|
153
|
+
|
|
154
|
+
let loading = $state(false);
|
|
155
|
+
let failureMessage: string | undefined = $state();
|
|
156
|
+
|
|
157
|
+
$effect(() => {
|
|
158
|
+
if (!open) {
|
|
159
|
+
loading = false;
|
|
160
|
+
failureMessage = undefined;
|
|
161
|
+
password = '';
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const onLogin = (currentUser: UserClass & CurrentUserData) => {
|
|
166
|
+
$user = currentUser;
|
|
167
|
+
};
|
|
168
|
+
const onLogout = () => {
|
|
169
|
+
$user = null;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
onMount(async () => {
|
|
173
|
+
User.on('login', onLogin);
|
|
174
|
+
User.on('logout', onLogout);
|
|
175
|
+
if ($user === (false as unknown as undefined)) {
|
|
176
|
+
$user = undefined;
|
|
177
|
+
$user = await User.current();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
onDestroy(() => {
|
|
182
|
+
User.off('login', onLogin);
|
|
183
|
+
User.off('logout', onLogout);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
async function revokeTokens() {
|
|
187
|
+
if (password === '') {
|
|
188
|
+
failureMessage = 'You need to enter your password';
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
failureMessage = undefined;
|
|
193
|
+
loading = true;
|
|
194
|
+
|
|
195
|
+
// Get the current user again, in case their data has changed.
|
|
196
|
+
$user = await User.current();
|
|
197
|
+
|
|
198
|
+
if ($user == null) {
|
|
199
|
+
failureMessage = 'You must be logged in.';
|
|
200
|
+
loading = false;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
// Revoke the current tokens.
|
|
206
|
+
const data = await $user.$revokeCurrentTokens({
|
|
207
|
+
password,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (!data.result) {
|
|
211
|
+
failureMessage = data.message;
|
|
212
|
+
} else {
|
|
213
|
+
open = false;
|
|
214
|
+
}
|
|
215
|
+
} catch (e: any) {
|
|
216
|
+
failureMessage = e?.message;
|
|
217
|
+
}
|
|
218
|
+
loading = false;
|
|
219
|
+
}
|
|
220
|
+
</script>
|
|
221
|
+
|
|
222
|
+
<style>
|
|
223
|
+
:global(
|
|
224
|
+
.mdc-dialog .mdc-dialog__surface.tilmeld-revoke-tokens-dialog-surface
|
|
225
|
+
) {
|
|
226
|
+
width: 360px;
|
|
227
|
+
max-width: calc(100vw - 32px);
|
|
228
|
+
}
|
|
229
|
+
.tilmeld-revoke-tokens-failure {
|
|
230
|
+
margin-top: 1em;
|
|
231
|
+
color: var(--mdc-theme-error, #f00);
|
|
232
|
+
}
|
|
233
|
+
.tilmeld-revoke-tokens-loading {
|
|
234
|
+
display: flex;
|
|
235
|
+
justify-content: center;
|
|
236
|
+
align-items: center;
|
|
237
|
+
}
|
|
238
|
+
</style>
|