mirror of
https://github.com/HeyPuter/puter.git
synced 2026-09-23 21:56:57 +00:00
Return JSON errors for signup and handle in GUI
This commit is contained in:
@@ -120,7 +120,7 @@ module.exports = eggspress(['/signup'], {
|
||||
await svc_event.emit('puter.signup', event);
|
||||
|
||||
if ( ! event.allow ) {
|
||||
return res.status(400).send(event.error ?? 'You are not allowed to sign up.');
|
||||
return res.status(400).send({ message: event.error ?? 'You are not allowed to sign up.', code: 'not_allowed_to_signup' });
|
||||
}
|
||||
|
||||
// check if user is already logged in
|
||||
@@ -153,19 +153,19 @@ module.exports = eggspress(['/signup'], {
|
||||
const is_user_signup_disabled = await lazy_user_signup();
|
||||
|
||||
if ( is_temp_users_disabled && is_user_signup_disabled ) {
|
||||
return res.status(403).send('User signup and Temporary users are disabled.');
|
||||
return res.status(403).send({ message: 'User signup and Temporary users are disabled.', code: 'user_signup_and_temp_users_disabled' });
|
||||
}
|
||||
|
||||
if ( !req.body.is_temp && is_user_signup_disabled ) {
|
||||
return res.status(403).send('User signup is disabled.');
|
||||
return res.status(403).send({ message: 'User signup is disabled.', code: 'user_signup_disabled' });
|
||||
}
|
||||
|
||||
if ( req.body.is_temp && is_temp_users_disabled ) {
|
||||
return res.status(403).send('Temporary users are disabled.');
|
||||
return res.status(403).send({ message: 'Temporary users are disabled.', code: 'temp_users_disabled' });
|
||||
}
|
||||
|
||||
if ( req.body.is_temp && event.no_temp_user ) {
|
||||
return res.status(403).send('You must login or signup.');
|
||||
return res.status(403).send({ message: 'You must login or signup.', code: 'must_login_or_signup' });
|
||||
}
|
||||
|
||||
// Create temp user data
|
||||
|
||||
+20
-3
@@ -1111,9 +1111,26 @@ window.initgui = async function (options) {
|
||||
document.dispatchEvent(new Event('login', { bubbles: true }));
|
||||
},
|
||||
error: async (err) => {
|
||||
UIAlert({
|
||||
message: html_encode(err.responseText),
|
||||
});
|
||||
let err_obj = null;
|
||||
try {
|
||||
err_obj = JSON.parse(err.responseText);
|
||||
} catch (e) {
|
||||
err_obj = e;
|
||||
}
|
||||
if ( err_obj.code === 'must_login_or_signup' ) {
|
||||
await UIWindowSignup({
|
||||
reload_on_success: false,
|
||||
send_confirmation_code: false,
|
||||
window_options: {
|
||||
has_head: false,
|
||||
cover_page: window.is_embedded || window.is_fullpage_mode,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
UIAlert({
|
||||
message: err_obj.message ?? 'There was an error creating your account. Please try again.',
|
||||
});
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user