]> git.proxmox.com Git - pmg-gui.git/blob - js/LoginView.js
add 'Request Quarantine Link' Button to LoginView
[pmg-gui.git] / js / LoginView.js
1 Ext.define('PMG.LoginView', {
2 extend: 'Ext.container.Container',
3 xtype: 'loginview',
4
5 controller: {
6 xclass: 'Ext.app.ViewController',
7
8 init: function(view) {
9 let me = this;
10
11 let realmfield = me.lookup('realmfield');
12
13 me.lookup('quarantineButton').setVisible(!!Proxmox.QuarantineLink);
14
15 if (view.targetview !== 'quarantineview') {
16 return;
17 }
18
19 realmfield.setValue('quarantine');
20
21 // try autologin with quarantine ticket from URL
22
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');
34 loginwin.autoShow = false;
35 loginwin.setVisible(false);
36 realmfield.setDisabled(true);
37
38 me.lookup('usernameField').setValue(username);
39 me.lookup('passwordField').setValue(ticket);
40
41 me.submitForm();
42 },
43
44 submitForm: function() {
45 let me = this;
46 let view = me.getView();
47 let loginForm = me.lookupReference('loginForm');
48
49 if (loginForm.isValid()) {
50 if (loginForm.isVisible()) {
51 loginForm.mask(gettext('Please wait...'), 'x-mask-loading');
52 }
53 loginForm.submit({
54 success: function(form, action) {
55 // save login data and create cookie
56 PMG.Utils.updateLoginData(action.result.data);
57 PMG.app.changeView(view.targetview);
58 },
59 failure: function(form, action) {
60 loginForm.unmask();
61 Ext.MessageBox.alert(
62 gettext('Error'),
63 gettext('Login failed. Please try again'),
64 );
65 },
66 });
67 }
68 },
69
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
94 control: {
95 'field[name=lang]': {
96 change: function(f, value) {
97 let dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
98 Ext.util.Cookies.set('PMGLangCookie', value, dt);
99
100 let loginwin = this.lookupReference('loginwindow');
101 loginwin.mask(gettext('Please wait...'), 'x-mask-loading');
102 window.location.reload();
103 },
104 },
105 'button[reference=quarantineButton]': {
106 click: 'openQuarantineLinkWindow',
107 },
108 'button[reference=loginButton]': {
109 click: 'submitForm',
110 },
111 },
112 },
113
114 plugins: 'viewport',
115
116 layout: {
117 type: 'border',
118 },
119
120 items: [
121 {
122 region: 'north',
123 xtype: 'container',
124 layout: {
125 type: 'hbox',
126 align: 'middle',
127 },
128 margin: '2 5 2 5',
129 height: 38,
130 items: [
131 {
132 xtype: 'proxmoxlogo',
133 },
134 {
135 xtype: 'versioninfo',
136 makeApiCall: false,
137 },
138 ],
139 },
140 {
141 region: 'center',
142 },
143 {
144 xtype: 'window',
145 closable: false,
146 resizable: false,
147 reference: 'loginwindow',
148 autoShow: true,
149 modal: true,
150
151 defaultFocus: 'usernameField',
152
153 layout: {
154 type: 'auto',
155 },
156
157 title: gettext('Proxmox Mail Gateway Login'),
158
159 items: [
160 {
161 xtype: 'form',
162 layout: {
163 type: 'form',
164 },
165 defaultButton: 'loginButton',
166 url: '/api2/extjs/access/ticket',
167 reference: 'loginForm',
168
169 fieldDefaults: {
170 labelAlign: 'right',
171 allowBlank: false,
172 },
173
174 items: [
175 {
176 xtype: 'textfield',
177 fieldLabel: gettext('User name'),
178 name: 'username',
179 itemId: 'usernameField',
180 reference: 'usernameField',
181 },
182 {
183 xtype: 'textfield',
184 inputType: 'password',
185 fieldLabel: gettext('Password'),
186 name: 'password',
187 reference: 'passwordField',
188 },
189 {
190 xtype: 'proxmoxLanguageSelector',
191 fieldLabel: gettext('Language'),
192 value: Ext.util.Cookies.get('PMGLangCookie') || 'en',
193 name: 'lang',
194 submitValue: false,
195 },
196 {
197 xtype: 'hiddenfield',
198 reference: 'realmfield',
199 name: 'realm',
200 value: 'pmg',
201 },
202 ],
203 buttons: [
204 {
205 text: gettext('Request Quarantine Link'),
206 reference: 'quarantineButton',
207 },
208 {
209 text: gettext('Login'),
210 reference: 'loginButton',
211 formBind: true,
212 },
213 ],
214 },
215 ],
216 },
217 ],
218 });