Skip to content

Commit 802b9a5

Browse files
committed
fix a bug with user profile screen
1 parent 17877be commit 802b9a5

5 files changed

Lines changed: 30 additions & 42 deletions

File tree

ARCHITECTURE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# MWS Server Architecture Explained
22

3+
https://deepwiki.com/TiddlyWiki/MultiWikiServer
4+
35
## Overview
46

57
The system treats a public wiki as a named, database-backed resource addressed by a slug. Internally that wiki is backed by a recipe, but for most developer-facing purposes it is simplest to think in terms of a wiki assembled from three things: a template, a set of bags, and a plugin set.

packages/admin-vanilla/src/FomController.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,23 @@ export class FomController<T extends AdminRecord> {
122122
// #region common
123123
// Keep the shared card structure in one place so each form mode only supplies its
124124
// mode-specific title, copy, fields, extra content, and actions.
125-
renderCommon({ title, copy, submitDisabled, submitAction, submitLabel, isStart: isStart, handleBackClick }: {
125+
renderCommon({
126+
title,
127+
copy,
128+
submitDisabled,
129+
submitAction,
130+
submitLabel,
131+
isStart: isStart,
132+
backAction: handleBackClick,
133+
backLabel = "Cancel",
134+
}: {
126135
title: string;
127136
copy: string;
128137
submitDisabled: boolean;
129138
submitLabel: string;
130139
submitAction: () => Promise<void>;
131-
handleBackClick: () => Promise<void>;
140+
backAction: () => Promise<void>;
141+
backLabel?: string;
132142
isStart?: boolean;
133143
}, content: JSX.Node): JSX.Node {
134144
return (
@@ -165,7 +175,7 @@ export class FomController<T extends AdminRecord> {
165175
type="button"
166176
disabled={this.isSubmitting}
167177
onclick={handleBackClick}
168-
>Cancel</button>}
178+
>{backLabel}</button>}
169179
<button
170180
class="primary-button login-submit"
171181
type="button"

packages/admin-vanilla/src/app-login.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class LoginForm extends JSXElement {
232232
submitDisabled: isLoginPageBusy,
233233
submitLabel: this.isSubmitting ? "Logging in…" : "Log in",
234234
isStart: true,
235-
handleBackClick: this.handleBackClick,
235+
backAction: this.handleBackClick,
236236
}, <>
237237
<div class="login-fields">{this.fields.map((field) => this.control.renderField(field))}</div>
238238
<div class="login-options" aria-label="Login options">
@@ -275,7 +275,7 @@ export class LoginForm extends JSXElement {
275275
submitAction: this.handleForgotPasswordSubmit,
276276
submitDisabled: isSubmitDisabled,
277277
submitLabel: isForgotPasswordEmailEnabled ? "Send Email" : "Enter Code",
278-
handleBackClick: this.handleBackClick,
278+
backAction: this.handleBackClick,
279279
}, this.isResolvingServerState ? (
280280
<div class="modal-loading-shell">
281281
<div class="modal-loading-bar" aria-hidden="true"><span></span></div>
@@ -301,7 +301,7 @@ export class LoginForm extends JSXElement {
301301
submitAction: this.handleResetCodeSubmit,
302302
submitDisabled: resetCodeActionDisabled,
303303
submitLabel: "Verify code",
304-
handleBackClick: this.handleBackClick,
304+
backAction: this.handleBackClick,
305305
}, <>
306306
<div class="login-fields">
307307
{!this.serverState?.emailEnabled &&
@@ -326,7 +326,7 @@ export class LoginForm extends JSXElement {
326326
submitAction: this.handleUpdatePasswordSubmit,
327327
submitDisabled: updatePasswordActionDisabled,
328328
submitLabel: "Update password",
329-
handleBackClick: this.handleBackClick,
329+
backAction: this.handleBackClick,
330330
}, <>
331331
<div class="login-fields">
332332
{renderCallout("Username: " + this.draft.username)}

packages/admin-vanilla/src/app-profile.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export class ProfileForm extends JSXElement {
110110
submitAction: this.handleProfileSubmit,
111111
submitDisabled: false,
112112
submitLabel: "Update Password",
113-
handleBackClick: this.onCancel,
113+
backAction: this.onCancel,
114+
backLabel: "Close",
114115
}, <>
115116
<div class="login-fields">
116117
{profileFields.map((field) => this.control.renderField(field))}
@@ -133,7 +134,7 @@ export class ProfileForm extends JSXElement {
133134
submitAction: this.handleUpdatePasswordSubmit,
134135
submitDisabled: updatePasswordActionDisabled,
135136
submitLabel: "Update password",
136-
handleBackClick: async () => { this.mode = "profile"; },
137+
backAction: async () => { this.mode = "profile"; },
137138
}, <>
138139
<div class="login-fields">
139140
{updatePasswordFields.map((field) => this.control.renderField(field))}

packages/admin-vanilla/src/passwords.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const sessionRequest: SessionManagerMap = {
88
login2: sessionManager("login2", "/login/2"),
99
logout: sessionManager("logout", "/logout"),
1010
forgotPassword: sessionManager("forgotPassword", "/login/forgot-password"),
11-
resetPassword: sessionManager("resetPassword", "/login/reset-password")
11+
resetPassword: sessionManager("resetPassword", "/login/reset-password"),
12+
user_update_password: sessionManager("user_update_password", "/login/user_update_password"),
1213
}
1314

1415
function sessionManager<K extends keyof SessionManagerMap>(key: K, path: SessionManagerMap[K]["path"]) {
@@ -29,32 +30,6 @@ function sessionManager<K extends keyof SessionManagerMap>(key: K, path: Session
2930
return t;
3031
}
3132

32-
const user_update_password_body = (z: Z2<"JSON">) => z.object({
33-
user_id: z.prismaField("Users", "user_id", "string"),
34-
registrationRequest: z.string().optional(),
35-
registrationRecord: z.string().optional(),
36-
session_id: z.string().optional(),
37-
signature: z.string().optional(),
38-
});
39-
40-
async function user_update_password(data: zod.infer<ART<typeof user_update_password_body>>): Promise<string | null | undefined> {
41-
const result = await fetch("/admin/user_update_password", {
42-
headers: {
43-
"X-Requested-With": "TiddlyWiki",
44-
"Content-Type": "application/json",
45-
},
46-
body: JSON.stringify(data)
47-
});
48-
49-
if (result.ok) {
50-
return (result.status === 200) ? await result.json() : undefined;
51-
} else {
52-
throw new Error(await result.text());
53-
}
54-
55-
}
56-
57-
5833
function arrayBufferToBase64_viaBlob(buffer: ArrayBuffer) {
5934
return new Promise<string>((resolve, reject) => {
6035
const blob = new Blob([buffer], { type: "application/octet-stream" });
@@ -89,7 +64,7 @@ export async function createNewPassword({ user_id, password }: { user_id: string
8964
password
9065
});
9166

92-
const registrationResponse = await user_update_password({
67+
const registrationResponse = await sessionRequest.user_update_password({
9368
user_id, registrationRequest
9469
});
9570

@@ -99,7 +74,7 @@ export async function createNewPassword({ user_id, password }: { user_id: string
9974
clientRegistrationState, registrationResponse, password
10075
});
10176

102-
await user_update_password({
77+
await sessionRequest.user_update_password({
10378
user_id, registrationRecord
10479
});
10580

@@ -112,7 +87,7 @@ export async function changeExistingPasswordAdmin({ user_id, newPassword }: { us
11287

11388
const { clientRegistrationState, registrationRequest } = opaque.client.startRegistration({ password: newPassword });
11489

115-
const registrationResponse = await user_update_password({
90+
const registrationResponse = await sessionRequest.user_update_password({
11691
user_id, registrationRequest
11792
});
11893

@@ -122,7 +97,7 @@ export async function changeExistingPasswordAdmin({ user_id, newPassword }: { us
12297
clientRegistrationState, registrationResponse, password: newPassword,
12398
});
12499

125-
await user_update_password({ user_id, registrationRecord });
100+
await sessionRequest.user_update_password({ user_id, registrationRecord });
126101

127102
}
128103

@@ -139,7 +114,7 @@ export async function changeExistingPasswordWithPassword({ username, password, n
139114

140115
const signature = await generateSessionSignature(sessionKey, session_id);
141116

142-
const registrationResponse = await user_update_password({
117+
const registrationResponse = await sessionRequest.user_update_password({
143118
user_id, registrationRequest, session_id, signature
144119
});
145120

@@ -149,7 +124,7 @@ export async function changeExistingPasswordWithPassword({ username, password, n
149124
clientRegistrationState, registrationResponse, password: newPassword,
150125
});
151126

152-
await user_update_password({ user_id, registrationRecord, session_id, signature });
127+
await sessionRequest.user_update_password({ user_id, registrationRecord, session_id, signature });
153128

154129
// this closes the login session we opened for the password change
155130
await sessionRequest.logout({ session_id, signature, skipCookie: true });

0 commit comments

Comments
 (0)