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