]> git.proxmox.com Git - pve-manager.git/blob - www/mobile/Login.js
ui: sdn: homogenize the casing of labels
[pve-manager.git] / www / mobile / Login.js
1 Ext.define('PVE.Login', {
2 extend: 'Ext.form.Panel',
3 alias: "widget.pveLogin",
4
5 handleTFA: function(username, ticketResponse) {
6 let me = this;
7 let errlabel = me.down('#signInFailedLabel');
8
9 // set auth cookie with half-loggedin ticket for TFA
10 ticketResponse.LoggedOut = true;
11 Proxmox.Utils.setAuthData(ticketResponse);
12
13 if (Ext.isDefined(ticketResponse.U2FChallenge)) {
14 Ext.Msg.show({
15 title: 'Error - U2F not implemented',
16 message: 'The U2F two factor authentication is not yet implemented on mobile.',
17 buttons: Ext.MessageBox.CANCEL,
18 });
19 errlabel.show();
20 } else {
21 Ext.Msg.show({
22 title: 'Two-Factor Authentication',
23 message: 'Please enter your OTP verification code:',
24 buttons: Ext.MessageBox.OKCANCEL,
25 prompt: {
26 xtype: 'tfacode',
27 },
28 fn: function(buttonId, code) {
29 if (buttonId === "cancel") {
30 Proxmox.LoggedOut = false;
31 Proxmox.Utils.authClear();
32 } else {
33 me.mask({
34 xtype: 'loadmask',
35 message: 'Loading...',
36 });
37 Proxmox.Utils.API2Request({
38 url: '/api2/extjs/access/tfa',
39 params: { response: code },
40 method: 'POST',
41 timeout: 5000, // it'll delay both success & failure
42 success: function(resp, opts) {
43 me.unmask();
44 // Fill in what we copy over from the 1st factor:
45 let authdata = resp.result.data;
46 authdata.CSRFPreventionToken = Proxmox.CSRFPreventionToken;
47 authdata.username = username;
48 // Finish login, sets real cookie and loads page
49 PVE.Workspace.updateLoginData(authdata);
50 },
51 failure: function(resp, opts) {
52 me.unmask();
53 Proxmox.Utils.authClear();
54 errlabel.show();
55 },
56 });
57 }
58 },
59 });
60 }
61 },
62
63 config: {
64 title: 'Login',
65 padding: 10,
66 appUrl: 'login',
67 items: [
68 {
69 xtype: 'image',
70 src: '/pve2/images/proxmox_logo.png',
71 height: 30,
72 width: 209,
73 },
74 {
75 xtype: 'fieldset',
76 title: 'Proxmox VE Login',
77 items: [
78 {
79 xtype: 'textfield',
80 placeHolder: gettext('User name'),
81 itemId: 'userNameTextField',
82 name: 'username',
83 required: true,
84 },
85 {
86 xtype: 'passwordfield',
87 placeHolder: gettext('Password'),
88 itemId: 'passwordTextField',
89 name: 'password',
90 required: true,
91 },
92 {
93 xtype: 'pveRealmSelector',
94 itemId: 'realmSelectorField',
95 name: 'realm',
96 },
97 ],
98 },
99 {
100 xtype: 'label',
101 html: 'Login failed. Please enter the correct credentials.',
102 itemId: 'signInFailedLabel',
103 hidden: true,
104 hideAnimation: 'fadeOut',
105 showAnimation: 'fadeIn',
106 style: 'color:#990000;margin:5px 0px;',
107 },
108 {
109 xtype: 'button',
110 itemId: 'logInButton',
111 ui: 'action',
112 text: 'Log In',
113 handler: function() {
114 var form = this.up('formpanel');
115
116 var usernameField = form.down('#userNameTextField'),
117 passwordField = form.down('#passwordTextField'),
118 realmField = form.down('#realmSelectorField'),
119 errlabel = form.down('#signInFailedLabel');
120
121 errlabel.hide();
122
123 var username = usernameField.getValue();
124 var password = passwordField.getValue();
125 var realm = realmField.getValue();
126
127 Proxmox.Utils.API2Request({
128 url: '/access/ticket',
129 method: 'POST',
130 waitMsgTarget: form,
131 params: { username: username, password: password, realm: realm },
132 failure: function(response, options) {
133 errlabel.show();
134 },
135 success: function(response, options) {
136 passwordField.setValue('');
137
138 let data = response.result.data;
139 if (Ext.isDefined(data.NeedTFA)) {
140 form.handleTFA(username, data);
141 } else {
142 PVE.Workspace.updateLoginData(data);
143 }
144 },
145 });
146 },
147 },
148 ],
149 },
150 });
151
152 Ext.define('PVE.field.TFACode', {
153 extend: 'Ext.field.Text',
154 xtype: 'tfacode',
155
156 config: {
157 component: {
158 type: 'number',
159 },
160 maxLength: 6,
161 required: true,
162 },
163 });