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