From 492bc2ba633da508614f911ad0844edd9d81d9cc Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 18 Jan 2021 10:45:47 +0100 Subject: [PATCH] ui: tfa/recovery: add print button to key info window Signed-off-by: Thomas Lamprecht --- www/window/AddTfaRecovery.js | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/www/window/AddTfaRecovery.js b/www/window/AddTfaRecovery.js index 8d6ee51a..b63e8576 100644 --- a/www/window/AddTfaRecovery.js +++ b/www/window/AddTfaRecovery.js @@ -27,6 +27,7 @@ Ext.define('PBS.window.AddTfaRecovery', { let values = response.result.data.recovery.join("\n"); Ext.create('PBS.window.TfaRecoveryShow', { autoShow: true, + userid: this.getViewModel().get('userid'), values, }); }, @@ -182,5 +183,42 @@ Ext.define('PBS.window.TfaRecoveryShow', { iconCls: 'fa fa-clipboard', text: gettext('Copy Recovery Keys'), }, + { + handler: function(b) { + let win = this.up('window'); + win.paperkeys(win.values, win.userid); + }, + iconCls: 'fa fa-print', + text: gettext('Print Recovery Keys'), + }, ], + paperkeys: function(keyString, userid) { + let me = this; + + let printFrame = document.createElement("iframe"); + Object.assign(printFrame.style, { + position: "fixed", + right: "0", + bottom: "0", + width: "0", + height: "0", + border: "0", + }); + const host = document.location.host; + const title = document.title; + const html = ` +

Recovery Keys for '${userid}' - ${title} (${host})

+

+${keyString} +

+ `; + + printFrame.src = "data:text/html;base64," + btoa(html); + document.body.appendChild(printFrame); + }, });