From bfaaa914f1dfd4a29a5a025b104c369b544dfd8d Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sun, 14 Apr 2024 17:30:22 -0700 Subject: [PATCH] wip --- src/UI/Settings/UIWindowChangeEmail.js | 126 +++++++++++++++++++++++++ src/UI/Settings/UIWindowSettings.js | 18 ++-- src/i18n/translations/en.js | 1 + src/index.js | 4 +- src/initgui.js | 1 - 5 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 src/UI/Settings/UIWindowChangeEmail.js diff --git a/src/UI/Settings/UIWindowChangeEmail.js b/src/UI/Settings/UIWindowChangeEmail.js new file mode 100644 index 00000000..8ddc7c5f --- /dev/null +++ b/src/UI/Settings/UIWindowChangeEmail.js @@ -0,0 +1,126 @@ +/** + * 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 UIWindowChangeEmail(){ + const internal_id = window.uuidv4(); + let h = ''; + h += `
`; + // error msg + h += `
`; + // success msg + h += `
`; + // new email + h += `
`; + h += ``; + h += ``; + h += `
`; + + // Change Email + h += ``; + h += `
`; + + const el_window = await UIWindow({ + title: i18n('change_email'), + app: 'change-email', + single_instance: true, + icon: null, + uid: null, + is_dir: false, + body_content: h, + has_head: true, + selectable_body: false, + draggable_body: false, + allow_context_menu: false, + is_resizable: false, + is_droppable: false, + init_center: true, + allow_native_ctxmenu: false, + allow_user_select: false, + width: 350, + height: 'auto', + dominant: true, + show_in_taskbar: false, + onAppend: function(this_window){ + $(this_window).find(`.new-email`).get(0)?.focus({preventScroll:true}); + }, + window_class: 'window-publishWebsite', + body_css: { + width: 'initial', + height: '100%', + 'background-color': 'rgb(245 247 249)', + 'backdrop-filter': 'blur(3px)', + } + }) + + $(el_window).find('.change-email-btn').on('click', function(e){ + // hide previous error/success msg + $(el_window).find('.form-success-msg, .form-success-msg').hide(); + + const new_email = $(el_window).find('.new-email').val(); + + if(!new_email){ + $(el_window).find('.form-error-msg').html(i18n('all_fields_required')); + $(el_window).find('.form-error-msg').fadeIn(); + return; + } + + $(el_window).find('.form-error-msg').hide(); + + // disable button + $(el_window).find('.change-email-btn').addClass('disabled'); + // disable input + $(el_window).find('.new-email').attr('disabled', true); + + $.ajax({ + url: api_origin + "/change_email/start", + type: 'POST', + async: true, + headers: { + "Authorization": "Bearer "+auth_token + }, + contentType: "application/json", + data: JSON.stringify({ + new_email: new_email, + }), + success: function (data){ + $(el_window).find('.form-success-msg').html(i18n('username_changed')); + $(el_window).find('.form-success-msg').fadeIn(); + $(el_window).find('input').val(''); + // update email + window.user.email = new_email; + // enable button + $(el_window).find('.change-email-btn').removeClass('disabled'); + // enable input + $(el_window).find('.new-email').attr('disabled', false); + }, + error: function (err){ + $(el_window).find('.form-error-msg').html(html_encode(err.responseJSON?.message)); + $(el_window).find('.form-error-msg').fadeIn(); + // enable button + $(el_window).find('.change-email-btn').removeClass('disabled'); + // enable input + $(el_window).find('.new-email').attr('disabled', false); + } + }); + }) +} + +export default UIWindowChangeEmail \ No newline at end of file diff --git a/src/UI/Settings/UIWindowSettings.js b/src/UI/Settings/UIWindowSettings.js index d7ecab01..40a4f89b 100644 --- a/src/UI/Settings/UIWindowSettings.js +++ b/src/UI/Settings/UIWindowSettings.js @@ -19,7 +19,7 @@ import UIWindow from '../UIWindow.js' import UIWindowChangePassword from '../UIWindowChangePassword.js' -// import UIWindowChangeEmail from './UIWindowChangeEmail.js' +import UIWindowChangeEmail from './UIWindowChangeEmail.js' // import UIWindowDeleteAccount from './UIWindowDeleteAccount.js' import UIWindowChangeUsername from '../UIWindowChangeUsername.js' import changeLanguage from "../../i18n/i18nChangeLanguage.js" @@ -106,14 +106,6 @@ async function UIWindowSettings(options){ h += ``; } - // 'Delete Account' button - h += `
`; - h += `${i18n("delete_account")}`; - h += `
`; - h += ``; - h += `
`; - h += `
`; - // session manager h += `
`; h += `${i18n('sessions')}`; @@ -122,6 +114,14 @@ async function UIWindowSettings(options){ h += `
`; h += ``; + // 'Delete Account' button + h += `
`; + h += `${i18n("delete_account")}`; + h += `
`; + h += ``; + h += `
`; + h += `
`; + h += ``; // Personalization diff --git a/src/i18n/translations/en.js b/src/i18n/translations/en.js index 8e2c5c3a..d3198eae 100644 --- a/src/i18n/translations/en.js +++ b/src/i18n/translations/en.js @@ -125,6 +125,7 @@ const en = { name_must_be_string: "Name can only be a string.", name_too_long: `Name can not be longer than %% characters.`, new: 'New', + new_email: 'New Email', new_folder: 'New folder', new_password: "New Password", new_username: "New Username", diff --git a/src/index.js b/src/index.js index 6bb56651..7e7b962c 100644 --- a/src/index.js +++ b/src/index.js @@ -46,10 +46,10 @@ window.puter_gui_enabled = true; window.gui = async function(options){ options = options ?? {}; // app_origin is deprecated, use gui_origin instead - window.gui_origin = options.gui_origin ?? options.app_origin ?? `https://puter.com`; + window.gui_origin = `https://puter.com`; window.app_domain = options.app_domain ?? new URL(window.gui_origin).hostname; window.hosting_domain = options.hosting_domain ?? 'puter.site'; - window.api_origin = options.api_origin ?? "https://api.puter.com"; + window.api_origin = "https://api.puter.com"; window.max_item_name_length = options.max_item_name_length ?? 500; window.require_email_verification_to_publish_website = options.require_email_verification_to_publish_website ?? true; diff --git a/src/initgui.js b/src/initgui.js index 5c156975..9bf42784 100644 --- a/src/initgui.js +++ b/src/initgui.js @@ -35,7 +35,6 @@ import update_title_based_on_uploads from './helpers/update_title_based_on_uploa import PuterDialog from './UI/PuterDialog.js'; import determine_active_container_parent from './helpers/determine_active_container_parent.js'; import { ThemeService } from './services/ThemeService.js'; -import UIWindowThemeDialog from './UI/UIWindowThemeDialog.js'; import { BroadcastService } from './services/BroadcastService.js'; const launch_services = async function () {