123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /**
- * 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 <https://www.gnu.org/licenses/>.
- */
- 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 += `<div style="padding: 20px;">`;
- h += `<div class="generic-close-window-button disable-user-select"> × </div>`;
- h += `<img src="${window.icons['danger.svg']}" class="account-deletion-confirmation-icon">`;
- h += `<p class="account-deletion-confirmation-prompt">${i18n('type_confirm_to_delete_account')}</p>`;
- // error message
- h += `<div class="error-message"></div>`;
- // input field
- h += `<input type="text" class="confirm-temporary-user-deletion" placeholder="${i18n('type_confirm_to_delete_account')}">`;
- h += `<button class="button button-block button-danger proceed-with-user-deletion">${i18n('delete_account')}</button>`;
- h += `<button class="button button-block button-secondary cancel-user-deletion">${i18n('cancel')}</button>`;
- h += `</div>`;
- }
- // otherwise ask for password
- else{
- h += `<div style="padding: 20px;">`;
- h += `<div class="generic-close-window-button disable-user-select"> × </div>`;
- h += `<img src="${window.icons['danger.svg']}" class="account-deletion-confirmation-icon">`;
- h += `<p class="account-deletion-confirmation-prompt">${i18n('enter_password_to_confirm_delete_user')}</p>`;
- // error message
- h += `<div class="error-message"></div>`;
- // input field
- h += `<input type="password" class="confirm-user-deletion-password" placeholder="${i18n('current_password')}">`;
- h += `<button class="button button-block button-danger proceed-with-user-deletion">${i18n('delete_account')}</button>`;
- h += `<button class="button button-block button-secondary cancel-user-deletion">${i18n('cancel')}</button>`;
- h += `</div>`;
- }
- 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;
|