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