]> git.proxmox.com Git - pmg-gui.git/blame - js/LoginView.js
fix typo
[pmg-gui.git] / js / LoginView.js
CommitLineData
2c1d504e 1/*global Proxmox*/
cd6bb503
DC
2Ext.define('PMG.LoginView', {
3 extend: 'Ext.container.Container',
4 xtype: 'loginview',
5
6 controller: {
7 xclass: 'Ext.app.ViewController',
4bc1cbd8
DM
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];
216bbcd5
DC
20 var loginwin = this.lookupReference('loginwindow');
21 loginwin.autoShow = false;
22 loginwin.setVisible(false);
4bc1cbd8
DM
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();
9bdd2de3 36 PMG.view = 'quarantine';
0277bfeb 37 Ext.create({ xtype: 'quarantineview' });
9584871d 38 Proxmox.Utils.checked_command(function() {}); // display subscription status
4bc1cbd8
DM
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
cd6bb503
DC
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();
0277bfeb
DM
62
63 if (location.pathname === "/quarantine") {
64 Ext.create({ xtype: 'quarantineview' });
9bdd2de3 65 PMG.view = 'quarantine';
0277bfeb
DM
66 } else {
67 Ext.create({ xtype: 'mainview' });
9bdd2de3 68 PMG.view = 'main';
0277bfeb 69 }
9584871d 70 Proxmox.Utils.checked_command(function() {}); // display subscription status
cd6bb503
DC
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: {
775b9a7d
DM
84 'field[name=lang]': {
85 change: function(f, value) {
86 var dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
282d45fb 87 Ext.util.Cookies.set('PMGLangCookie', value, dt);
65921b40
DM
88
89 var loginwin = this.lookupReference('loginwindow');
90 loginwin.mask(gettext('Please wait...'), 'x-mask-loading');
775b9a7d
DM
91 window.location.reload();
92 }
93 },
cd6bb503
DC
94 'button[reference=loginButton]': {
95 click: 'submitForm'
96 }
97 }
98 },
99
100 plugins: 'viewport',
101
ea07c9aa
DC
102 layout: {
103 type: 'border'
104 },
cd6bb503
DC
105
106 items: [
107 {
108 region: 'north',
109 xtype: 'container',
110 layout: {
111 type: 'hbox',
112 align: 'middle'
113 },
114 margin: '4 5 4 5',
115 items: [
116 {
117 xtype: 'proxmoxlogo'
118 },
119 {
120 xtype: 'versioninfo',
749af060 121 makeApiCall: false
cd6bb503
DC
122 }
123 ]
124 },
125 {
126 region: 'center'
127 },
128 {
129 xtype: 'window',
130 closable: false,
131 resizable: false,
216bbcd5 132 reference: 'loginwindow',
cd6bb503
DC
133 autoShow: true,
134 modal: true,
135
7d48b138
DC
136 defaultFocus: 'usernameField',
137
ea07c9aa
DC
138 layout: {
139 type: 'auto'
140 },
cd6bb503
DC
141
142 title: gettext('Proxmox Mail Gateway Login'),
143
144 items: [
145 {
146 xtype: 'form',
ea07c9aa
DC
147 layout: {
148 type: 'form'
149 },
cd6bb503
DC
150 defaultButton: 'loginButton',
151 url: '/api2/extjs/access/ticket',
152 reference: 'loginForm',
153
154 fieldDefaults: {
155 labelAlign: 'right',
156 allowBlank: false
157 },
158
159 items: [
160 {
161 xtype: 'textfield',
162 fieldLabel: gettext('User name'),
163 name: 'username',
164 itemId: 'usernameField',
749af060 165 reference: 'usernameField'
cd6bb503
DC
166 },
167 {
168 xtype: 'textfield',
169 inputType: 'password',
170 fieldLabel: gettext('Password'),
171 name: 'password',
172 reference: 'passwordField'
173 },
775b9a7d
DM
174 {
175 xtype: 'proxmoxLanguageSelector',
176 fieldLabel: gettext('Language'),
282d45fb 177 value: Ext.util.Cookies.get('PMGLangCookie') || 'en',
775b9a7d
DM
178 name: 'lang',
179 submitValue: false
180 },
cd6bb503
DC
181 {
182 xtype: 'hiddenfield',
183 name: 'realm',
749af060 184 value: 'pam'
cd6bb503
DC
185 }
186 ],
187 buttons: [
188 {
189 text: gettext('Login'),
190 reference: 'loginButton',
191 formBind: true
192 }
193 ]
194 }
195 ]
196 }
197 ]
198});