diff --git a/src/UI/Settings/UITabAbout.js b/src/UI/Settings/UITabAbout.js new file mode 100644 index 00000000..88003ebf --- /dev/null +++ b/src/UI/Settings/UITabAbout.js @@ -0,0 +1,97 @@ +/** + * Copyright (C) 2024 Puter Technologies Inc. + * + * This file is part of Puter. + * + * Puter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +// About +function UITabAbout(){ + let h = ``; + + h += `
`; + h += `
` + h += `
+ +

Puter is a privacy-first personal cloud to keep all your files, apps, and games in one + secure place, accessible from anywhere at any time.

+ + +
+
+ + +
+

Open Source Software and Content

+
+ +
+
+
+ `; + h += `
`; + h += `
`; + + return h; +} +export default UITabAbout; \ No newline at end of file diff --git a/src/UI/Settings/UIWindowConfirmUserDeletion.js b/src/UI/Settings/UIWindowConfirmUserDeletion.js new file mode 100644 index 00000000..f300e7b4 --- /dev/null +++ b/src/UI/Settings/UIWindowConfirmUserDeletion.js @@ -0,0 +1,83 @@ +/** + * Copyright (C) 2024 Puter Technologies Inc. + * + * This file is part of Puter. + * + * Puter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import UIWindow from '../UIWindow.js' +import UIWindowFinalizeUserDeletion from './UIWindowFinalizeUserDeletion.js' + +async function UIWindowConfirmUserDeletion(options){ + return new Promise(async (resolve) => { + options = options ?? {}; + + let h = ''; + h += `
`; + h += `
×
`; + h += ``; + h += `

${i18n('confirm_delete_user')}

`; + h += ``; + h += ``; + h += `
`; + + const el_window = await UIWindow({ + title: i18n('confirm_delete_user_title'), + icon: null, + uid: null, + is_dir: false, + body_content: h, + has_head: false, + selectable_body: false, + draggable_body: false, + allow_context_menu: false, + is_draggable: true, + is_resizable: false, + is_droppable: false, + init_center: true, + allow_native_ctxmenu: true, + allow_user_select: true, + backdrop: true, + onAppend: function(el_window){ + }, + width: 500, + dominant: true, + window_css: { + height: 'initial', + padding: '0', + border: 'none', + boxShadow: '0 0 10px rgba(0,0,0,.2)', + borderRadius: '5px', + backgroundColor: 'white', + color: 'black', + }, + }); + + $(el_window).find('.generic-close-window-button').on('click', function(){ + $(el_window).close(); + }); + + $(el_window).find('.cancel-user-deletion').on('click', function(){ + $(el_window).close(); + }); + + $(el_window).find('.proceed-with-user-deletion').on('click', function(){ + UIWindowFinalizeUserDeletion(); + $(el_window).close(); + }); + }) +} + +export default UIWindowConfirmUserDeletion; \ No newline at end of file diff --git a/src/UI/Settings/UIWindowFinalizeUserDeletion.js b/src/UI/Settings/UIWindowFinalizeUserDeletion.js new file mode 100644 index 00000000..d30d33f3 --- /dev/null +++ b/src/UI/Settings/UIWindowFinalizeUserDeletion.js @@ -0,0 +1,152 @@ +/** + * Copyright (C) 2024 Puter Technologies Inc. + * + * This file is part of Puter. + * + * Puter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import UIWindow from '../UIWindow.js' + +async function UIWindowFinalizeUserDeletion(options){ + return new Promise(async (resolve) => { + options = options ?? {}; + + let h = ''; + + // if user is temporary, ask them to type in 'confirm' to delete their account + if(user.is_temp){ + h += `
`; + h += `
×
`; + h += ``; + h += `

${i18n('type_confirm_to_delete_account')}

`; + // error message + h += ``; + // input field + h += ``; + h += ``; + h += ``; + h += `
`; + } + // otherwise ask for password + else{ + h += `
`; + h += `
×
`; + h += ``; + h += `

${i18n('enter_password_to_confirm_delete_user')}

`; + // error message + h += ``; + // input field + h += ``; + h += ``; + h += ``; + h += `
`; + } + + const el_window = await UIWindow({ + title: i18n('confirm_delete_user_title'), + icon: null, + uid: null, + is_dir: false, + body_content: h, + has_head: false, + selectable_body: false, + draggable_body: false, + allow_context_menu: false, + is_draggable: true, + is_resizable: false, + is_droppable: false, + init_center: true, + allow_native_ctxmenu: true, + allow_user_select: true, + backdrop: true, + onAppend: function(el_window){ + }, + width: 500, + dominant: false, + window_css: { + height: 'initial', + padding: '0', + border: 'none', + boxShadow: '0 0 10px rgba(0,0,0,.2)', + } + }); + + $(el_window).find('.generic-close-window-button').on('click', function(){ + $(el_window).close(); + }); + + $(el_window).find('.cancel-user-deletion').on('click', function(){ + $(el_window).close(); + }); + + $(el_window).find('.proceed-with-user-deletion').on('click', function(){ + $(el_window).find('.error-message').hide(); + // if user is temporary, check if they typed 'confirm' + if(user.is_temp){ + if($(el_window).find('.confirm-temporary-user-deletion').val() !== 'confirm'){ + $(el_window).find('.error-message').html(i18n('type_confirm_to_delete_account'), false); + $(el_window).find('.error-message').show(); + return; + } + } + // otherwise, check if password is correct + else{ + if($(el_window).find('.confirm-user-deletion-password').val() === ''){ + $(el_window).find('.error-message').html(i18n('all_fields_required'), false); + $(el_window).find('.error-message').show(); + return; + } + } + + // delete user + $.ajax({ + url: api_origin + "/delete-own-user", + type: 'POST', + async: true, + contentType: "application/json", + headers: { + "Authorization": "Bearer " + auth_token + }, + data: JSON.stringify({ + password: $(el_window).find('.confirm-user-deletion-password').val(), + }), + statusCode: { + 401: function () { + logout(); + }, + 400: function(){ + $(el_window).find('.error-message').html(i18n('incorrect_password')); + $(el_window).find('.error-message').show(); + } + }, + success: function(data){ + if(data.success){ + // mark user as deleted + window.user.deleted = true; + // log user out + logout(); + } + else{ + $(el_window).find('.error-message').html(data.error); + $(el_window).find('.error-message').show(); + + } + } + }); + }); + }) +} + +export default UIWindowFinalizeUserDeletion; \ No newline at end of file diff --git a/src/UI/Settings/UIWindowSettings.js b/src/UI/Settings/UIWindowSettings.js index ae53dbb0..c365af02 100644 --- a/src/UI/Settings/UIWindowSettings.js +++ b/src/UI/Settings/UIWindowSettings.js @@ -23,7 +23,8 @@ import UIWindowChangePassword from '../UIWindowChangePassword.js' // import UIWindowDeleteAccount from './UIWindowDeleteAccount.js' import UIWindowChangeUsername from '../UIWindowChangeUsername.js' import changeLanguage from "../../i18n/i18nchangeLanguage.js" - +import UIWindowConfirmUserDeletion from './UIWindowConfirmUserDeletion.js'; +import UITabAbout from './UITabAbout.js'; async function UIWindowSettings(options){ return new Promise(async (resolve) => { @@ -43,76 +44,9 @@ async function UIWindowSettings(options){ // content h += `
`; + // About - h += `
`; - h += `
` - h += `
- -

Puter is a privacy-first personal cloud to keep all your files, apps, and games in one - secure place, accessible from anywhere at any time.

- - -
-
- - -
-

Open Source Software and Content

-
- -
-
-
- `; - h += `
`; - h += `
`; + h += UITabAbout(); // Usage h += `
`; @@ -142,16 +76,6 @@ async function UIWindowSettings(options){ h += `
`; h += `
`; - // change email button - if(user.email){ - h += `
`; - h += `${user.email}`; - h += `
`; - h += ``; - h += `
`; - h += `
`; - } - // change username button h += `
`; h += `
`; @@ -163,11 +87,24 @@ async function UIWindowSettings(options){ h += `
` h += `
`; - // delete account button + // change email button + if(user.email){ + h += `
`; + h += `
`; + h += `Email`; + h += `${user.email}`; + h += `
`; + h += `
`; + h += ``; + h += `
`; + h += `
`; + } + + // 'Delete Account' button h += `
`; - h += `Delete Account`; + h += `${i18n("delete_account")}`; h += `
`; - h += ``; + h += ``; h += `
`; h += `
`; @@ -349,7 +286,7 @@ async function UIWindowSettings(options){ }) $(el_window).find('.delete-account').on('click', function (e) { - UIWindowDeleteAccount(); + UIWindowConfirmUserDeletion(); }) $(el_window).find('.change-username').on('click', function (e) { diff --git a/src/css/style.css b/src/css/style.css index 0950031d..94b22e28 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -3549,4 +3549,15 @@ label { border-color: #f0080866; background: #ffecec; color: rgb(215 2 2); +} +.error-message{ + border-color: #f0080866; + background: #ffecec; + color: rgb(215 2 2); + font-size: 14px; + margin-top: 10px; + margin-bottom: 10px; + padding: 10px; + border-radius: 4px; + border: 1px solid #f0080866; } \ No newline at end of file diff --git a/src/i18n/translations/en.js b/src/i18n/translations/en.js index ffb64747..4346c052 100644 --- a/src/i18n/translations/en.js +++ b/src/i18n/translations/en.js @@ -46,6 +46,7 @@ const en = { confirm_delete_single_item: 'Do you want to permanently delete this item?', confirm_open_apps_log_out: 'You have open apps. Are you sure you want to log out?', confirm_new_password: "Confirm New Password", + confirm_delete_user: "Are you sure you want to delete your account? All your files and data will be permanently deleted. This action cannot be undone.", contact_us: "Contact Us", contain: 'Contain', continue: "Continue", @@ -60,6 +61,7 @@ const en = { cut: 'Cut', date_modified: 'Date modified', delete: 'Delete', + delete_account: "Delete Account", delete_permanently: "Delete Permanently", deploy_as_app: 'Deploy as app', descending: 'Descending', @@ -74,6 +76,7 @@ const en = { empty_trash: 'Empty Trash', empty_trash_confirmation: `Are you sure you want to permanently delete the items in Trash?`, emptying_trash: 'Emptying Trash…', + enter_password_to_confirm_delete_user: "Enter your password to confirm account deletion", feedback: "Feedback", feedback_c2a: "Please use the form below to send us your feedback, comments, and bug reports.", feedback_sent_confirmation: "Thank you for contacting us. If you have an email associated with your account, you will hear back from us as soon as possible.", @@ -124,14 +127,15 @@ const en = { paste_into_folder: "Paste Into Folder", pick_name_for_website: "Pick a name for your website:", picture: "Picture", + plural_suffix: 's', powered_by_puter_js: `Powered by Puter.js`, preparing: "Preparing...", preparing_for_upload: "Preparing for upload...", proceed_to_login: 'Proceed to login', + proceed_with_account_deletion: "Proceed with Account Deletion", properties: "Properties", publish: "Publish", publish_as_website: 'Publish as website', - plural_suffix: 's', recent: "Recent", recover_password: "Recover Password", refer_friends_c2a: "Get 1 GB for every friend who creates and confirms an account on Puter. Your friend will get 1 GB too!", @@ -174,6 +178,7 @@ const en = { tos_fineprint: `By clicking 'Create Free Account' you agree to Puter's Terms of Service and Privacy Policy.`, trash: 'Trash', type: 'Type', + type_confirm_to_delete_account: "Type 'confirm' to delete your account.", undo: 'Undo', unzip: "Unzip", upload: 'Upload', diff --git a/src/icons/danger.svg b/src/icons/danger.svg new file mode 100644 index 00000000..ce0d5592 --- /dev/null +++ b/src/icons/danger.svg @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/initgui.js b/src/initgui.js index b59307b7..280215b1 100644 --- a/src/initgui.js +++ b/src/initgui.js @@ -1870,7 +1870,7 @@ window.initgui = async function(){ */ $(document).on("logout", async function(event) { // is temp user? - if(window.user && window.user.is_temp){ + if(window.user && window.user.is_temp && !window.user.deleted){ const alert_resp = await UIAlert({ message: `Save account before logging out!

You are using a temporary account and logging out will erase all your data.

`, buttons:[