]> git.proxmox.com Git - proxmox-backup.git/blob - www/window/AddTfaRecovery.js
ui: window/AddTfaRecovery: fix style of TfaRecoveryShow window
[proxmox-backup.git] / www / window / AddTfaRecovery.js
1 Ext.define('PBS.window.AddTfaRecovery', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pbsAddTfaRecovery',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 onlineHelp: 'user_mgmt',
7 isCreate: true,
8 isAdd: true,
9 subject: gettext('TFA recovery keys'),
10 width: 512,
11 method: 'POST',
12
13 fixedUser: false,
14
15 url: '/api2/extjs/access/tfa',
16 submitUrl: function(url, values) {
17 let userid = values.userid;
18 delete values.userid;
19 return `${url}/${userid}`;
20 },
21
22 apiCallDone: function(success, response) {
23 if (!success) {
24 return;
25 }
26
27 let values = response.result.data.recovery.join("\n");
28 Ext.create('PBS.window.TfaRecoveryShow', {
29 autoShow: true,
30 values,
31 });
32 },
33
34 viewModel: {
35 data: {
36 has_entry: false,
37 },
38 },
39
40 controller: {
41 xclass: 'Ext.app.ViewController',
42 hasEntry: async function(userid) {
43 let me = this;
44 let view = me.getView();
45
46 try {
47 await PBS.Async.api2({
48 url: `${view.url}/${userid}/recovery`,
49 method: 'GET',
50 });
51 return true;
52 } catch (_ex) {
53 return false;
54 }
55 },
56
57 init: function(view) {
58 this.onUseridChange(null, Proxmox.UserName);
59 },
60
61 onUseridChange: async function(field, userid) {
62 let me = this;
63
64 me.userid = userid;
65
66 let has_entry = await me.hasEntry(userid);
67 me.getViewModel().set('has_entry', has_entry);
68 },
69 },
70
71 items: [
72 {
73 xtype: 'pmxDisplayEditField',
74 name: 'userid',
75 cbind: {
76 editable: (get) => !get('fixedUser'),
77 },
78 fieldLabel: gettext('User'),
79 editConfig: {
80 xtype: 'pbsUserSelector',
81 allowBlank: false,
82 validator: function(_value) {
83 return !this.up('window').getViewModel().get('has_entry');
84 },
85 },
86 renderer: Ext.String.htmlEncode,
87 value: Proxmox.UserName,
88 listeners: {
89 change: 'onUseridChange',
90 },
91 },
92 {
93 xtype: 'hiddenfield',
94 name: 'type',
95 value: 'recovery',
96 },
97 {
98 xtype: 'displayfield',
99 bind: {
100 hidden: '{!has_entry}',
101 },
102 hidden: true,
103 userCls: 'pmx-hint',
104 value: gettext('User already has recovery keys.'),
105 },
106 {
107 xtype: 'textfield',
108 inputType: 'password',
109 fieldLabel: gettext('Password'),
110 minLength: 5,
111 reference: 'password',
112 name: 'password',
113 allowBlank: false,
114 validateBlank: true,
115 hidden: Proxmox.UserName === 'root@pam',
116 disabled: Proxmox.UserName === 'root@pam',
117 emptyText: gettext('verify current password'),
118 },
119 ],
120 });
121
122 Ext.define('PBS.window.TfaRecoveryShow', {
123 extend: 'Ext.window.Window',
124 alias: ['widget.pbsTfaRecoveryShow'],
125 mixins: ['Proxmox.Mixin.CBind'],
126
127 width: 600,
128 modal: true,
129 resizable: false,
130 title: gettext('Recovery Keys'),
131
132 items: [
133 {
134 xtype: 'form',
135 layout: 'anchor',
136 bodyPadding: 10,
137 border: false,
138 fieldDefaults: {
139 anchor: '100%',
140 },
141 items: [
142 {
143 xtype: 'textarea',
144 editable: false,
145 inputId: 'token-secret-value',
146 cbind: {
147 value: '{values}',
148 },
149 fieldStyle: {
150 'fontFamily': 'monospace',
151 },
152 height: '160px',
153 },
154 {
155 xtype: 'displayfield',
156 border: false,
157 padding: '5 0 0 0',
158 userCls: 'pmx-hint',
159 value: gettext('Please record recovery keys - they will only be displayed now'),
160 },
161 ],
162 },
163 ],
164 buttons: [
165 {
166 handler: function(b) {
167 document.getElementById('token-secret-value').select();
168 document.execCommand("copy");
169 },
170 text: gettext('Copy Secret Value'),
171 },
172 ],
173 });