Skip to content

Commit f9333b3

Browse files
authored
feat: add option to disable temporary users
1 parent ba50d0f commit f9333b3

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

src/backend/src/config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ let config = {};
2525
// Static defaults
2626
config.servers = [];
2727

28+
// Will disable the auto-generated temp users. If a user lands on the site, they will be required to sign up or log in.
29+
config.disable_temp_users = false;
30+
2831
config.max_file_size = 100_000_000_000,
2932
config.max_thumb_size = 1_000,
3033
config.max_fsentry_name_length = 767,
@@ -131,7 +134,6 @@ const config_pointer = {};
131134
config_to_export = config_pointer;
132135
}
133136

134-
135137
// We have some methods that can be called on `config`
136138
{
137139
// Add configuration values with precedence over the current config

src/backend/src/routers/signup.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ module.exports = eggspress(['/signup'], {
100100
}
101101

102102
// temporary user
103-
if(req.body.is_temp){
103+
if(req.body.is_temp && !config.disable_temp_users){
104104
req.body.username = await generate_random_username();
105105
req.body.email = req.body.username + '@gmail.com';
106106
req.body.password = 'sadasdfasdfsadfsa';
107+
}else if(config.disable_temp_users){
108+
return res.status(400).send('Temp users are disabled.');
107109
}
108110

109111
// send_confirmation_code

src/backend/src/services/PuterHomepageService.js

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class PuterHomepageService extends BaseService {
108108
require_email_verification_to_publish_website: config.require_email_verification_to_publish_website,
109109
short_description: config.short_description,
110110
long_description: config.long_description,
111+
disable_temp_users: config.disable_temp_users,
111112
},
112113
}));
113114
}

src/gui/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ window.puter_gui_enabled = true;
3131
* @param {string} [options.api_origin='https://api.puter.com'] - The origin URL for the API.
3232
* @param {number} [options.max_item_name_length=500] - Maximum allowed length for an item name.
3333
* @param {boolean} [options.require_email_verification_to_publish_website=true] - Flag to decide whether email verification is required to publish a website.
34+
* @param {boolean} [options.disable_temp_users=false] - Flag to disable auto-generated temporary users.
3435
*
3536
* @property {string} [options.app_domain] - Extracted domain name from gui_origin. It's derived automatically if not provided.
3637
* @property {string} [window.gui_env] - The environment in which the GUI is running (e.g., "dev" or "prod").
@@ -54,6 +55,7 @@ window.gui = async function(options){
5455
window.api_origin = options.api_origin ?? "https://api.puter.com";
5556
window.max_item_name_length = options.max_item_name_length ?? 500;
5657
window.require_email_verification_to_publish_website = options.require_email_verification_to_publish_website ?? true;
58+
window.disable_temp_users = options.disable_temp_users ?? false;
5759

5860
// DEV: Load the initgui.js file if we are in development mode
5961
if(!window.gui_env || window.gui_env === "dev"){
@@ -73,6 +75,7 @@ window.gui = async function(options){
7375

7476
// 🚀 Launch the GUI 🚀
7577
window.initgui(options);
78+
7679
}
7780

7881
/**

src/gui/src/initgui.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ window.initgui = async function(options){
831831
// -------------------------------------------------------------------------------------
832832
// Un-authed but not first visit -> try to log in/sign up
833833
// -------------------------------------------------------------------------------------
834-
if(!window.is_auth() && !window.first_visit_ever){
834+
if(!window.is_auth() && (!window.first_visit_ever || window.disable_temp_users)){
835835
if(window.logged_in_users.length > 0){
836836
UIWindowSessionList();
837837
}
@@ -849,7 +849,7 @@ window.initgui = async function(options){
849849
// -------------------------------------------------------------------------------------
850850
// Un-authed and first visit ever -> create temp user
851851
// -------------------------------------------------------------------------------------
852-
else if(!window.is_auth() && window.first_visit_ever){
852+
else if(!window.is_auth() && window.first_visit_ever && !window.disable_temp_users){
853853
let referrer;
854854
try{
855855
referrer = new URL(window.location.href).pathname;

0 commit comments

Comments
 (0)