]> git.proxmox.com Git - pmg-gui.git/blob - js/LoginView.js
add language selector
[pmg-gui.git] / js / LoginView.js
1 /*global Proxmox*/
2 Ext.define('PMG.LoginView', {
3 extend: 'Ext.container.Container',
4 xtype: 'loginview',
5
6 controller: {
7 xclass: 'Ext.app.ViewController',
8
9 init: function(view) {
10 var loginForm = this.lookupReference('loginForm');
11
12 // try autologin with quarantine ticket from URL
13
14 var qs = Ext.Object.fromQueryString(location.search);
15 if (qs.ticket == undefined) { return; }
16 var ticket = decodeURIComponent(qs.ticket);
17 var match = ticket.match(/^PMGQUAR:([^\s\:]+):/);
18 if (!match) { return; }
19 var username = match[1];
20 var loginwin = this.lookupReference('loginwindow');
21 loginwin.autoShow = false;
22 loginwin.setVisible(false);
23
24 Proxmox.Utils.API2Request({
25 url: '/api2/extjs/access/ticket',
26 params: {
27 username: username,
28 password: ticket
29 },
30 method: 'POST',
31 success: function(response) {
32 // save login data and create cookie
33 PMG.Utils.updateLoginData(response.result.data);
34 // change view to mainview
35 view.destroy();
36 PMG.view = 'quarantine';
37 Ext.create({ xtype: 'quarantineview' });
38 Proxmox.Utils.checked_command(function() {}); // display subscription status
39 },
40 failure: function(form, action) {
41 loginForm.unmask();
42 Ext.MessageBox.alert(
43 gettext('Error'),
44 gettext('Login failed. Please try again')
45 );
46 }
47 });
48 },
49
50 submitForm: function() {
51 var me = this;
52 var loginForm = me.lookupReference('loginForm');
53
54 if (loginForm.isValid()) {
55 loginForm.mask(gettext('Please wait...'), 'x-mask-loading');
56 loginForm.submit({
57 success: function(form, action) {
58 // save login data and create cookie
59 PMG.Utils.updateLoginData(action.result.data);
60 // change view to mainview
61 me.getView().destroy();
62
63 if (location.pathname === "/quarantine") {
64 Ext.create({ xtype: 'quarantineview' });
65 PMG.view = 'quarantine';
66 } else {
67 Ext.create({ xtype: 'mainview' });
68 PMG.view = 'main';
69 }
70 Proxmox.Utils.checked_command(function() {}); // display subscription status
71 },
72 failure: function(form, action) {
73 loginForm.unmask();
74 Ext.MessageBox.alert(
75 gettext('Error'),
76 gettext('Login failed. Please try again')
77 );
78 }
79 });
80 }
81 },
82
83 control: {
84 'field[name=lang]': {
85 change: function(f, value) {
86 var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
87 Ext.util.Cookies.set('ProxmoxLangCookie', value, dt);
88 this.getView().mask(gettext('Please wait...'), 'x-mask-loading');
89 window.location.reload();
90 }
91 },
92 'button[reference=loginButton]': {
93 click: 'submitForm'
94 }
95 }
96 },
97
98 plugins: 'viewport',
99
100 layout: {
101 type: 'border'
102 },
103
104 items: [
105 {
106 region: 'north',
107 xtype: 'container',
108 layout: {
109 type: 'hbox',
110 align: 'middle'
111 },
112 margin: '4 5 4 5',
113 items: [
114 {
115 xtype: 'proxmoxlogo'
116 },
117 {
118 xtype: 'versioninfo',
119 makeApiCall: false
120 }
121 ]
122 },
123 {
124 region: 'center'
125 },
126 {
127 xtype: 'window',
128 closable: false,
129 resizable: false,
130 reference: 'loginwindow',
131 autoShow: true,
132 modal: true,
133
134 defaultFocus: 'usernameField',
135
136 layout: {
137 type: 'auto'
138 },
139
140 title: gettext('Proxmox Mail Gateway Login'),
141
142 items: [
143 {
144 xtype: 'form',
145 layout: {
146 type: 'form'
147 },
148 defaultButton: 'loginButton',
149 url: '/api2/extjs/access/ticket',
150 reference: 'loginForm',
151
152 fieldDefaults: {
153 labelAlign: 'right',
154 allowBlank: false
155 },
156
157 items: [
158 {
159 xtype: 'textfield',
160 fieldLabel: gettext('User name'),
161 name: 'username',
162 itemId: 'usernameField',
163 reference: 'usernameField'
164 },
165 {
166 xtype: 'textfield',
167 inputType: 'password',
168 fieldLabel: gettext('Password'),
169 name: 'password',
170 reference: 'passwordField'
171 },
172 {
173 xtype: 'proxmoxLanguageSelector',
174 fieldLabel: gettext('Language'),
175 value: Ext.util.Cookies.get('ProxmoxLangCookie') || 'en',
176 name: 'lang',
177 submitValue: false
178 },
179 {
180 xtype: 'hiddenfield',
181 name: 'realm',
182 value: 'pam'
183 }
184 ],
185 buttons: [
186 {
187 text: gettext('Login'),
188 reference: 'loginButton',
189 formBind: true
190 }
191 ]
192 }
193 ]
194 }
195 ]
196 });