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