]>
Commit | Line | Data |
---|---|---|
cd6bb503 DC |
1 | Ext.define('PMG.LoginView', { |
2 | extend: 'Ext.container.Container', | |
3 | xtype: 'loginview', | |
4 | ||
5 | controller: { | |
6 | xclass: 'Ext.app.ViewController', | |
4bc1cbd8 DM |
7 | |
8 | init: function(view) { | |
28eb60c0 | 9 | let me = this; |
c1e4fa2a | 10 | |
28eb60c0 | 11 | let realmfield = me.lookup('realmfield'); |
c1e4fa2a | 12 | |
83c036b4 DC |
13 | me.lookup('quarantineButton').setVisible(!!Proxmox.QuarantineLink); |
14 | ||
c17f9fe4 DC |
15 | if (view.targetview !== 'quarantineview') { |
16 | return; | |
17 | } | |
c1e4fa2a | 18 | |
ab01cd95 | 19 | realmfield.setValue('quarantine'); |
4bc1cbd8 DM |
20 | |
21 | // try autologin with quarantine ticket from URL | |
22 | ||
28eb60c0 TL |
23 | let qs = Ext.Object.fromQueryString(location.search); |
24 | if (qs.ticket === undefined) { | |
25 | return; | |
26 | } | |
27 | let ticket = decodeURIComponent(qs.ticket); | |
28 | let match = ticket.match(/^PMGQUAR:([^\s:]+):/); | |
29 | if (!match) { | |
30 | return; | |
31 | } | |
32 | let username = match[1]; | |
33 | let loginwin = me.lookup('loginwindow'); | |
216bbcd5 DC |
34 | loginwin.autoShow = false; |
35 | loginwin.setVisible(false); | |
c1e4fa2a | 36 | realmfield.setDisabled(true); |
4bc1cbd8 | 37 | |
99bba12c DC |
38 | me.lookup('usernameField').setValue(username); |
39 | me.lookup('passwordField').setValue(ticket); | |
40 | ||
41 | me.submitForm(); | |
4bc1cbd8 DM |
42 | }, |
43 | ||
cd6bb503 | 44 | submitForm: function() { |
28eb60c0 TL |
45 | let me = this; |
46 | let view = me.getView(); | |
47 | let loginForm = me.lookupReference('loginForm'); | |
cd6bb503 DC |
48 | |
49 | if (loginForm.isValid()) { | |
99bba12c DC |
50 | if (loginForm.isVisible()) { |
51 | loginForm.mask(gettext('Please wait...'), 'x-mask-loading'); | |
52 | } | |
cd6bb503 DC |
53 | loginForm.submit({ |
54 | success: function(form, action) { | |
55 | // save login data and create cookie | |
56 | PMG.Utils.updateLoginData(action.result.data); | |
99bba12c | 57 | PMG.app.changeView(view.targetview); |
cd6bb503 DC |
58 | }, |
59 | failure: function(form, action) { | |
60 | loginForm.unmask(); | |
61 | Ext.MessageBox.alert( | |
62 | gettext('Error'), | |
c87d46fb | 63 | gettext('Login failed. Please try again'), |
cd6bb503 | 64 | ); |
c87d46fb | 65 | }, |
cd6bb503 DC |
66 | }); |
67 | } | |
68 | }, | |
69 | ||
83c036b4 DC |
70 | openQuarantineLinkWindow: function() { |
71 | let me = this; | |
72 | me.lookup('loginwindow').setVisible(false); | |
73 | Ext.create('Proxmox.window.Edit', { | |
74 | title: gettext('Request Quarantine Link'), | |
75 | url: '/quarantine/sendlink', | |
76 | isCreate: true, | |
77 | submitText: gettext('OK'), | |
78 | method: 'POST', | |
79 | items: [ | |
80 | { | |
81 | xtype: 'proxmoxtextfield', | |
82 | name: 'mail', | |
83 | fieldLabel: gettext('Your E-Mail'), | |
84 | }, | |
85 | ], | |
86 | listeners: { | |
87 | destroy: function() { | |
88 | me.lookup('loginwindow').show(true); | |
89 | }, | |
90 | }, | |
91 | }).show(); | |
92 | }, | |
93 | ||
cd6bb503 | 94 | control: { |
775b9a7d DM |
95 | 'field[name=lang]': { |
96 | change: function(f, value) { | |
28eb60c0 | 97 | let dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10); |
282d45fb | 98 | Ext.util.Cookies.set('PMGLangCookie', value, dt); |
65921b40 | 99 | |
28eb60c0 | 100 | let loginwin = this.lookupReference('loginwindow'); |
65921b40 | 101 | loginwin.mask(gettext('Please wait...'), 'x-mask-loading'); |
775b9a7d | 102 | window.location.reload(); |
c87d46fb | 103 | }, |
775b9a7d | 104 | }, |
83c036b4 DC |
105 | 'button[reference=quarantineButton]': { |
106 | click: 'openQuarantineLinkWindow', | |
107 | }, | |
cd6bb503 | 108 | 'button[reference=loginButton]': { |
c87d46fb TL |
109 | click: 'submitForm', |
110 | }, | |
111 | }, | |
cd6bb503 DC |
112 | }, |
113 | ||
114 | plugins: 'viewport', | |
115 | ||
ea07c9aa | 116 | layout: { |
c87d46fb | 117 | type: 'border', |
ea07c9aa | 118 | }, |
cd6bb503 DC |
119 | |
120 | items: [ | |
121 | { | |
122 | region: 'north', | |
123 | xtype: 'container', | |
124 | layout: { | |
125 | type: 'hbox', | |
c87d46fb | 126 | align: 'middle', |
cd6bb503 | 127 | }, |
c45e23e4 DC |
128 | margin: '2 5 2 5', |
129 | height: 38, | |
cd6bb503 DC |
130 | items: [ |
131 | { | |
c87d46fb | 132 | xtype: 'proxmoxlogo', |
cd6bb503 DC |
133 | }, |
134 | { | |
135 | xtype: 'versioninfo', | |
c87d46fb TL |
136 | makeApiCall: false, |
137 | }, | |
138 | ], | |
cd6bb503 DC |
139 | }, |
140 | { | |
c87d46fb | 141 | region: 'center', |
cd6bb503 DC |
142 | }, |
143 | { | |
144 | xtype: 'window', | |
145 | closable: false, | |
146 | resizable: false, | |
216bbcd5 | 147 | reference: 'loginwindow', |
cd6bb503 DC |
148 | autoShow: true, |
149 | modal: true, | |
150 | ||
7d48b138 DC |
151 | defaultFocus: 'usernameField', |
152 | ||
ea07c9aa | 153 | layout: { |
c87d46fb | 154 | type: 'auto', |
ea07c9aa | 155 | }, |
cd6bb503 DC |
156 | |
157 | title: gettext('Proxmox Mail Gateway Login'), | |
158 | ||
159 | items: [ | |
160 | { | |
161 | xtype: 'form', | |
ea07c9aa | 162 | layout: { |
c87d46fb | 163 | type: 'form', |
ea07c9aa | 164 | }, |
cd6bb503 DC |
165 | defaultButton: 'loginButton', |
166 | url: '/api2/extjs/access/ticket', | |
167 | reference: 'loginForm', | |
168 | ||
169 | fieldDefaults: { | |
170 | labelAlign: 'right', | |
c87d46fb | 171 | allowBlank: false, |
cd6bb503 DC |
172 | }, |
173 | ||
174 | items: [ | |
175 | { | |
176 | xtype: 'textfield', | |
177 | fieldLabel: gettext('User name'), | |
178 | name: 'username', | |
179 | itemId: 'usernameField', | |
c87d46fb | 180 | reference: 'usernameField', |
cd6bb503 DC |
181 | }, |
182 | { | |
183 | xtype: 'textfield', | |
184 | inputType: 'password', | |
185 | fieldLabel: gettext('Password'), | |
186 | name: 'password', | |
c87d46fb | 187 | reference: 'passwordField', |
cd6bb503 | 188 | }, |
775b9a7d DM |
189 | { |
190 | xtype: 'proxmoxLanguageSelector', | |
191 | fieldLabel: gettext('Language'), | |
282d45fb | 192 | value: Ext.util.Cookies.get('PMGLangCookie') || 'en', |
775b9a7d | 193 | name: 'lang', |
c87d46fb | 194 | submitValue: false, |
ab01cd95 DM |
195 | }, |
196 | { | |
197 | xtype: 'hiddenfield', | |
198 | reference: 'realmfield', | |
199 | name: 'realm', | |
c87d46fb TL |
200 | value: 'pmg', |
201 | }, | |
cd6bb503 DC |
202 | ], |
203 | buttons: [ | |
83c036b4 DC |
204 | { |
205 | text: gettext('Request Quarantine Link'), | |
206 | reference: 'quarantineButton', | |
207 | }, | |
cd6bb503 DC |
208 | { |
209 | text: gettext('Login'), | |
210 | reference: 'loginButton', | |
c87d46fb TL |
211 | formBind: true, |
212 | }, | |
213 | ], | |
214 | }, | |
215 | ], | |
216 | }, | |
217 | ], | |
cd6bb503 | 218 | }); |