From 789c62ef71e176d349801e66cc5362a5fe1850e4 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 2 May 2026 09:55:12 -0700 Subject: [PATCH] Remove RecoveryCodesView and inline in 2FA setup --- .../src/UI/Components/RecoveryCodesView.js | 112 ------------------ src/gui/src/UI/UIWindow2FASetup.js | 32 ++++- 2 files changed, 28 insertions(+), 116 deletions(-) delete mode 100644 src/gui/src/UI/Components/RecoveryCodesView.js diff --git a/src/gui/src/UI/Components/RecoveryCodesView.js b/src/gui/src/UI/Components/RecoveryCodesView.js deleted file mode 100644 index 8cc3d5e7c..000000000 --- a/src/gui/src/UI/Components/RecoveryCodesView.js +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright (C) 2024-present 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 . - */ - -const Component = use('util.Component'); - -export default def(class RecoveryCodesView extends Component { - static ID = 'ui.component.RecoveryCodesView'; - - static PROPERTIES = { - values: { - description: 'The recovery codes to display', - }, - }; - - static CSS = /*css*/` - .recovery-codes { - display: flex; - flex-direction: column; - gap: 10px; - border: 1px solid #ccc; - padding: 20px; - margin: 20px auto; - width: 90%; - max-width: 600px; - background-color: #f9f9f9; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); - } - - .recovery-codes h2 { - text-align: center; - font-size: 18px; - color: #333; - margin-bottom: 15px; - } - - .recovery-codes-list { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); - gap: 10px; /* Adds space between grid items */ - padding: 0; - } - - .recovery-code { - background-color: #fff; - border: 1px solid #ddd; - padding: 10px; - text-align: center; - font-family: 'Courier New', Courier, monospace; - font-size: 12px; - letter-spacing: 1px; - } - - .actions { - flex-direction: row-reverse; - display: flex; - gap: 10px; - } - `; - - create_template ({ template }) { - $(template).html(` - -
-
-
-
- - -
-
- `); - } - - on_ready ({ listen }) { - listen('values', values => { - for ( const value of values ) { - $(this.dom_).find('.recovery-codes-list').append(` -
${html_encode(value)}
- `); - } - }); - - $(this.dom_).find('[data-action="copy"]').on('click', () => { - const codes = this.get('values').join('\n'); - navigator.clipboard.writeText(codes); - }); - - $(this.dom_).find('[data-action="print"]').on('click', () => { - const target = $(this.dom_).find('.recovery-codes-list')[0]; - const print_frame = $(this.dom_).find('iframe[name="print_frame"]')[0]; - print_frame.contentWindow.document.body.innerHTML = target.outerHTML; - print_frame.contentWindow.window.focus(); - print_frame.contentWindow.window.print(); - }); - } -}); diff --git a/src/gui/src/UI/UIWindow2FASetup.js b/src/gui/src/UI/UIWindow2FASetup.js index d43c700fd..d444d4d37 100644 --- a/src/gui/src/UI/UIWindow2FASetup.js +++ b/src/gui/src/UI/UIWindow2FASetup.js @@ -29,7 +29,7 @@ - cancel action Screen 2: Recovery codes - Components: Flexer < RecoveryCodesView, ActionsView > + Components: Flexer < ActionsView > Logic: - done action - cancel action @@ -43,7 +43,6 @@ import Button from './Components/Button.js'; import CodeEntryView from './Components/CodeEntryView.js'; import Flexer from './Components/Flexer.js'; import UIQRCode from './UIQRCode.js'; -import RecoveryCodesView from './Components/RecoveryCodesView.js'; import StepView from './Components/StepView.js'; import JustHTML from './Components/JustHTML.js'; import UIComponentWindow from './UIComponentWindow.js'; @@ -168,8 +167,33 @@ const UIWindow2FASetup = async function UIWindow2FASetup () { new JustHTML({ html: `
${i18n('setup2fa_4_instructions', [], false)}
`, }), - new RecoveryCodesView({ - values: data.codes, + new JustHTML({ + _ref: me => { + me.dom_.addEventListener('click', (e) => { + const action = e.target.closest('[data-action]')?.dataset.action; + if ( action === 'copy' ) { + navigator.clipboard.writeText(data.codes.join('\n')); + } else if ( action === 'print' ) { + const target = me.dom_.querySelector('.recovery-codes-list'); + const print_frame = me.dom_.querySelector('iframe[name="print_frame"]'); + print_frame.contentWindow.document.body.innerHTML = target.outerHTML; + print_frame.contentWindow.window.focus(); + print_frame.contentWindow.window.print(); + } + }); + }, + html: ` + +
+
+ ${data.codes.map(code => `
${html_encode(code)}
`).join('')} +
+
+ + +
+
+ `, }), new JustHTML({ html: `