]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/window/AddYubico.js
Buttons: add AltText
[proxmox-widget-toolkit.git] / src / window / AddYubico.js
CommitLineData
20b39dd8
WB
1Ext.define('Proxmox.window.AddYubico', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pmxAddYubico',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 onlineHelp: 'user_mgmt',
7
8 modal: true,
9 resizable: false,
05da27ed 10 title: gettext('Add a Yubico OTP key'),
20b39dd8
WB
11 width: 512,
12
13 isAdd: true,
14 userid: undefined,
15 fixedUser: false,
16
17 initComponent: function() {
18 let me = this;
19 me.url = '/api2/extjs/access/tfa/';
20 me.method = 'POST';
21 me.callParent();
22 },
23
24 viewModel: {
25 data: {
26 valid: false,
27 userid: null,
28 },
29 },
30
31 controller: {
32 xclass: 'Ext.app.ViewController',
33
34 control: {
35 'field': {
36 validitychange: function(field, valid) {
37 let me = this;
38 let viewmodel = me.getViewModel();
39 let form = me.lookup('yubico_form');
40 viewmodel.set('valid', form.isValid());
41 },
42 },
43 '#': {
44 show: function() {
45 let me = this;
46 let view = me.getView();
47
48 if (Proxmox.UserName === 'root@pam') {
49 view.lookup('password').setVisible(false);
50 view.lookup('password').setDisabled(true);
51 }
52 },
53 },
54 },
55 },
56
57 items: [
58 {
59 xtype: 'form',
60 reference: 'yubico_form',
61 layout: 'anchor',
62 border: false,
63 bodyPadding: 10,
64 fieldDefaults: {
65 anchor: '100%',
66 },
67 items: [
68 {
69 xtype: 'pmxDisplayEditField',
70 name: 'userid',
71 cbind: {
72 editable: (get) => !get('fixedUser'),
73 value: () => Proxmox.UserName,
74 },
75 fieldLabel: gettext('User'),
76 editConfig: {
77 xtype: 'pmxUserSelector',
78 allowBlank: false,
79 },
80 renderer: Ext.String.htmlEncode,
81 listeners: {
82 change: function(field, newValue, oldValue) {
83 let vm = this.up('window').getViewModel();
84 vm.set('userid', newValue);
85 },
86 },
87 },
88 {
89 xtype: 'textfield',
90 fieldLabel: gettext('Description'),
91 allowBlank: false,
92 name: 'description',
93 maxLength: 256,
94 emptyText: gettext('For example: TFA device ID, required to identify multiple factors.'),
95 },
96 {
97 xtype: 'textfield',
98 fieldLabel: gettext('Yubico OTP Key'),
99 emptyText: gettext('A currently valid Yubico OTP value'),
100 name: 'otp_value',
101 maxLength: 44,
102 enforceMaxLength: true,
103 regex: /^[a-zA-Z0-9]{44}$/,
104 regexText: '44 characters',
105 maskRe: /^[a-zA-Z0-9]$/,
106 },
107 {
108 xtype: 'textfield',
109 name: 'password',
110 reference: 'password',
111 fieldLabel: gettext('Verify Password'),
112 inputType: 'password',
113 minLength: 5,
114 allowBlank: false,
115 validateBlank: true,
116 cbind: {
117 hidden: () => Proxmox.UserName === 'root@pam',
118 disabled: () => Proxmox.UserName === 'root@pam',
119 emptyText: () =>
120 Ext.String.format(gettext("Confirm your ({0}) password"), Proxmox.UserName),
121 },
122 },
05da27ed
TL
123 {
124 xtype: 'box',
125 html: `<span class='pmx-hint'>${gettext('Tip:')}</span> `
126 + gettext('YubiKeys also support WebAuthn, which is often a better alternative.'),
127 },
20b39dd8
WB
128 ],
129 },
130 ],
131
132 getValues: function(dirtyOnly) {
133 let me = this;
134
135 let values = me.callParent(arguments);
136
137 let uid = encodeURIComponent(values.userid);
138 me.url = `/api2/extjs/access/tfa/${uid}`;
139 delete values.userid;
140
141 let data = {
142 description: values.description,
143 type: "yubico",
144 value: values.otp_value,
145 };
146
147 if (values.password) {
148 data.password = values.password;
149 }
150
151 return data;
152 },
153});