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