]> git.proxmox.com Git - pve-manager.git/blob - www/manager/window/LoginWindow.js
333144470bcf9686a78ca9f24f671a9da4254bd7
[pve-manager.git] / www / manager / window / LoginWindow.js
1 Ext.define('PVE.window.LoginWindow', {
2 extend: 'Ext.window.Window',
3
4 // private
5 onLogon: function() {
6 var me = this;
7
8 var form = me.getComponent(0).getForm();
9
10 if(form.isValid()){
11 me.el.mask(gettext('Please wait...'), 'x-mask-loading');
12
13 form.submit({
14 failure: function(f, resp){
15 me.el.unmask();
16 Ext.MessageBox.alert(gettext('Error'),
17 gettext("Login failed. Please try again"),
18 function() {
19 var uf = form.findField('username');
20 uf.focus(true, true);
21 });
22 },
23 success: function(f, resp){
24 me.el.unmask();
25
26 var handler = me.handler || Ext.emptyFn;
27 handler.call(me, resp.result.data);
28 me.close();
29 }
30 });
31 }
32 },
33
34 initComponent: function() {
35 var me = this;
36
37 var otp_field = Ext.createWidget('textfield', {
38 fieldLabel: gettext('OTP'),
39 name: 'otp',
40 allowBlank: false,
41 hidden: true
42 });
43
44 Ext.apply(me, {
45 width: 400,
46 modal: true,
47 border: false,
48 draggable: true,
49 closable: false,
50 resizable: false,
51 layout: 'auto',
52 title: gettext('Proxmox VE Login'),
53
54 items: [{
55 xtype: 'form',
56 frame: true,
57 url: '/api2/extjs/access/ticket',
58
59 fieldDefaults: {
60 labelAlign: 'right'
61 },
62
63 defaults: {
64 anchor: '-5',
65 allowBlank: false
66 },
67
68 items: [
69 {
70 xtype: 'textfield',
71 fieldLabel: gettext('User name'),
72 name: 'username',
73 blankText: gettext("Enter your user name"),
74 listeners: {
75 afterrender: function(f) {
76 // Note: only works if we pass delay 1000
77 f.focus(true, 1000);
78 },
79 specialkey: function(f, e) {
80 if (e.getKey() === e.ENTER) {
81 var pf = me.query('textfield[name="password"]')[0];
82 if (pf.getValue()) {
83 me.onLogon();
84 } else {
85 pf.focus(false);
86 }
87 }
88 }
89 }
90 },
91 {
92 xtype: 'textfield',
93 inputType: 'password',
94 fieldLabel: gettext('Password'),
95 name: 'password',
96 blankText: gettext("Enter your password"),
97 listeners: {
98 specialkey: function(field, e) {
99 if (e.getKey() === e.ENTER) {
100 me.onLogon();
101 }
102 }
103 }
104 },
105 otp_field,
106 {
107 xtype: 'pveRealmComboBox',
108 name: 'realm',
109 listeners: {
110 change: function(f, value) {
111 if (f.needOTP(value)) {
112 otp_field.setVisible(true);
113 otp_field.setDisabled(false);
114 } else {
115 otp_field.setVisible(false);
116 otp_field.setDisabled(true);
117 }
118 }
119 }
120 },
121 {
122 xtype: 'pveLanguageSelector',
123 fieldLabel: gettext('Language'),
124 value: Ext.util.Cookies.get('PVELangCookie') || 'en',
125 name: 'lang',
126 submitValue: false,
127 listeners: {
128 change: function(t, value) {
129 var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
130 Ext.util.Cookies.set('PVELangCookie', value, dt);
131 me.el.mask(gettext('Please wait...'), 'x-mask-loading');
132 window.location.reload();
133 }
134 }
135 }
136 ],
137 buttons: [
138 {
139 text: gettext('Login'),
140 handler: function(){
141 me.onLogon();
142 }
143 }
144 ]
145 }]
146 });
147
148 me.callParent();
149 }
150 });