]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/UserView.js
user management: separate add/create and edit/remove buttons
[pmg-gui.git] / js / UserView.js
index ce9d566d5b021c0061aafaa571483de6e2bdac3d..13da72c69891e24b486ed8f27e87ac97565d08a3 100644 (file)
@@ -1,11 +1,8 @@
-/*global Proxmox*/
-/*jslint confusion: true*/
-/*renderer is string and function*/
 Ext.define('pmg-users', {
     extend: 'Ext.data.Model',
     fields: [
        'userid', 'firstname', 'lastname', 'email', 'comment',
-       'role', 'keys', 'realm',
+       'role', 'keys', 'realm', 'totp-lock',
        { type: 'boolean', name: 'enable' },
        { type: 'date', dateFormat: 'timestamp', name: 'expire' },
     ],
@@ -87,6 +84,30 @@ Ext.define('PMG.UserView', {
            var view = this.getView();
            view.reload();
        },
+
+       onUnlockTfa: function(btn, event, rec) {
+           let me = this;
+           let view = me.getView();
+           Ext.Msg.confirm(
+               Ext.String.format(gettext('Unlock TFA authentication for {0}'), rec.data.userid),
+               gettext("Locked 2nd factors can happen if the user's password was leaked. Are you sure you want to unlock the user?"),
+               function(btn_response) {
+                   if (btn_response === 'yes') {
+                       Proxmox.Utils.API2Request({
+                           url: `/access/users/${rec.data.userid}/unlock-tfa`,
+                           waitMsgTarget: view,
+                           method: 'PUT',
+                           failure: function(response, options) {
+                               Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                           },
+                           success: function(response, options) {
+                               view.reload();
+                           },
+                       });
+                   }
+               },
+           );
+       },
     },
 
     listeners: {
@@ -100,6 +121,7 @@ Ext.define('PMG.UserView', {
            reference: 'addBtn',
            handler: 'onAdd',
        },
+       '-',
        {
            xtype: 'proxmoxButton',
            text: gettext('Edit'),
@@ -119,6 +141,15 @@ Ext.define('PMG.UserView', {
            disabled: true,
            handler: 'onPassword',
        },
+       '-',
+       {
+           xtype: 'proxmoxButton',
+           text: gettext('Unlock TFA'),
+           handler: 'onUnlockTfa',
+           disabled: true,
+           enableFn: ({ data }) =>
+               data['totp-locked'] || (data['tfa-locked-until'] > (new Date().getTime() / 1000)),
+       },
     ],
 
     columns: [
@@ -163,6 +194,27 @@ Ext.define('PMG.UserView', {
            renderer: 'renderFullName',
            dataIndex: 'firstname',
        },
+       {
+           header: gettext('TFA Lock'),
+           width: 120,
+           sortable: true,
+           dataIndex: 'totp-locked',
+           renderer: function(v, metaData, record) {
+               let locked_until = record.data['tfa-locked-until'];
+               if (locked_until !== undefined) {
+                   let now = new Date().getTime() / 1000;
+                   if (locked_until > now) {
+                       return gettext('Locked');
+                   }
+               }
+
+               if (record.data['totp-locked']) {
+                   return gettext('TOTP Locked');
+               }
+
+               return Proxmox.Utils.noText;
+           },
+       },
        {
            header: gettext('Comment'),
            sortable: false,