]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/panel/TfaView.js
a0cb04a7dc7c149b7459962facabf842e9faaf70
1 Ext
.define('pmx-tfa-users', {
2 extend
: 'Ext.data.Model',
7 url
: '/api2/json/access/tfa',
11 Ext
.define('pmx-tfa-entry', {
12 extend
: 'Ext.data.Model',
13 fields
: ['fullid', 'userid', 'type', 'description', 'created', 'enable'],
18 Ext
.define('Proxmox.panel.TfaView', {
19 extend
: 'Ext.grid.GridPanel',
20 alias
: 'widget.pmxTfaView',
22 title
: gettext('Second Factors'),
25 issuerName
: 'Proxmox',
30 autoDestroyRstore
: true,
31 model
: 'pmx-tfa-entry',
35 storeid
: 'pmx-tfa-entry',
36 model
: 'pmx-tfa-entry',
41 xclass
: 'Ext.app.ViewController',
43 init: function(view
) {
45 view
.tfaStore
= Ext
.create('Proxmox.data.UpdateStore', {
48 storeid
: 'pmx-tfa-users',
49 model
: 'pmx-tfa-users',
51 view
.tfaStore
.on('load', this.onLoad
, this);
52 view
.on('destroy', view
.tfaStore
.stopUpdate
);
53 Proxmox
.Utils
.monStoreErrors(view
, view
.tfaStore
);
56 reload: function() { this.getView().tfaStore
.load(); },
58 onLoad: function(store
, data
, success
) {
62 Ext
.Array
.each(data
, user
=> {
63 Ext
.Array
.each(user
.data
.entries
, entry
=> {
65 fullid
: `${user.id}/${entry.id}`,
68 description
: entry
.description
,
69 created
: entry
.created
,
75 let rstore
= this.getView().store
.rstore
;
76 rstore
.loadData(records
);
77 rstore
.fireEvent('load', rstore
, records
, true);
83 Ext
.create('Proxmox.window.AddTotp', {
85 issuerName
: me
.getView().issuerName
,
94 addWebauthn: function() {
97 Ext
.create('Proxmox.window.AddWebauthn', {
100 destroy: function() {
107 addRecovery
: async
function() {
110 Ext
.create('Proxmox.window.AddTfaRecovery', {
112 destroy: function() {
119 editItem: function() {
121 let view
= me
.getView();
122 let selection
= view
.getSelection();
123 if (selection
.length
!== 1 || selection
[0].id
.endsWith("/recovery")) {
127 Ext
.create('Proxmox.window.TfaEdit', {
128 'tfa-id': selection
[0].data
.fullid
,
130 destroy: function() {
137 renderUser
: fullid
=> fullid
.split('/')[0],
139 renderEnabled
: enabled
=> {
140 if (enabled
=== undefined) {
141 return Proxmox
.Utils
.yesText
;
143 return Proxmox
.Utils
.format_boolean(enabled
);
147 onRemoveButton: function(btn
, event
, record
) {
150 Ext
.create('Proxmox.tfa.confirmRemove', {
152 callback
: password
=> me
.removeItem(password
, record
),
157 removeItem
: async
function(password
, record
) {
160 if (password
!== null) {
161 password
= '?password=' + encodeURIComponent(password
);
167 me
.getView().mask(gettext('Please wait...'), 'x-mask-loading');
168 await Proxmox
.Async
.api2({
169 url
: `/api2/extjs/access/tfa/${record.id}${password}`,
174 Ext
.Msg
.alert(gettext('Error'), response
.result
.message
);
176 me
.getView().unmask();
186 itemdblclick
: 'editItem',
191 header
: gettext('User'),
195 renderer
: 'renderUser',
198 header
: gettext('Enabled'),
202 renderer
: 'renderEnabled',
205 header
: gettext('TFA Type'),
211 header
: gettext('Created'),
214 dataIndex
: 'created',
215 renderer
: Proxmox
.Utils
.render_timestamp
,
218 header
: gettext('Description'),
221 dataIndex
: 'description',
222 renderer
: Ext
.String
.htmlEncode
,
229 text
: gettext('Add'),
234 text
: gettext('TOTP'),
236 iconCls
: 'fa fa-fw fa-clock-o',
240 text
: gettext('Webauthn'),
242 iconCls
: 'fa fa-fw fa-shield',
243 handler
: 'addWebauthn',
246 text
: gettext('Recovery Keys'),
248 iconCls
: 'fa fa-fw fa-file-text-o',
249 handler
: 'addRecovery',
256 xtype
: 'proxmoxButton',
257 text
: gettext('Edit'),
259 enableFn
: rec
=> !rec
.id
.endsWith("/recovery"),
263 xtype
: 'proxmoxButton',
265 text
: gettext('Remove'),
266 getRecordName
: rec
=> rec
.data
.description
,
267 handler
: 'onRemoveButton',