diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js index ec5b81f2943..a0065495417 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js @@ -22,12 +22,20 @@ exports.bodyFormat = "www-form-urlencoded"; exports.csrfDisable = true; +function deleteQueryParams() { + setTimeout(() => { + $tw.mws.store.adminWiki.deleteTiddler("$:/temp/mws/queryParams"); + }, 1000); +} + exports.handler = function(request, response, state) { + var current_user_id = state.authenticatedUser.user_id; var sqlTiddlerDatabase = state.server.sqlTiddlerDatabase; var username = state.data.username; var email = state.data.email; var password = state.data.password; var confirmPassword = state.data.confirmPassword; + var queryParamsTiddlerTitle = "$:/temp/mws/"+state.authenticatedUser.user_id+"/queryParams"; if(!state.authenticatedUser && !state.firstGuestUser) { $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ @@ -44,6 +52,11 @@ exports.handler = function(request, response, state) { title: "$:/temp/mws/post-user/error", text: "All fields are required" })); + $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ + title: queryParamsTiddlerTitle, + username: username, + email: email, + })); response.writeHead(302, { "Location": "/admin/users" }); response.end(); return; @@ -54,8 +67,14 @@ exports.handler = function(request, response, state) { title: "$:/temp/mws/post-user/error", text: "Passwords do not match" })); + $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ + title: "$:/temp/mws/queryParams", + username: username, + email: email, + })); response.writeHead(302, { "Location": "/admin/users" }); response.end(); + deleteQueryParams(); return; } @@ -67,8 +86,14 @@ exports.handler = function(request, response, state) { title: "$:/temp/mws/post-user/error", text: "Username already exists" })); + $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ + title: queryParamsTiddlerTitle, + username: username, + email: email, + })); response.writeHead(302, { "Location": "/admin/users" }); response.end(); + deleteQueryParams(); return; } @@ -101,8 +126,14 @@ exports.handler = function(request, response, state) { title: "$:/temp/mws/post-user/error", text: "Error creating admin user" })); + $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ + title: queryParamsTiddlerTitle, + username: username, + email: email, + })); response.writeHead(302, { "Location": "/admin/users" }); response.end(); + deleteQueryParams(); return; } } else { @@ -110,6 +141,11 @@ exports.handler = function(request, response, state) { title: "$:/temp/mws/post-user/success", text: "User created successfully" })); + $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ + title: queryParamsTiddlerTitle, + username: username, + email: email, + })); // assign role to user const roles = sqlTiddlerDatabase.listRoles(); const roleId = roles.find(role => role.role_name.toUpperCase() !== "ADMIN")?.role_id; @@ -118,14 +154,21 @@ exports.handler = function(request, response, state) { } response.writeHead(302, {"Location": "/admin/users/"+userId}); response.end(); + deleteQueryParams(); } } catch (error) { $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ title: "$:/temp/mws/post-user/error", text: "Error creating user: " + error.message })); + $tw.mws.store.adminWiki.addTiddler(new $tw.Tiddler({ + title: queryParamsTiddlerTitle, + username: username, + email: email, + })); response.writeHead(302, { "Location": "/admin/users" }); response.end(); + deleteQueryParams(); return; } }; diff --git a/plugins/tiddlywiki/multiwikiserver/templates/add-user-form.tid b/plugins/tiddlywiki/multiwikiserver/templates/add-user-form.tid index 23f1d7221a0..fbb04ec72ba 100644 --- a/plugins/tiddlywiki/multiwikiserver/templates/add-user-form.tid +++ b/plugins/tiddlywiki/multiwikiserver/templates/add-user-form.tid @@ -1,22 +1,24 @@ title: $:/plugins/tiddlywiki/multiwikiserver/templates/add-user-form

Add New User

-
-
- - -
-
- - -
+ + <$vars username={{{ [[$:/temp/mws/queryParams]get[username]] }}} email={{{ [[$:/temp/mws/queryParams]get[email]] }}}> +
+ + > autocomplete="new-password" readonly> +
+
+ + > autocomplete="new-password" readonly> +
+
- +
- +
<$list filter="[[$:/temp/mws/post-user/error]!is[missing]]" variable="errorTiddler"> diff --git a/plugins/tiddlywiki/multiwikiserver/templates/page.tid b/plugins/tiddlywiki/multiwikiserver/templates/page.tid index c515d458be9..337f4865b67 100644 --- a/plugins/tiddlywiki/multiwikiserver/templates/page.tid +++ b/plugins/tiddlywiki/multiwikiserver/templates/page.tid @@ -10,6 +10,17 @@ page-content: title of tiddler containing the main page content + `