/** * 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 += ``; // error message h += `
`; // input field h += ``; h += ``; h += ``; h += `
`; } // otherwise ask for password else{ h += `
`; h += `
×
`; h += ``; h += ``; // 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;