]>
git.proxmox.com Git - proxmox-backup.git/blob - www/LoginView.js
d4d8e73e65bb473bbc1748ba8c545c5142931ec5
1 Ext
.define('PBS.LoginView', {
2 extend
: 'Ext.container.Container',
10 button_text: function(get) {
11 if (get("openid") === true) {
12 return gettext("Login (OpenID redirect)");
14 return gettext("Login");
21 xclass
: 'Ext.app.ViewController',
23 submitForm
: async
function() {
25 var loginForm
= me
.lookupReference('loginForm');
26 var unField
= me
.lookupReference('usernameField');
27 var saveunField
= me
.lookupReference('saveunField');
29 if (!loginForm
.isValid()) {
33 let creds
= loginForm
.getValues();
35 if (this.getViewModel().data
.openid
=== true) {
36 const redirectURL
= location
.origin
;
38 let resp
= await Proxmox
.Async
.api2({
39 url
: '/api2/extjs/access/openid/auth-url',
42 "redirect-url": redirectURL
,
46 window
.location
= resp
.result
.data
;
48 Proxmox
.Utils
.authClear();
52 gettext('OpenID redirect failed, please try again') + `<br>${response.result.message}`,
58 creds
.username
= `${creds.username}@${creds.realm}`;
61 if (loginForm
.isVisible()) {
62 loginForm
.mask(gettext('Please wait...'), 'x-mask-loading');
65 // set or clear username
66 var sp
= Ext
.state
.Manager
.getProvider();
67 if (saveunField
.getValue() === true) {
68 sp
.set(unField
.getStateId(), unField
.getValue());
70 sp
.clear(unField
.getStateId());
72 sp
.set(saveunField
.getStateId(), saveunField
.getValue());
75 let resp
= await Proxmox
.Async
.api2({
76 url
: '/api2/extjs/access/ticket',
81 let data
= resp
.result
.data
;
82 if (data
.ticket
.startsWith("PBS:!tfa!")) {
83 data
= await me
.performTFAChallenge(data
);
86 PBS
.Utils
.updateLoginData(data
);
87 PBS
.app
.changeView('mainview');
89 Proxmox
.Utils
.authClear();
93 gettext('Login failed. Please try again'),
98 performTFAChallenge
: async
function(data
) {
101 let userid
= data
.username
;
102 let ticket
= data
.ticket
;
103 let challenge
= JSON
.parse(decodeURIComponent(
104 ticket
.split(':')[1].slice("!tfa!".length
),
107 let resp
= await
new Promise((resolve
, reject
) => {
108 Ext
.create('Proxmox.window.TfaLoginWindow', {
112 onResolve
: value
=> resolve(value
),
117 return resp
.result
.data
;
121 'field[name=username]': {
122 specialkey: function(f
, e
) {
123 if (e
.getKey() === e
.ENTER
) {
124 var pf
= this.lookupReference('passwordField');
125 if (!pf
.getValue()) {
131 'field[name=lang]': {
132 change: function(f
, value
) {
133 var dt
= Ext
.Date
.add(new Date(), Ext
.Date
.YEAR
, 10);
134 Ext
.util
.Cookies
.set('PBSLangCookie', value
, dt
);
135 this.getView().mask(gettext('Please wait...'), 'x-mask-loading');
136 window
.location
.reload();
139 'field[name=realm]': {
140 change: function(f
, value
) {
141 let record
= f
.store
.getById(value
);
142 if (record
=== undefined) return;
143 let data
= record
.data
;
144 this.getViewModel().set("openid", data
.type
=== "openid");
147 'button[reference=loginButton]': {
150 'window[reference=loginwindow]': {
152 var sp
= Ext
.state
.Manager
.getProvider();
153 var checkboxField
= this.lookupReference('saveunField');
154 var unField
= this.lookupReference('usernameField');
156 var checked
= sp
.get(checkboxField
.getStateId());
157 checkboxField
.setValue(checked
);
159 if (checked
=== true) {
160 var username
= sp
.get(unField
.getStateId());
161 unField
.setValue(username
);
162 var pwField
= this.lookupReference('passwordField');
166 let auth
= Proxmox
.Utils
.getOpenIDRedirectionAuthorization();
167 if (auth
!== undefined) {
168 Proxmox
.Utils
.authClear();
170 let loginForm
= this.lookupReference('loginForm');
171 loginForm
.mask(gettext('OpenID login - please wait...'), 'x-mask-loading');
173 // openID checks the original redirection URL we used, so pass that too
174 const redirectURL
= location
.origin
;
176 Proxmox
.Utils
.API2Request({
177 url
: '/api2/extjs/access/openid/login',
181 "redirect-url": redirectURL
,
184 failure: function(response
) {
186 let error
= response
.htmlStatus
;
187 Ext
.MessageBox
.alert(
189 gettext('OpenID login failed, please try again') + `<br>${error}`,
190 () => { window
.location
= redirectURL
; },
193 success: function(response
, options
) {
195 let creds
= response
.result
.data
;
196 PBS
.Utils
.updateLoginData(creds
);
197 PBS
.app
.changeView('mainview');
198 history
.replaceState(null, '', `${redirectURL}#pbsDashboard`);
225 xtype
: 'proxmoxlogo',
229 xtype
: 'versioninfo',
241 reference
: 'loginwindow',
246 defaultFocus
: 'usernameField',
252 title
: gettext('Proxmox Backup Server Login'),
260 defaultButton
: 'loginButton',
261 url
: '/api2/extjs/access/ticket',
262 reference
: 'loginForm',
272 fieldLabel
: gettext('User name'),
274 itemId
: 'usernameField',
275 reference
: 'usernameField',
276 stateId
: 'login-username',
277 inputAttrTpl
: 'autocomplete=username',
279 visible
: "{!openid}",
280 disabled
: "{openid}",
285 inputType
: 'password',
286 fieldLabel
: gettext('Password'),
288 itemId
: 'passwordField',
289 reference
: 'passwordField',
290 inputAttrTpl
: 'autocomplete=current-password',
292 visible
: "{!openid}",
293 disabled
: "{openid}",
297 xtype
: 'pmxRealmComboBox',
301 xtype
: 'proxmoxLanguageSelector',
302 fieldLabel
: gettext('Language'),
303 value
: Ext
.util
.Cookies
.get('PBSLangCookie') || Proxmox
.defaultLang
|| '__default__',
305 reference
: 'langField',
312 fieldLabel
: gettext('Save User name'),
313 name
: 'saveusername',
314 reference
: 'saveunField',
315 stateId
: 'login-saveusername',
320 visible
: "{!openid}",
325 text
: "{button_text}",
327 reference
: 'loginButton',