]> git.proxmox.com Git - pmg-gui.git/commitdiff
add TFA components
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 26 Nov 2021 13:55:11 +0000 (14:55 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 28 Nov 2021 19:17:47 +0000 (20:17 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
js/LoginView.js
js/Makefile
js/UserManagement.js
js/UserSelector.js [new file with mode: 0644]
pmg-index.html.tt

index 7ad695c1e353fadce525349f74b88d4dd682e316..63f4099d413c22820e1ae299809941af2eba7bdd 100644 (file)
@@ -44,7 +44,7 @@ Ext.define('PMG.LoginView', {
            me.submitForm();
        },
 
-       submitForm: function() {
+       submitForm: async function() {
            let me = this;
            let view = me.getView();
            let loginForm = me.lookupReference('loginForm');
@@ -67,23 +67,54 @@ Ext.define('PMG.LoginView', {
                    sp.set(saveunField.getStateId(), saveunField.getValue());
                }
 
-               loginForm.submit({
-                   success: function(form, action) {
-                       // save login data and create cookie
-                       PMG.Utils.updateLoginData(action.result.data);
-                       PMG.app.changeView(view.targetview);
-                   },
-                   failure: function(form, action) {
-                       loginForm.unmask();
-                       Ext.MessageBox.alert(
-                           gettext('Error'),
-                           gettext('Login failed. Please try again'),
-                       );
-                   },
-               });
+               let creds = loginForm.getValues();
+
+               try {
+                   let resp = await Proxmox.Async.api2({
+                       url: '/api2/extjs/access/ticket',
+                       params: creds,
+                       method: 'POST',
+                   });
+
+                   let data = resp.result.data;
+                   if (data.ticket.startsWith('PMG:!tfa!')) {
+                       data = await me.performTFAChallenge(data);
+                   }
+                   PMG.Utils.updateLoginData(data);
+                   PMG.app.changeView(view.targetview);
+               } catch (error) {
+                   Proxmox.Utils.authClear();
+                   loginForm.unmask();
+                   Ext.MessageBox.alert(
+                       gettext('Error'),
+                       gettext('Login failed. Please try again'),
+                   );
+               }
            }
        },
 
+       performTFAChallenge: async function(data) {
+           let me = this;
+
+           let userid = data.username;
+           let ticket = data.ticket;
+           let challenge = JSON.parse(decodeURIComponent(
+               ticket.split(':')[1].slice("!tfa!".length),
+           ));
+
+           let resp = await new Promise((resolve, reject) => {
+               Ext.create('Proxmox.window.TfaLoginWindow', {
+                   userid,
+                   ticket,
+                   challenge,
+                   onResolve: value => resolve(value),
+                   onReject: reject,
+               }).show();
+           });
+
+           return resp.result.data;
+       },
+
        openQuarantineLinkWindow: function() {
            let me = this;
            me.lookup('loginwindow').setVisible(false);
index 672f61e109ff3df5dad88040364d24c752c852b4..f4b7630af32b8a73011eb2c55a4665169d48ce4d 100644 (file)
@@ -73,6 +73,7 @@ JSSRC=                                                        \
        FetchmailEdit.js                                \
        FetchmailView.js                                \
        UserManagement.js                               \
+       UserSelector.js                                 \
        ViewMailHeaders.js                              \
        PostfixQShape.js                                \
        PostfixMailQueue.js                             \
index 85e41e5297b36bac54e205b53bdab220accc411e..d81a4cc7e6a29cabbea746c8716ab969044cc49f 100644 (file)
@@ -27,7 +27,11 @@ Ext.define('PMG.UserManagement', {
            itemId: 'pop',
            iconCls: 'fa fa-reply-all',
        },
+       {
+           xtype: 'pmxTfaView',
+           title: 'Two Factor',
+           itemId: 'tfa',
+           iconCls: 'fa fa-key',
+       },
     ],
 });
-
-
diff --git a/js/UserSelector.js b/js/UserSelector.js
new file mode 100644 (file)
index 0000000..8fb31d7
--- /dev/null
@@ -0,0 +1,13 @@
+Ext.define('pmx-users', {
+    extend: 'Ext.data.Model',
+    fields: [
+       'userid', 'firstname', 'lastname', 'email', 'comment',
+       { type: 'boolean', name: 'enable' },
+       { type: 'date', dateFormat: 'timestamp', name: 'expire' },
+    ],
+    proxy: {
+       type: 'proxmox',
+       url: "/api2/json/access/users",
+    },
+    idProperty: 'userid',
+});
index 4a29ba2587a63e4765afe62b1caa914102b60f29..4e9f1afb1197b00b20a1836f51d6b42fd04e2e60 100644 (file)
@@ -24,6 +24,7 @@
     [% ELSE %]
     <script type="text/javascript" src="/pve2/ext6/ext-all.js"></script>
     <script type="text/javascript" src="/pve2/ext6/charts.js"></script>
+    <script type="text/javascript" src="/qrcode.min.js"></script>
     [% END %]
     <script type="text/javascript">
       Proxmox = {