]>
Commit | Line | Data |
---|---|---|
34f956bc DM |
1 | Ext.define('PBS.LoginView', { |
2 | extend: 'Ext.container.Container', | |
3 | xtype: 'loginview', | |
4 | ||
5 | controller: { | |
6 | xclass: 'Ext.app.ViewController', | |
7 | ||
8 | submitForm: function() { | |
9 | var me = this; | |
34f956bc | 10 | var loginForm = me.lookupReference('loginForm'); |
9abcae1b DM |
11 | var unField = me.lookupReference('usernameField'); |
12 | var saveunField = me.lookupReference('saveunField'); | |
34f956bc | 13 | |
9abcae1b DM |
14 | if (!loginForm.isValid()) { |
15 | return; | |
16 | } | |
17 | ||
18 | let params = loginForm.getValues(); | |
19 | ||
20 | params.username = params.username + '@' + params.realm; | |
8acd4d9a | 21 | delete params.realm; |
9abcae1b DM |
22 | |
23 | if (loginForm.isVisible()) { | |
24 | loginForm.mask(gettext('Please wait...'), 'x-mask-loading'); | |
34f956bc | 25 | } |
9abcae1b DM |
26 | |
27 | // set or clear username | |
28 | var sp = Ext.state.Manager.getProvider(); | |
29 | if (saveunField.getValue() === true) { | |
30 | sp.set(unField.getStateId(), unField.getValue()); | |
31 | } else { | |
32 | sp.clear(unField.getStateId()); | |
33 | } | |
34 | sp.set(saveunField.getStateId(), saveunField.getValue()); | |
35 | ||
36 | Proxmox.Utils.API2Request({ | |
37 | url: '/api2/extjs/access/ticket', | |
38 | params: params, | |
39 | method: 'POST', | |
40 | success: function(resp, opts) { | |
41 | // save login data and create cookie | |
42 | PBS.Utils.updateLoginData(resp.result.data); | |
43 | PBS.app.changeView('mainview'); | |
44 | }, | |
45 | failure: function(resp, opts) { | |
46 | Proxmox.Utils.authClear(); | |
47 | loginForm.unmask(); | |
48 | Ext.MessageBox.alert( | |
49 | gettext('Error'), | |
8acd4d9a | 50 | gettext('Login failed. Please try again'), |
9abcae1b | 51 | ); |
8acd4d9a | 52 | }, |
9abcae1b | 53 | }); |
34f956bc DM |
54 | }, |
55 | ||
56 | control: { | |
9abcae1b DM |
57 | 'field[name=username]': { |
58 | specialkey: function(f, e) { | |
59 | if (e.getKey() === e.ENTER) { | |
60 | var pf = this.lookupReference('passwordField'); | |
61 | if (!pf.getValue()) { | |
62 | pf.focus(false); | |
63 | } | |
64 | } | |
8acd4d9a | 65 | }, |
9abcae1b DM |
66 | }, |
67 | 'field[name=lang]': { | |
68 | change: function(f, value) { | |
69 | var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10); | |
70 | Ext.util.Cookies.set('PBSLangCookie', value, dt); | |
71 | this.getView().mask(gettext('Please wait...'), 'x-mask-loading'); | |
72 | window.location.reload(); | |
8acd4d9a | 73 | }, |
9abcae1b | 74 | }, |
34f956bc | 75 | 'button[reference=loginButton]': { |
8acd4d9a | 76 | click: 'submitForm', |
9abcae1b DM |
77 | }, |
78 | 'window[reference=loginwindow]': { | |
79 | show: function() { | |
80 | var sp = Ext.state.Manager.getProvider(); | |
81 | var checkboxField = this.lookupReference('saveunField'); | |
82 | var unField = this.lookupReference('usernameField'); | |
83 | ||
84 | var checked = sp.get(checkboxField.getStateId()); | |
85 | checkboxField.setValue(checked); | |
86 | ||
8acd4d9a | 87 | if (checked === true) { |
9abcae1b DM |
88 | var username = sp.get(unField.getStateId()); |
89 | unField.setValue(username); | |
90 | var pwField = this.lookupReference('passwordField'); | |
91 | pwField.focus(); | |
92 | } | |
8acd4d9a TL |
93 | }, |
94 | }, | |
95 | }, | |
34f956bc DM |
96 | }, |
97 | ||
98 | plugins: 'viewport', | |
99 | ||
100 | layout: { | |
8acd4d9a | 101 | type: 'border', |
34f956bc DM |
102 | }, |
103 | ||
104 | items: [ | |
105 | { | |
106 | region: 'north', | |
107 | xtype: 'container', | |
108 | layout: { | |
109 | type: 'hbox', | |
8acd4d9a | 110 | align: 'middle', |
34f956bc DM |
111 | }, |
112 | margin: '2 5 2 5', | |
113 | height: 38, | |
114 | items: [ | |
115 | { | |
1d8ef0dc DC |
116 | xtype: 'proxmoxlogo', |
117 | prefix: '', | |
34f956bc DM |
118 | }, |
119 | { | |
120 | xtype: 'versioninfo', | |
8acd4d9a TL |
121 | makeApiCall: false, |
122 | }, | |
123 | ], | |
34f956bc DM |
124 | }, |
125 | { | |
8acd4d9a | 126 | region: 'center', |
34f956bc DM |
127 | }, |
128 | { | |
129 | xtype: 'window', | |
130 | closable: false, | |
131 | resizable: false, | |
132 | reference: 'loginwindow', | |
133 | autoShow: true, | |
134 | modal: true, | |
9abcae1b | 135 | width: 400, |
34f956bc | 136 | |
9abcae1b | 137 | defaultFocus: 'usernameField', |
34f956bc DM |
138 | |
139 | layout: { | |
8acd4d9a | 140 | type: 'auto', |
34f956bc DM |
141 | }, |
142 | ||
143 | title: gettext('Proxmox Backup Server Login'), | |
144 | ||
145 | items: [ | |
146 | { | |
147 | xtype: 'form', | |
148 | layout: { | |
8acd4d9a | 149 | type: 'form', |
34f956bc DM |
150 | }, |
151 | defaultButton: 'loginButton', | |
152 | url: '/api2/extjs/access/ticket', | |
153 | reference: 'loginForm', | |
154 | ||
155 | fieldDefaults: { | |
156 | labelAlign: 'right', | |
8acd4d9a | 157 | allowBlank: false, |
34f956bc DM |
158 | }, |
159 | ||
160 | items: [ | |
161 | { | |
162 | xtype: 'textfield', | |
163 | fieldLabel: gettext('User name'), | |
164 | name: 'username', | |
165 | itemId: 'usernameField', | |
9abcae1b | 166 | reference: 'usernameField', |
8acd4d9a | 167 | stateId: 'login-username', |
34f956bc DM |
168 | }, |
169 | { | |
170 | xtype: 'textfield', | |
171 | inputType: 'password', | |
172 | fieldLabel: gettext('Password'), | |
173 | name: 'password', | |
3a841004 TL |
174 | itemId: 'passwordField', |
175 | reference: 'passwordField', | |
9abcae1b | 176 | }, |
1d8ef0dc DC |
177 | { |
178 | xtype: 'pmxRealmComboBox', | |
8acd4d9a | 179 | name: 'realm', |
1d8ef0dc | 180 | }, |
9abcae1b DM |
181 | { |
182 | xtype: 'proxmoxLanguageSelector', | |
183 | fieldLabel: gettext('Language'), | |
184 | value: Ext.util.Cookies.get('PBSLangCookie') || Proxmox.defaultLang || 'en', | |
185 | name: 'lang', | |
186 | reference: 'langField', | |
8acd4d9a TL |
187 | submitValue: false, |
188 | }, | |
34f956bc DM |
189 | ], |
190 | buttons: [ | |
9abcae1b DM |
191 | { |
192 | xtype: 'checkbox', | |
193 | fieldLabel: gettext('Save User name'), | |
194 | name: 'saveusername', | |
195 | reference: 'saveunField', | |
196 | stateId: 'login-saveusername', | |
197 | labelWidth: 250, | |
198 | labelAlign: 'right', | |
8acd4d9a | 199 | submitValue: false, |
9abcae1b | 200 | }, |
34f956bc DM |
201 | { |
202 | text: gettext('Login'), | |
203 | reference: 'loginButton', | |
8acd4d9a TL |
204 | formBind: true, |
205 | }, | |
206 | ], | |
207 | }, | |
208 | ], | |
209 | }, | |
210 | ], | |
34f956bc | 211 | }); |