]> git.proxmox.com Git - pmg-gui.git/blob - js/LoginView.js
jslint: globals
[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: 'border',
91
92 items: [
93 {
94 region: 'north',
95 xtype: 'container',
96 layout: {
97 type: 'hbox',
98 align: 'middle'
99 },
100 margin: '4 5 4 5',
101 items: [
102 {
103 xtype: 'proxmoxlogo'
104 },
105 {
106 xtype: 'versioninfo',
107 makeApiCall: false,
108 }
109 ]
110 },
111 {
112 region: 'center'
113 },
114 {
115 xtype: 'window',
116 closable: false,
117 resizable: false,
118 reference: 'loginwindow',
119 autoShow: true,
120 modal: true,
121
122 defaultFocus: 'usernameField',
123
124 layout: 'auto',
125
126 title: gettext('Proxmox Mail Gateway Login'),
127
128 items: [
129 {
130 xtype: 'form',
131 layout: 'form',
132 defaultButton: 'loginButton',
133 url: '/api2/extjs/access/ticket',
134 reference: 'loginForm',
135
136 fieldDefaults: {
137 labelAlign: 'right',
138 allowBlank: false
139 },
140
141 items: [
142 {
143 xtype: 'textfield',
144 fieldLabel: gettext('User name'),
145 name: 'username',
146 itemId: 'usernameField',
147 reference: 'usernameField',
148 },
149 {
150 xtype: 'textfield',
151 inputType: 'password',
152 fieldLabel: gettext('Password'),
153 name: 'password',
154 reference: 'passwordField'
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 });