feat(sync): paginate Android sync with change tokens
This commit is contained in:
1 parent
0ff94f9b10
commit
97c237be80
76 files changed
+3401
-851
No files matched your search
@@ -13,6 +13,7 @@
|
||||
onTotpSetup,
|
||||
onTotpStatus,
|
||||
totpEnabled = false,
|
||||
requireCredentialsForEmailChange = false,
|
||||
open = $bindable(false)
|
||||
}: {
|
||||
currentEmail?: string;
|
||||
@@ -23,6 +24,7 @@
|
||||
onTotpSetup?: TotpSetupRequest;
|
||||
onTotpStatus?: TotpStatusRequest;
|
||||
totpEnabled?: boolean;
|
||||
requireCredentialsForEmailChange?: boolean;
|
||||
open?: boolean;
|
||||
} = $props();
|
||||
|
||||
@@ -30,8 +32,13 @@
|
||||
let email = $state('');
|
||||
let password = $state('');
|
||||
let confirmPassword = $state('');
|
||||
let currentPassword = $state('');
|
||||
let totpToken = $state('');
|
||||
let error = $state('');
|
||||
let saving = $state(false);
|
||||
let requiresCurrentCredentials = $derived(
|
||||
!!password || (requireCredentialsForEmailChange && email.trim() !== currentEmail.trim())
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
if (open) {
|
||||
@@ -39,6 +46,8 @@
|
||||
email = currentEmail;
|
||||
password = '';
|
||||
confirmPassword = '';
|
||||
currentPassword = '';
|
||||
totpToken = '';
|
||||
error = '';
|
||||
}
|
||||
});
|
||||
@@ -52,6 +61,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (requiresCurrentCredentials && !currentPassword) {
|
||||
error = 'Enter your current password to change your email or password.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (requiresCurrentCredentials && totpEnabled && !totpToken) {
|
||||
error = 'Enter a current authenticator code to change your email or password.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!onSave) {
|
||||
error = 'The application has not configured its profile update handler.';
|
||||
return;
|
||||
@@ -59,7 +78,13 @@
|
||||
|
||||
saving = true;
|
||||
try {
|
||||
await onSave({ username, email, password: password || undefined });
|
||||
const input: ProfileUpdateInput = { username, email };
|
||||
if (requiresCurrentCredentials) {
|
||||
input.currentPassword = currentPassword;
|
||||
if (totpEnabled) input.totpToken = totpToken;
|
||||
}
|
||||
if (password) input.password = password;
|
||||
await onSave(input);
|
||||
open = false;
|
||||
} catch (caught) {
|
||||
error = caught instanceof Error ? caught.message : 'Profile update failed.';
|
||||
@@ -100,6 +125,35 @@
|
||||
/>
|
||||
</label>
|
||||
|
||||
{#if requiresCurrentCredentials}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Current password</span>
|
||||
<input
|
||||
autocomplete="current-password"
|
||||
class="sc-input"
|
||||
required
|
||||
type="password"
|
||||
bind:value={currentPassword}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{#if totpEnabled}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Current authenticator code</span>
|
||||
<input
|
||||
autocomplete="one-time-code"
|
||||
class="sc-input"
|
||||
inputmode="numeric"
|
||||
maxlength="6"
|
||||
pattern="[0-9]{6}"
|
||||
required
|
||||
type="text"
|
||||
bind:value={totpToken}
|
||||
/>
|
||||
</label>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if password}
|
||||
<label class="sc-field">
|
||||
<span class="sc-label">Confirm new password</span>
|
||||
|
||||
@@ -42,6 +42,8 @@ export interface ProfileUpdateInput {
|
||||
username: string;
|
||||
email: string;
|
||||
password?: string;
|
||||
currentPassword?: string;
|
||||
totpToken?: string;
|
||||
}
|
||||
|
||||
export type UserRole = "superadmin" | "admin" | "user";
|
||||
|
||||
Reference in new issue
Block a user