]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/AddTfaRecovery.js
1 Ext
.define('Proxmox.window.AddTfaRecovery', {
2 extend
: 'Proxmox.window.Edit',
3 alias
: 'widget.pmxAddTfaRecovery',
4 mixins
: ['Proxmox.Mixin.CBind'],
6 onlineHelp
: 'user_mgmt',
9 subject
: gettext('TFA recovery keys'),
15 url
: '/api2/extjs/access/tfa',
16 submitUrl: function(url
, values
) {
17 let userid
= values
.userid
;
19 return `${url}/${userid}`;
22 apiCallDone: function(success
, response
) {
31 .map((v
, i
) => `${i}: ${v}`)
33 Ext
.create('Proxmox.window.TfaRecoveryShow', {
35 userid
: this.getViewModel().get('userid'),
48 xclass
: 'Ext.app.ViewController',
49 hasEntry
: async
function(userid
) {
51 let view
= me
.getView();
54 await Proxmox
.Async
.api2({
55 url
: `${view.url}/${userid}/recovery`,
64 init: function(view
) {
65 this.onUseridChange(null, Proxmox
.UserName
);
68 onUseridChange
: async
function(field
, userid
) {
70 let vm
= me
.getViewModel();
73 vm
.set('userid', userid
);
75 let has_entry
= await me
.hasEntry(userid
);
76 vm
.set('has_entry', has_entry
);
82 xtype
: 'pmxDisplayEditField',
85 editable
: (get) => !get('fixedUser'),
86 value
: () => Proxmox
.UserName
,
88 fieldLabel
: gettext('User'),
90 xtype
: 'pmxUserSelector',
92 validator: function(_value
) {
93 return !this.up('window').getViewModel().get('has_entry');
96 renderer
: Ext
.String
.htmlEncode
,
98 change
: 'onUseridChange',
102 xtype
: 'hiddenfield',
107 xtype
: 'displayfield',
109 hidden
: '{!has_entry}',
113 value
: gettext('User already has recovery keys.'),
118 reference
: 'password',
119 fieldLabel
: gettext('Verify Password'),
120 inputType
: 'password',
125 hidden
: () => Proxmox
.UserName
=== 'root@pam',
126 disabled
: () => Proxmox
.UserName
=== 'root@pam',
128 Ext
.String
.format(gettext("Confirm your ({0}) password"), Proxmox
.UserName
),
134 Ext
.define('Proxmox.window.TfaRecoveryShow', {
135 extend
: 'Ext.window.Window',
136 alias
: ['widget.pmxTfaRecoveryShow'],
137 mixins
: ['Proxmox.Mixin.CBind'],
142 title
: gettext('Recovery Keys'),
158 inputId
: 'token-secret-value',
163 'fontFamily': 'monospace',
168 xtype
: 'displayfield',
172 value
: gettext('Please record recovery keys - they will only be displayed now'),
179 handler: function(b
) {
180 document
.getElementById('token-secret-value').select();
181 document
.execCommand("copy");
183 iconCls
: 'fa fa-clipboard',
184 text
: gettext('Copy Recovery Keys'),
187 handler: function(b
) {
188 let win
= this.up('window');
189 win
.paperkeys(win
.values
, win
.userid
);
191 iconCls
: 'fa fa-print',
192 text
: gettext('Print Recovery Keys'),
195 paperkeys: function(keyString
, userid
) {
198 let printFrame
= document
.createElement("iframe");
199 Object
.assign(printFrame
.style
, {
207 const host
= document
.location
.host
;
208 const title
= document
.title
;
209 const html
= `<html><head><script>
210 window.addEventListener('DOMContentLoaded', (ev) => window.print());
211 </script><style>@media print and (max-height: 150mm) {
212 h4, p { margin: 0; font-size: 1em; }
213 }</style></head><body style="padding: 5px;">
214 <h4>Recovery Keys for '${userid}' - ${title} (${host})</h4>
215 <p style="font-size:1.5em;line-height:1.5em;font-family:monospace;
216 white-space:pre-wrap;overflow-wrap:break-word;">
221 printFrame
.src
= "data:text/html;base64," + btoa(html
);
222 document
.body
.appendChild(printFrame
);