@@ -121,6 +121,63 @@ export async function handlePost(request, reply) {
121121 return reply . code ( 201 ) . send ( ) ;
122122}
123123
124+ /**
125+ * Create pod directory structure (reusable for registration)
126+ * @param {string } name - Pod name (username)
127+ * @param {string } webId - User's WebID URI
128+ * @param {string } baseUrl - Base URL (without trailing slash)
129+ */
130+ export async function createPodStructure ( name , webId , baseUrl ) {
131+ const podPath = `/${ name } /` ;
132+ const podUri = `${ baseUrl } /${ name } /` ;
133+ const issuer = baseUrl + '/' ;
134+
135+ // Create pod directory structure
136+ await storage . createContainer ( podPath ) ;
137+ await storage . createContainer ( `${ podPath } inbox/` ) ;
138+ await storage . createContainer ( `${ podPath } public/` ) ;
139+ await storage . createContainer ( `${ podPath } private/` ) ;
140+ await storage . createContainer ( `${ podPath } settings/` ) ;
141+
142+ // Generate and write WebID profile as index.html at pod root
143+ const profileHtml = generateProfile ( { webId, name, podUri, issuer } ) ;
144+ await storage . write ( `${ podPath } index.html` , profileHtml ) ;
145+
146+ // Generate and write preferences
147+ const prefs = generatePreferences ( { webId, podUri } ) ;
148+ await storage . write ( `${ podPath } settings/prefs` , serialize ( prefs ) ) ;
149+
150+ // Generate and write type indexes
151+ const publicTypeIndex = generateTypeIndex ( `${ podUri } settings/publicTypeIndex` ) ;
152+ await storage . write ( `${ podPath } settings/publicTypeIndex` , serialize ( publicTypeIndex ) ) ;
153+
154+ const privateTypeIndex = generateTypeIndex ( `${ podUri } settings/privateTypeIndex` ) ;
155+ await storage . write ( `${ podPath } settings/privateTypeIndex` , serialize ( privateTypeIndex ) ) ;
156+
157+ // Create default ACL files
158+ // Pod root: owner full control, public read
159+ const rootAcl = generateOwnerAcl ( podUri , webId , true ) ;
160+ await storage . write ( `${ podPath } .acl` , serializeAcl ( rootAcl ) ) ;
161+
162+ // Private folder: owner only (no public)
163+ const privateAcl = generatePrivateAcl ( `${ podUri } private/` , webId ) ;
164+ await storage . write ( `${ podPath } private/.acl` , serializeAcl ( privateAcl ) ) ;
165+
166+ // Settings folder: owner only
167+ const settingsAcl = generatePrivateAcl ( `${ podUri } settings/` , webId ) ;
168+ await storage . write ( `${ podPath } settings/.acl` , serializeAcl ( settingsAcl ) ) ;
169+
170+ // Inbox: owner full, public append
171+ const inboxAcl = generateInboxAcl ( `${ podUri } inbox/` , webId ) ;
172+ await storage . write ( `${ podPath } inbox/.acl` , serializeAcl ( inboxAcl ) ) ;
173+
174+ // Public folder: owner full, public read (with inheritance)
175+ const publicAcl = generatePublicFolderAcl ( `${ podUri } public/` , webId ) ;
176+ await storage . write ( `${ podPath } public/.acl` , serializeAcl ( publicAcl ) ) ;
177+
178+ return { podPath, podUri } ;
179+ }
180+
124181/**
125182 * Create a pod (container) for a user
126183 * POST /.pods with { "name": "alice" }
@@ -149,8 +206,8 @@ export async function handleCreatePod(request, reply) {
149206 if ( ! email || typeof email !== 'string' ) {
150207 return reply . code ( 400 ) . send ( { error : 'Email required for account creation' } ) ;
151208 }
152- if ( ! password || password . length < 8 ) {
153- return reply . code ( 400 ) . send ( { error : 'Password required (minimum 8 characters) ' } ) ;
209+ if ( ! password ) {
210+ return reply . code ( 400 ) . send ( { error : 'Password required' } ) ;
154211 }
155212 }
156213
@@ -189,49 +246,8 @@ export async function handleCreatePod(request, reply) {
189246 const issuer = baseUri + '/' ;
190247
191248 try {
192- // Create pod directory structure
193- await storage . createContainer ( podPath ) ;
194- await storage . createContainer ( `${ podPath } inbox/` ) ;
195- await storage . createContainer ( `${ podPath } public/` ) ;
196- await storage . createContainer ( `${ podPath } private/` ) ;
197- await storage . createContainer ( `${ podPath } settings/` ) ;
198-
199- // Generate and write WebID profile as index.html at pod root
200- const profileHtml = generateProfile ( { webId, name, podUri, issuer } ) ;
201- await storage . write ( `${ podPath } index.html` , profileHtml ) ;
202-
203- // Generate and write preferences
204- const prefs = generatePreferences ( { webId, podUri } ) ;
205- await storage . write ( `${ podPath } settings/prefs` , serialize ( prefs ) ) ;
206-
207- // Generate and write type indexes
208- const publicTypeIndex = generateTypeIndex ( `${ podUri } settings/publicTypeIndex` ) ;
209- await storage . write ( `${ podPath } settings/publicTypeIndex` , serialize ( publicTypeIndex ) ) ;
210-
211- const privateTypeIndex = generateTypeIndex ( `${ podUri } settings/privateTypeIndex` ) ;
212- await storage . write ( `${ podPath } settings/privateTypeIndex` , serialize ( privateTypeIndex ) ) ;
213-
214- // Create default ACL files
215- // Pod root: owner full control, public read
216- const rootAcl = generateOwnerAcl ( podUri , webId , true ) ;
217- await storage . write ( `${ podPath } .acl` , serializeAcl ( rootAcl ) ) ;
218-
219- // Private folder: owner only (no public)
220- const privateAcl = generatePrivateAcl ( `${ podUri } private/` , webId ) ;
221- await storage . write ( `${ podPath } private/.acl` , serializeAcl ( privateAcl ) ) ;
222-
223- // Settings folder: owner only
224- const settingsAcl = generatePrivateAcl ( `${ podUri } settings/` , webId ) ;
225- await storage . write ( `${ podPath } settings/.acl` , serializeAcl ( settingsAcl ) ) ;
226-
227- // Inbox: owner full, public append
228- const inboxAcl = generateInboxAcl ( `${ podUri } inbox/` , webId ) ;
229- await storage . write ( `${ podPath } inbox/.acl` , serializeAcl ( inboxAcl ) ) ;
230-
231- // Public folder: owner full, public read (with inheritance)
232- const publicAcl = generatePublicFolderAcl ( `${ podUri } public/` , webId ) ;
233- await storage . write ( `${ podPath } public/.acl` , serializeAcl ( publicAcl ) ) ;
234-
249+ // Use shared pod creation function
250+ await createPodStructure ( name , webId , baseUri ) ;
235251 } catch ( err ) {
236252 console . error ( 'Pod creation error:' , err ) ;
237253 // Cleanup on failure
@@ -249,7 +265,7 @@ export async function handleCreatePod(request, reply) {
249265 if ( idpEnabled ) {
250266 try {
251267 const { createAccount } = await import ( '../idp/accounts.js' ) ;
252- await createAccount ( { email, password, webId, podName : name } ) ;
268+ await createAccount ( { username : name , email, password, webId, podName : name } ) ;
253269
254270 return reply . code ( 201 ) . send ( {
255271 name,
0 commit comments