]> git.proxmox.com Git - pmg-gui.git/blob - js/LoginView.js
jslint: type confusion
[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 loginForm = this.lookupReference('loginForm');
11
12 // try autologin with quarantine ticket from URL
13
14 var qs = Ext.Object.fromQueryString(location.search);
15 if (qs.ticket == undefined) { return; }
16 var ticket = decodeURIComponent(qs.ticket);
17 var match = ticket.match(/^PMGQUAR:([^\s\:]+):/);
18 if (!match) { return; }
19 var username = match[1];
20 var loginwin = this.lookupReference('loginwindow');
21 loginwin.autoShow = false;
22 loginwin.setVisible(false);
23
24 Proxmox.Utils.API2Request({
25 url: '/api2/extjs/access/ticket',
26 params: {
27 username: username,
28 password: ticket
29 },
30 method: 'POST',
31 success: function(response) {
32 // save login data and create cookie
33 PMG.Utils.updateLoginData(response.result.data);
34 // change view to mainview
35 view.destroy();
36 PMG.view = 'quarantine';
37 Ext.create({ xtype: 'quarantineview' });
38 },
39 failure: function(form, action) {
40 loginForm.unmask();
41 Ext.MessageBox.alert(
42 gettext('Error'),
43 gettext('Login failed. Please try again')
44 );
45 }
46 });
47 },
48
49 submitForm: function() {
50 var me = this;
51 var loginForm = me.lookupReference('loginForm');
52
53 if (loginForm.isValid()) {
54 loginForm.mask(gettext('Please wait...'), 'x-mask-loading');
55 loginForm.submit({
56 success: function(form, action) {
57 // save login data and create cookie
58 PMG.Utils.updateLoginData(action.result.data);
59 // change view to mainview
60 me.getView().destroy();
61
62 if (location.pathname === "/quarantine") {
63 Ext.create({ xtype: 'quarantineview' });
64 PMG.view = 'quarantine';
65 } else {
66 Ext.create({ xtype: 'mainview' });
67 PMG.view = 'main';
68 }
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: {
82 'button[reference=loginButton]': {
83 click: 'submitForm'
84 }
85 }
86 },
87
88 plugins: 'viewport',
89
90 layout: {
91 type: 'border'
92 },
93
94 items: [
95 {
96 region: 'north',
97 xtype: 'container',
98 layout: {
99 type: 'hbox',
100 align: 'middle'
101 },
102 margin: '4 5 4 5',
103 items: [
104 {
105 xtype: 'proxmoxlogo'
106 },
107 {
108 xtype: 'versioninfo',
109 makeApiCall: false
110 }
111 ]
112 },
113 {
114 region: 'center'
115 },
116 {
117 xtype: 'window',
118 closable: false,
119 resizable: false,
120 reference: 'loginwindow',
121 autoShow: true,
122 modal: true,
123
124 defaultFocus: 'usernameField',
125
126 layout: {
127 type: 'auto'
128 },
129
130 title: gettext('Proxmox Mail Gateway Login'),
131
132 items: [
133 {
134 xtype: 'form',
135 layout: {
136 type: 'form'
137 },
138 defaultButton: 'loginButton',
139 url: '/api2/extjs/access/ticket',
140 reference: 'loginForm',
141
142 fieldDefaults: {
143 labelAlign: 'right',
144 allowBlank: false
145 },
146
147 items: [
148 {
149 xtype: 'textfield',
150 fieldLabel: gettext('User name'),
151 name: 'username',
152 itemId: 'usernameField',
153 reference: 'usernameField'
154 },
155 {
156 xtype: 'textfield',
157 inputType: 'password',
158 fieldLabel: gettext('Password'),
159 name: 'password',
160 reference: 'passwordField'
161 },
162 {
163 xtype: 'hiddenfield',
164 name: 'realm',
165 value: 'pam'
166 }
167 ],
168 buttons: [
169 {
170 text: gettext('Login'),
171 reference: 'loginButton',
172 formBind: true
173 }
174 ]
175 }
176 ]
177 }
178 ]
179 });