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