ui: dc/TFA Edit: eslint fixes and code cleanup/refactoring
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
a30dca2f9f
commit
12f237de8b
@ -1,4 +1,4 @@
|
|||||||
/*global u2f,QRCode,Uint8Array*/
|
/*global u2f,QRCode*/
|
||||||
Ext.define('PVE.window.TFAEdit', {
|
Ext.define('PVE.window.TFAEdit', {
|
||||||
extend: 'Ext.window.Window',
|
extend: 'Ext.window.Window',
|
||||||
mixins: ['Proxmox.Mixin.CBind'],
|
mixins: ['Proxmox.Mixin.CBind'],
|
||||||
@ -48,23 +48,23 @@ Ext.define('PVE.window.TFAEdit', {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
doU2FChallenge: function(response) {
|
doU2FChallenge: function(res) {
|
||||||
var me = this;
|
let me = this;
|
||||||
|
|
||||||
var data = response.result.data;
|
let challenge = res.result.data;
|
||||||
me.lookup('password').setDisabled(true);
|
me.lookup('password').setDisabled(true);
|
||||||
var msg = Ext.Msg.show({
|
let msg = Ext.Msg.show({
|
||||||
title: 'U2F: '+gettext('Setup'),
|
title: 'U2F: ' + gettext('Setup'),
|
||||||
message: gettext('Please press the button on your U2F Device'),
|
message: gettext('Please press the button on your U2F Device'),
|
||||||
buttons: [],
|
buttons: [],
|
||||||
});
|
});
|
||||||
Ext.Function.defer(function() {
|
Ext.Function.defer(function() {
|
||||||
u2f.register(data.appId, [data], [], function(data) {
|
u2f.register(challenge.appId, [challenge], [], function(response) {
|
||||||
msg.close();
|
msg.close();
|
||||||
if (data.errorCode) {
|
if (response.errorCode) {
|
||||||
me.showError(data.errorCode);
|
me.showError(response.errorCode);
|
||||||
} else {
|
} else {
|
||||||
me.respondToU2FChallenge(data);
|
me.respondToU2FChallenge(response);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 500, me);
|
}, 500, me);
|
||||||
@ -178,8 +178,7 @@ Ext.define('PVE.window.TFAEdit', {
|
|||||||
control: {
|
control: {
|
||||||
'field[qrupdate=true]': {
|
'field[qrupdate=true]': {
|
||||||
change: function() {
|
change: function() {
|
||||||
var me = this.getView();
|
this.getView().updateQrCode();
|
||||||
me.updateQrCode();
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'field': {
|
'field': {
|
||||||
@ -194,50 +193,47 @@ Ext.define('PVE.window.TFAEdit', {
|
|||||||
},
|
},
|
||||||
'#': {
|
'#': {
|
||||||
show: function() {
|
show: function() {
|
||||||
var me = this.getView();
|
let view = this.getView();
|
||||||
var viewmodel = this.getViewModel();
|
|
||||||
|
|
||||||
var loadMaskContainer = me.down('#tfatabs');
|
|
||||||
Proxmox.Utils.API2Request({
|
Proxmox.Utils.API2Request({
|
||||||
url: '/access/users/' + encodeURIComponent(me.userid) + '/tfa',
|
url: '/access/users/' + encodeURIComponent(view.userid) + '/tfa',
|
||||||
waitMsgTarget: loadMaskContainer,
|
waitMsgTarget: view.down('#tfatabs'),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
success: function(response, opts) {
|
success: function(response, opts) {
|
||||||
var data = response.result.data;
|
let data = response.result.data;
|
||||||
me.afterLoading(data.realm, data.user);
|
view.afterLoading(data.realm, data.user);
|
||||||
},
|
},
|
||||||
failure: function(response, opts) {
|
failure: function(response, opts) {
|
||||||
me.close();
|
view.close();
|
||||||
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
me.qrdiv = document.createElement('center');
|
view.qrdiv = document.createElement('center');
|
||||||
me.qrcode = new QRCode(me.qrdiv, {
|
view.qrcode = new QRCode(view.qrdiv, {
|
||||||
width: 256,
|
width: 256,
|
||||||
height: 256,
|
height: 256,
|
||||||
correctLevel: QRCode.CorrectLevel.M,
|
correctLevel: QRCode.CorrectLevel.M,
|
||||||
});
|
});
|
||||||
me.down('#qrbox').getEl().appendChild(me.qrdiv);
|
view.down('#qrbox').getEl().appendChild(view.qrdiv);
|
||||||
|
|
||||||
if (Proxmox.UserName === 'root@pam') {
|
if (Proxmox.UserName === 'root@pam') {
|
||||||
me.lookup('password').setVisible(false);
|
view.lookup('password').setVisible(false);
|
||||||
me.lookup('password').setDisabled(true);
|
view.lookup('password').setDisabled(true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'#tfatabs': {
|
'#tfatabs': {
|
||||||
tabchange: function(panel, newcard) {
|
tabchange: function(panel, newcard) {
|
||||||
var viewmodel = this.getViewModel();
|
this.getViewModel().set('in_totp_tab', newcard.itemId === 'totp-panel');
|
||||||
viewmodel.set('in_totp_tab', newcard.itemId === 'totp-panel');
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
applySettings: function() {
|
applySettings: function() {
|
||||||
var me = this;
|
let me = this;
|
||||||
var values = me.lookup('totp_form').getValues();
|
let values = me.lookup('totp_form').getValues();
|
||||||
var params = {
|
let params = {
|
||||||
userid: me.getView().userid,
|
userid: me.getView().userid,
|
||||||
action: 'new',
|
action: 'new',
|
||||||
key: 'v2-' + values.secret,
|
key: 'v2-' + values.secret,
|
||||||
@ -269,9 +265,8 @@ Ext.define('PVE.window.TFAEdit', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteTFA: function() {
|
deleteTFA: function() {
|
||||||
var me = this;
|
let me = this;
|
||||||
var values = me.lookup('totp_form').getValues();
|
let params = {
|
||||||
var params = {
|
|
||||||
userid: me.getView().userid,
|
userid: me.getView().userid,
|
||||||
action: 'delete',
|
action: 'delete',
|
||||||
};
|
};
|
||||||
@ -295,28 +290,26 @@ Ext.define('PVE.window.TFAEdit', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
randomizeSecret: function() {
|
randomizeSecret: function() {
|
||||||
var me = this;
|
let me = this;
|
||||||
var rnd = new Uint8Array(32);
|
let rnd = new Uint8Array(32);
|
||||||
window.crypto.getRandomValues(rnd);
|
window.crypto.getRandomValues(rnd);
|
||||||
var data = '';
|
let data = '';
|
||||||
rnd.forEach(function(b) {
|
rnd.forEach(function(b) {
|
||||||
// secret must be base32, so just use the first 5 bits
|
// secret must be base32, so just use the first 5 bits
|
||||||
b = b & 0x1f;
|
b = b & 0x1f;
|
||||||
if (b < 26) {
|
if (b < 26) {
|
||||||
// A..Z
|
data += String.fromCharCode(b + 0x41); // A..Z
|
||||||
data += String.fromCharCode(b + 0x41);
|
|
||||||
} else {
|
} else {
|
||||||
// 2..7
|
data += String.fromCharCode(b-26 + 0x32); // 2..7
|
||||||
data += String.fromCharCode(b-26 + 0x32);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
me.getViewModel().set('secret', data);
|
me.getViewModel().set('secret', data);
|
||||||
},
|
},
|
||||||
|
|
||||||
startU2FRegistration: function() {
|
startU2FRegistration: function() {
|
||||||
var me = this;
|
let me = this;
|
||||||
|
|
||||||
var params = {
|
let params = {
|
||||||
userid: me.getView().userid,
|
userid: me.getView().userid,
|
||||||
action: 'new',
|
action: 'new',
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user